diff --git a/tests/blocks/test_form_block.py b/tests/blocks/test_form_block.py index 39e9f0f2..f0b463a2 100644 --- a/tests/blocks/test_form_block.py +++ b/tests/blocks/test_form_block.py @@ -228,9 +228,7 @@ def test_render_when_form_deleted(self): block = WagtailFormBlock() html = block.render( - block.to_python( - {"form": 100, "form_action": "/foo/", "form_reference": "some-ref"} - ) + block.to_python({"form": 100, "form_action": "/foo/", "form_reference": "some-ref"}) ) expected_html = "\n".join(["

Sorry, this form has been deleted.

"]) @@ -271,9 +269,7 @@ def test_context_has_form(self): def test_context_form_is_invalid_when_parent_context_has_this_form_with_errors( self, ): - invalid_form = self.form.get_form( - {"form_id": self.form.id, "form_reference": "some-ref"} - ) + invalid_form = self.form.get_form({"form_id": self.form.id, "form_reference": "some-ref"}) assert not invalid_form.is_valid() self.assertDictEqual( diff --git a/tests/blocks/test_form_chooser_block.py b/tests/blocks/test_form_chooser_block.py index af417427..57241bcd 100644 --- a/tests/blocks/test_form_chooser_block.py +++ b/tests/blocks/test_form_chooser_block.py @@ -19,12 +19,8 @@ def test_value_for_form(self): def test_value_from_form(self): block = FormChooserBlock() - self.assertTrue( - isinstance(block.value_from_form(self.form.pk), self.form.__class__) - ) - self.assertTrue( - isinstance(block.value_from_form(self.form), self.form.__class__) - ) + self.assertTrue(isinstance(block.value_from_form(self.form.pk), self.form.__class__)) + self.assertTrue(isinstance(block.value_from_form(self.form), self.form.__class__)) def test_to_python(self): block = FormChooserBlock() diff --git a/tests/blocks/test_info_block.py b/tests/blocks/test_info_block.py index a108968e..f397ed36 100644 --- a/tests/blocks/test_info_block.py +++ b/tests/blocks/test_info_block.py @@ -8,9 +8,7 @@ def test_form_render_with_value(self): block = InfoBlock() test_form_html = block.render_form("foo") - expected_html = "\n".join( - ['
foo
'] - ) + expected_html = "\n".join(['
foo
']) self.assertInHTML(expected_html, test_form_html) def test_form_render_no_value_with_help_text(self): @@ -26,7 +24,5 @@ def test_form_render_value_and_help_text(self): block = InfoBlock(help_text="some help") test_form_html = block.render_form("foo") - expected_html = "\n".join( - ['
foo
'] - ) + expected_html = "\n".join(['
foo
']) self.assertInHTML(expected_html, test_form_html) diff --git a/tests/fields/test_fields.py b/tests/fields/test_fields.py index efe66489..428f015e 100644 --- a/tests/fields/test_fields.py +++ b/tests/fields/test_fields.py @@ -13,11 +13,7 @@ def setUp(self): self.form = Form.objects.get(pk=1) def get_form_field_data(self, name): - return [ - item["value"] - for item in self.form.get_form_fields() - if item["type"] == name - ][0] + return [item["value"] for item in self.form.get_form_fields() if item["type"] == name][0] def test_singleline_field(self): data = self.get_form_field_data("singleline") diff --git a/tests/forms/test_form_builder.py b/tests/forms/test_form_builder.py index 1e9f66d9..9b133412 100644 --- a/tests/forms/test_form_builder.py +++ b/tests/forms/test_form_builder.py @@ -23,9 +23,7 @@ def test_formfields__invalid_type(self): fields = [{"type": "foo", "value": {}}] with self.assertRaises(AttributeError) as ex: FormBuilder(fields).formfields - self.assertEqual( - ex.exception.args[0], "Could not find a registered field of type foo" - ) + self.assertEqual(ex.exception.args[0], "Could not find a registered field of type foo") def test_formfields__missing_label_in_value(self): fields = [{"type": "singleline", "value": {}}] diff --git a/tests/hooks/test_process_form.py b/tests/hooks/test_process_form.py index 35da1b94..0dae10c0 100644 --- a/tests/hooks/test_process_form.py +++ b/tests/hooks/test_process_form.py @@ -49,9 +49,7 @@ def test_hook_disabled_when_setting_false(self): self.assertIsNone(response) def test_valid_post_redirects__to_the_forms_post_redirect_page(self): - redirect_to = self.page.add_child( - instance=Page(title="another", slug="another") - ) + redirect_to = self.page.add_child(instance=Page(title="another", slug="another")) form = self.test_form() form.post_redirect_page = redirect_to form.save() @@ -143,9 +141,7 @@ def test_success_message__sent_when_form_has_message(self): process_form(self.page, fake_request) self.mock_success_message.assert_called() self.assertEqual(self.mock_success_message.call_args[0][1], "well done") - self.assertEqual( - self.mock_success_message.call_args[1], {"fail_silently": True} - ) + self.assertEqual(self.mock_success_message.call_args[1], {"fail_silently": True}) def test_success_message__not_sent_when_form_has_no_message(self): form = self.test_form() @@ -176,9 +172,7 @@ def test_success_message__not_sent_when_form_has_no_message(self): process_form(self.page, fake_request) - assert ( - not self.mock_success_message.called - ), "messages.success should not have been called" + assert not self.mock_success_message.called, "messages.success should not have been called" def test_error_message__sent_when_form_has_message(self): form = self.test_form() @@ -207,9 +201,7 @@ def test_error_message__not_sent_when_form_has_no_message(self): process_form(self.page, fake_request) - assert ( - not self.mock_error_message.called - ), "messages.error should not have been called" + assert not self.mock_error_message.called, "messages.error should not have been called" def test_invalid_form_id_returns_nothing(self): self.test_form() @@ -231,17 +223,13 @@ def test_no_form_id_returns_nothing(self): def test_invalid_form_returns_response_with_form(self): form = self.test_form() - fake_request = self.rf.post( - "/fake/", {"form_id": form.pk, "form_reference": "some-ref"} - ) + fake_request = self.rf.post("/fake/", {"form_id": form.pk, "form_reference": "some-ref"}) fake_request.user = AnonymousUser() response = process_form(self.page, fake_request) self.assertEqual(response.status_code, 200) - self.assertEqual( - response.context_data["invalid_stream_form_reference"], "some-ref" - ) + self.assertEqual(response.context_data["invalid_stream_form_reference"], "some-ref") invalid_form = response.context_data["invalid_stream_form"] self.assertDictEqual( diff --git a/tests/hooks/test_save_form_submission_data.py b/tests/hooks/test_save_form_submission_data.py index 98480cb9..a98df27e 100644 --- a/tests/hooks/test_save_form_submission_data.py +++ b/tests/hooks/test_save_form_submission_data.py @@ -61,6 +61,4 @@ def test_saves_record_with_files(self): json.loads(instance.get_submission_class().objects.all()[0].form_data), expected_data, ) - self.assertEqual( - instance.get_submission_class().objects.all()[0].files.count(), 2 - ) + self.assertEqual(instance.get_submission_class().objects.all()[0].files.count(), 2) diff --git a/tests/models/test_form.py b/tests/models/test_form.py index 273253ad..98bb8a34 100644 --- a/tests/models/test_form.py +++ b/tests/models/test_form.py @@ -120,9 +120,7 @@ def test_copy_does_not_copy_form_submissions(self): self.assertEqual(FormSubmission.objects.filter(form=copied).count(), 0) - @override_settings( - WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel" - ) + @override_settings(WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel") def test_copy_copies_advanced_settings(self): from wagtailstreamforms.utils.loading import get_advanced_settings_model diff --git a/tests/settings.py b/tests/settings.py index bfe1fd63..6fbb8f25 100644 --- a/tests/settings.py +++ b/tests/settings.py @@ -43,12 +43,8 @@ "wagtail.contrib.redirects.middleware.RedirectMiddleware", ] -DJANGO_VERSION = int( - re.search("dj([0-9]+)", os.environ.get("TOX_ENV_NAME", "dj40")).group(1) -) -WAGTAIL_VERSION = int( - re.search("wt([0-9]+)", os.environ.get("TOX_ENV_NAME", "wt216")).group(1) -) +DJANGO_VERSION = int(re.search("dj([0-9]+)", os.environ.get("TOX_ENV_NAME", "dj40")).group(1)) +WAGTAIL_VERSION = int(re.search("wt([0-9]+)", os.environ.get("TOX_ENV_NAME", "wt216")).group(1)) DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "testdb"}} diff --git a/tests/test_case.py b/tests/test_case.py index 06811dd2..229a97ca 100644 --- a/tests/test_case.py +++ b/tests/test_case.py @@ -59,9 +59,7 @@ def render_template(self, string, context=None): _non_blankable_fields = [models.BooleanField] - def assertModelField( - self, field, expected_class, null=False, blank=False, default=None - ): + def assertModelField(self, field, expected_class, null=False, blank=False, default=None): self.assertEqual(field.__class__, expected_class) self.assertEqual(field.null, null) if expected_class not in self._non_blankable_fields: @@ -70,9 +68,7 @@ def assertModelField( if default: self.assertEqual(field.default, default) - def assertModelDecimalField( - self, field, max_digits, decimal_places, null=False, blank=False - ): + def assertModelDecimalField(self, field, max_digits, decimal_places, null=False, blank=False): self.assertEqual(field.__class__, models.DecimalField) self.assertEqual(field.max_digits, max_digits) self.assertEqual(field.decimal_places, decimal_places) diff --git a/tests/test_urls.py b/tests/test_urls.py index d3a46a4f..ab7eafcc 100644 --- a/tests/test_urls.py +++ b/tests/test_urls.py @@ -11,9 +11,7 @@ def test_no_advanced_url_when_no_setting(self): self.reload_module("wagtailstreamforms.urls") self.assertEqual(len(urlpatterns), 3) - @override_settings( - WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel" - ) + @override_settings(WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel") def test_no_advanced_url_when_no_setting(self): self.reload_module("wagtailstreamforms.urls") self.assertEqual(len(urlpatterns), 4) diff --git a/tests/test_utils.py b/tests/test_utils.py index bb62d6ee..9f91c200 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -24,16 +24,12 @@ def test_invalid_import(self): with self.assertRaisesMessage(ImproperlyConfigured, msg): get_advanced_settings_model() - @override_settings( - WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.InvalidFormSettingsModel" - ) + @override_settings(WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.InvalidFormSettingsModel") def test_invalid_model_inheritance(self): msg = "must inherit from 'wagtailstreamforms.models.AbstractFormSetting'" with self.assertRaisesMessage(ImproperlyConfigured, msg): get_advanced_settings_model() - @override_settings( - WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel" - ) + @override_settings(WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel") def test_valid_model_returns_class(self): self.assertIs(get_advanced_settings_model(), ValidFormSettingsModel) diff --git a/tests/views/test_admin_list.py b/tests/views/test_admin_list.py index 550bc752..f346ba1b 100644 --- a/tests/views/test_admin_list.py +++ b/tests/views/test_admin_list.py @@ -8,9 +8,7 @@ class AdminListViewTestCase(AppTestCase): fixtures = ["test.json"] def setUp(self): - self.user = User.objects.create_user( - "user", "user@test.com", "password", is_staff=True - ) + self.user = User.objects.create_user("user", "user@test.com", "password", is_staff=True) self.access_admin = Permission.objects.get(codename="access_admin") self.add_perm = Permission.objects.get(codename="add_form") self.change_perm = Permission.objects.get(codename="change_form") @@ -35,9 +33,7 @@ def test_copy_button_uses_add_perm(self): self.assertEqual(response.status_code, 200) self.assertIn('title="Copy this form">Copy', str(response.content)) - @override_settings( - WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel" - ) + @override_settings(WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel") def test_advanced_button_enabled_when_setup(self): url = "/cms/wagtailstreamforms/form/" expected_html = 'title="Advanced settings">Advanced' diff --git a/tests/views/test_advanced.py b/tests/views/test_advanced.py index 3e7fe050..eb9f66a8 100644 --- a/tests/views/test_advanced.py +++ b/tests/views/test_advanced.py @@ -8,9 +8,7 @@ from ..test_case import AppTestCase -@override_settings( - WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel" -) +@override_settings(WAGTAILSTREAMFORMS_ADVANCED_SETTINGS_MODEL="tests.ValidFormSettingsModel") class AdvancedSettingsViewTestCase(AppTestCase): fixtures = ["test.json"] @@ -39,8 +37,6 @@ def test_valid_post(self): self.assertEqual(self.form.advanced_settings.name, "foo") def test_post_redirects(self): - response = self.client.post( - self.advanced_url, data={"name": "foo", "number": 1} - ) + response = self.client.post(self.advanced_url, data={"name": "foo", "number": 1}) url_helper = FormURLHelper(model=Form) self.assertRedirects(response, url_helper.index_url) diff --git a/tests/views/test_copy.py b/tests/views/test_copy.py index 6eca00c1..f9af60a1 100644 --- a/tests/views/test_copy.py +++ b/tests/views/test_copy.py @@ -15,12 +15,8 @@ def setUp(self): User.objects.create_superuser("user", "user@test.com", "password") self.form = Form.objects.get(pk=1) - self.copy_url = reverse( - "wagtailstreamforms:streamforms_copy", kwargs={"pk": self.form.pk} - ) - self.invalid_copy_url = reverse( - "wagtailstreamforms:streamforms_copy", kwargs={"pk": 100} - ) + self.copy_url = reverse("wagtailstreamforms:streamforms_copy", kwargs={"pk": self.form.pk}) + self.invalid_copy_url = reverse("wagtailstreamforms:streamforms_copy", kwargs={"pk": 100}) self.client.login(username="user", password="password") @@ -49,9 +45,7 @@ def test_post_copies(self): self.assertEqual(Form.objects.count(), 2) def test_post_redirects(self): - response = self.client.post( - self.copy_url, data={"title": "new copy", "slug": "new-slug"} - ) + response = self.client.post(self.copy_url, data={"title": "new copy", "slug": "new-slug"}) url_helper = FormURLHelper(model=Form) self.assertRedirects(response, url_helper.index_url) @@ -62,16 +56,12 @@ class CopyViewPermissionTestCase(AppTestCase): def setUp(self): self.user = User.objects.create_user("user", "user@test.com", "password") form = Form.objects.get(pk=1) - self.copy_url = reverse( - "wagtailstreamforms:streamforms_copy", kwargs={"pk": form.pk} - ) + self.copy_url = reverse("wagtailstreamforms:streamforms_copy", kwargs={"pk": form.pk}) def test_no_user_no_access(self): response = self.client.get(self.copy_url) self.assertEqual(response.status_code, 302) - self.assertTrue( - response.url.startswith("/cms/login/?next=/cms/wagtailstreamforms") - ) + self.assertTrue(response.url.startswith("/cms/login/?next=/cms/wagtailstreamforms")) def test_user_with_no_perm_no_access(self): access_admin = Permission.objects.get(codename="access_admin") diff --git a/tests/views/test_delete.py b/tests/views/test_delete.py index 34cc8ca5..3a3638b4 100644 --- a/tests/views/test_delete.py +++ b/tests/views/test_delete.py @@ -75,9 +75,7 @@ def setUp(self): self.user = User.objects.create_user("user", "user@test.com", "password") self.form = Form.objects.get(pk=1) - self.form_submission = FormSubmission.objects.create( - form=self.form, form_data="{}" - ) + self.form_submission = FormSubmission.objects.create(form=self.form, form_data="{}") self.delete_url = "{}?selected-submissions={}".format( reverse( @@ -90,9 +88,7 @@ def setUp(self): def test_no_user_no_access(self): response = self.client.get(self.delete_url) self.assertEqual(response.status_code, 302) - self.assertTrue( - response.url.startswith("/cms/login/?next=/cms/wagtailstreamforms") - ) + self.assertTrue(response.url.startswith("/cms/login/?next=/cms/wagtailstreamforms")) def test_user_with_no_perm_no_access(self): access_admin = Permission.objects.get(codename="access_admin") diff --git a/tests/views/test_submission_list.py b/tests/views/test_submission_list.py index c4e88edc..fc22d125 100644 --- a/tests/views/test_submission_list.py +++ b/tests/views/test_submission_list.py @@ -29,14 +29,10 @@ def setUp(self): self.invalid_list_url = reverse( "wagtailstreamforms:streamforms_submissions", kwargs={"pk": 100} ) - self.filter_url = ( - "{}?date_from=2017-01-01&date_to=2017-01-02&action=filter".format( - self.list_url - ) - ) - self.invalid_filter_url = "{}?date_from=xx&date_to=xx&action=filter".format( + self.filter_url = "{}?date_from=2017-01-01&date_to=2017-01-02&action=filter".format( self.list_url ) + self.invalid_filter_url = "{}?date_from=xx&date_to=xx&action=filter".format(self.list_url) self.csv_url = "{}?date_from=2017-01-01&date_to=2017-01-02&action=CSV".format( self.list_url ) @@ -68,9 +64,7 @@ def test_get_filtering_doesnt_happen_with_invalid_form(self): def test_get_csv(self): response = self.client.get(self.csv_url) - self.assertEqual( - response.get("Content-Disposition"), "attachment;filename=export.csv" - ) + self.assertEqual(response.get("Content-Disposition"), "attachment;filename=export.csv") class ListViewPermissionTestCase(AppTestCase): @@ -86,9 +80,7 @@ def setUp(self): def test_no_user_no_access(self): response = self.client.get(self.list_url) self.assertEqual(response.status_code, 302) - self.assertTrue( - response.url.startswith("/cms/login/?next=/cms/wagtailstreamforms") - ) + self.assertTrue(response.url.startswith("/cms/login/?next=/cms/wagtailstreamforms")) def test_user_with_no_perm_no_access(self): access_admin = Permission.objects.get(codename="access_admin")