From a95e031140bc188e172523add8d201034f75f534 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 11 Nov 2021 11:33:12 -0800 Subject: [PATCH 1/4] Validate html in unit tests --- bookwyrm/tests/views/test_import.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bookwyrm/tests/views/test_import.py b/bookwyrm/tests/views/test_import.py index 2027d2845..b29190e72 100644 --- a/bookwyrm/tests/views/test_import.py +++ b/bookwyrm/tests/views/test_import.py @@ -5,6 +5,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile from django.template.response import TemplateResponse from django.test import TestCase from django.test.client import RequestFactory +from bookwyrm.tests.validate_html import validate_html from bookwyrm import forms, models, views @@ -34,7 +35,7 @@ class ImportViews(TestCase): request.user = self.local_user result = view(request) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_import_status(self): @@ -47,7 +48,7 @@ class ImportViews(TestCase): async_result.return_value = [] result = view(request, import_job.id) self.assertIsInstance(result, TemplateResponse) - result.render() + validate_html(result.render()) self.assertEqual(result.status_code, 200) def test_start_import(self): @@ -58,7 +59,9 @@ class ImportViews(TestCase): form.data["privacy"] = "public" form.data["include_reviews"] = False csv_file = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv") - form.data["csv_file"] = SimpleUploadedFile( + form.data[ + "csv_file" + ] = SimpleUploadedFile( # pylint: disable=consider-using-with csv_file, open(csv_file, "rb").read(), content_type="text/csv" ) From d807774c2d00fa5c3320b7be473330e4aee86161 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 11 Nov 2021 12:53:48 -0800 Subject: [PATCH 2/4] Fixes label for privacy field --- bookwyrm/templates/import/import.html | 6 +++--- bookwyrm/tests/views/test_import.py | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/import/import.html b/bookwyrm/templates/import/import.html index 81f0daa54..314a6861f 100644 --- a/bookwyrm/templates/import/import.html +++ b/bookwyrm/templates/import/import.html @@ -46,10 +46,10 @@
-
diff --git a/bookwyrm/tests/views/test_import.py b/bookwyrm/tests/views/test_import.py index b29190e72..29f4902d7 100644 --- a/bookwyrm/tests/views/test_import.py +++ b/bookwyrm/tests/views/test_import.py @@ -61,7 +61,8 @@ class ImportViews(TestCase): csv_file = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv") form.data[ "csv_file" - ] = SimpleUploadedFile( # pylint: disable=consider-using-with + ] = SimpleUploadedFile( + # pylint: disable=consider-using-with csv_file, open(csv_file, "rb").read(), content_type="text/csv" ) From c744faf393c1b354781e65a3a28927176b7f07fd Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 11 Nov 2021 13:00:34 -0800 Subject: [PATCH 3/4] Fixes dictionary list html validity --- bookwyrm/templates/import/import_status.html | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/bookwyrm/templates/import/import_status.html b/bookwyrm/templates/import/import_status.html index 1c0739444..91e48e34e 100644 --- a/bookwyrm/templates/import/import_status.html +++ b/bookwyrm/templates/import/import_status.html @@ -10,18 +10,17 @@

{% trans "Import Status" %}

{% trans "Back to imports" %} + {% if task.failed %} +
{% trans "TASK FAILED" %}
+ {% endif %} +
-
-
{% trans "Import started:" %}
-
{{ job.created_date | naturaltime }}
-
+
{% trans "Import started:" %}
+
{{ job.created_date | naturaltime }}
+ {% if job.complete %} -
-
{% trans "Import completed:" %}
-
{{ task.date_done | naturaltime }}
-
- {% elif task.failed %} -
{% trans "TASK FAILED" %}
+
{% trans "Import completed:" %}
+
{{ task.date_done | naturaltime }}
{% endif %}
From ffcaef055959b64576b9b01bbc0f84715cafb248 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Thu, 11 Nov 2021 13:39:58 -0800 Subject: [PATCH 4/4] Python formatting --- bookwyrm/tests/views/test_import.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bookwyrm/tests/views/test_import.py b/bookwyrm/tests/views/test_import.py index 29f4902d7..1411a5a89 100644 --- a/bookwyrm/tests/views/test_import.py +++ b/bookwyrm/tests/views/test_import.py @@ -59,11 +59,11 @@ class ImportViews(TestCase): form.data["privacy"] = "public" form.data["include_reviews"] = False csv_file = pathlib.Path(__file__).parent.joinpath("../data/goodreads.csv") - form.data[ - "csv_file" - ] = SimpleUploadedFile( + form.data["csv_file"] = SimpleUploadedFile( # pylint: disable=consider-using-with - csv_file, open(csv_file, "rb").read(), content_type="text/csv" + csv_file, + open(csv_file, "rb").read(), + content_type="text/csv", ) request = self.factory.post("", form.data)