Skip to content

Commit

Permalink
run black
Browse files Browse the repository at this point in the history
  • Loading branch information
pjstevns committed Apr 14, 2023
1 parent 345954b commit 0f80d82
Show file tree
Hide file tree
Showing 17 changed files with 38 additions and 116 deletions.
8 changes: 2 additions & 6 deletions tests/blocks/test_form_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(["<p>Sorry, this form has been deleted.</p>"])
Expand Down Expand Up @@ -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(
Expand Down
8 changes: 2 additions & 6 deletions tests/blocks/test_form_chooser_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 2 additions & 6 deletions tests/blocks/test_info_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ def test_form_render_with_value(self):
block = InfoBlock()

test_form_html = block.render_form("foo")
expected_html = "\n".join(
['<div style="margin-top:5px;padding:0.9em 1.2em;">foo</div>']
)
expected_html = "\n".join(['<div style="margin-top:5px;padding:0.9em 1.2em;">foo</div>'])
self.assertInHTML(expected_html, test_form_html)

def test_form_render_no_value_with_help_text(self):
Expand All @@ -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(
['<div style="margin-top:5px;padding:0.9em 1.2em;">foo</div>']
)
expected_html = "\n".join(['<div style="margin-top:5px;padding:0.9em 1.2em;">foo</div>'])
self.assertInHTML(expected_html, test_form_html)
6 changes: 1 addition & 5 deletions tests/fields/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions tests/forms/test_form_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}}]
Expand Down
24 changes: 6 additions & 18 deletions tests/hooks/test_process_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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(
Expand Down
4 changes: 1 addition & 3 deletions tests/hooks/test_save_form_submission_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 1 addition & 3 deletions tests/models/test_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}}

Expand Down
8 changes: 2 additions & 6 deletions tests/test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
4 changes: 1 addition & 3 deletions tests/test_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 2 additions & 6 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
8 changes: 2 additions & 6 deletions tests/views/test_admin_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ class AdminListViewTestCase(AppTestCase):
fixtures = ["test.json"]

def setUp(self):
self.user = User.objects.create_user(
"user", "[email protected]", "password", is_staff=True
)
self.user = User.objects.create_user("user", "[email protected]", "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")
Expand All @@ -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</a>', 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</a>'
Expand Down
8 changes: 2 additions & 6 deletions tests/views/test_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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)
20 changes: 5 additions & 15 deletions tests/views/test_copy.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ def setUp(self):
User.objects.create_superuser("user", "[email protected]", "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")

Expand Down Expand Up @@ -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)

Expand All @@ -62,16 +56,12 @@ class CopyViewPermissionTestCase(AppTestCase):
def setUp(self):
self.user = User.objects.create_user("user", "[email protected]", "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")
Expand Down
8 changes: 2 additions & 6 deletions tests/views/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ def setUp(self):
self.user = User.objects.create_user("user", "[email protected]", "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(
Expand All @@ -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")
Expand Down
16 changes: 4 additions & 12 deletions tests/views/test_submission_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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):
Expand All @@ -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")
Expand Down

0 comments on commit 0f80d82

Please sign in to comment.