Skip to content

Commit

Permalink
Replace usages of assertFormError which is removed in Django 5 (#754)
Browse files Browse the repository at this point in the history
  • Loading branch information
softquantum authored Dec 20, 2023
1 parent 41a9765 commit 99d93e5
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 31 deletions.
64 changes: 36 additions & 28 deletions wagtail_localize/locales/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ def test_duplicate_not_allowed(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response,
"form",
"language_code",
form = response.context["form"]
self.assertIn("language_code", form.errors)
self.assertEqual(
form.errors["language_code"],
["Select a valid choice. en is not one of the available choices."],
)

Expand All @@ -99,10 +99,10 @@ def test_language_code_must_be_in_settings(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response,
"form",
"language_code",
form = response.context["form"]
self.assertIn("language_code", form.errors)
self.assertEqual(
form.errors["language_code"],
["Select a valid choice. ja is not one of the available choices."],
)

Expand All @@ -117,8 +117,10 @@ def test_sync_from_required_when_enabled(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response, "component_form", "sync_from", ["This field is required."]
component_form = response.context["component_form"]
self.assertIn("sync_from", component_form.errors)
self.assertEqual(
component_form.errors["sync_from"], ["This field is required."]
)

# Check that the locale was not created
Expand Down Expand Up @@ -157,8 +159,10 @@ def test_sync_from_required_when_component_required(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response, "component_form", "sync_from", ["This field is required."]
component_form = response.context["component_form"]
self.assertIn("sync_from", component_form.errors)
self.assertEqual(
component_form.errors["sync_from"], ["This field is required."]
)

# Check that the locale was not created
Expand Down Expand Up @@ -250,10 +254,10 @@ def test_edit_duplicate_not_allowed(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response,
"form",
"language_code",
form = response.context["form"]
self.assertIn("language_code", form.errors)
self.assertEqual(
form.errors["language_code"],
["Select a valid choice. en is not one of the available choices."],
)

Expand All @@ -268,10 +272,10 @@ def test_edit_language_code_must_be_in_settings(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response,
"form",
"language_code",
form = response.context["form"]
self.assertIn("language_code", form.errors)
self.assertEqual(
form.errors["language_code"],
["Select a valid choice. ja is not one of the available choices."],
)

Expand All @@ -286,8 +290,10 @@ def test_sync_from_required_when_enabled(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response, "component_form", "sync_from", ["This field is required."]
component_form = response.context["component_form"]
self.assertIn("sync_from", component_form.errors)
self.assertEqual(
component_form.errors["sync_from"], ["This field is required."]
)

def test_sync_from_not_required_when_disabled(self):
Expand Down Expand Up @@ -321,8 +327,10 @@ def test_sync_from_required_when_component_required(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response, "component_form", "sync_from", ["This field is required."]
component_form = response.context["component_form"]
self.assertIn("sync_from", component_form.errors)
self.assertEqual(
component_form.errors["sync_from"], ["This field is required."]
)

def test_sync_from_cannot_be_the_same_as_locale(self):
Expand All @@ -336,10 +344,10 @@ def test_sync_from_cannot_be_the_same_as_locale(self):

# Should return the form with errors
self.assertEqual(response.status_code, 200)
self.assertFormError(
response,
"component_form",
"sync_from",
component_form = response.context["component_form"]
self.assertIn("sync_from", component_form.errors)
self.assertEqual(
component_form.errors["sync_from"],
["This locale cannot be synced into itself."],
)

Expand Down
4 changes: 3 additions & 1 deletion wagtail_localize/modeladmin/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,9 @@ def test_post_submit_modeladmin_translation_with_missing_locale(self):

self.assertEqual(response.status_code, 200)
self.assertFalse(Translation.objects.exists())
self.assertFormError(response, "form", "locales", ["This field is required."])
form = response.context["form"]
self.assertIn("locales", form.errors)
self.assertEqual(form.errors["locales"], ["This field is required."])

def test_post_submit_modeladmin_translation_without_permissions(self):
strip_user_perms()
Expand Down
8 changes: 6 additions & 2 deletions wagtail_localize/tests/test_submit_translations.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,9 @@ def test_post_submit_page_translation_with_missing_locale(self):

self.assertEqual(response.status_code, 200)
self.assertFalse(Translation.objects.exists())
self.assertFormError(response, "form", "locales", ["This field is required."])
form = response.context["form"]
self.assertIn("locales", form.errors)
self.assertEqual(form.errors["locales"], ["This field is required."])

def test_post_submit_page_translation_without_permissions(self):
strip_user_perms()
Expand Down Expand Up @@ -984,7 +986,9 @@ def test_post_submit_snippet_translation_with_missing_locale(self):

self.assertEqual(response.status_code, 200)
self.assertFalse(Translation.objects.exists())
self.assertFormError(response, "form", "locales", ["This field is required."])
form = response.context["form"]
self.assertIn("locales", form.errors)
self.assertEqual(form.errors["locales"], ["This field is required."])

def test_post_submit_snippet_translation_without_permissions(self):
strip_user_perms()
Expand Down

0 comments on commit 99d93e5

Please sign in to comment.