More general forbidden test

This commit is contained in:
Ludovic Stephan 2021-02-20 19:18:21 +01:00
parent 6adfaba8e9
commit c14c2d54a5
2 changed files with 51 additions and 18 deletions

View file

@ -79,10 +79,15 @@ class TestCaseMixin:
self.assertEqual(response.status_code, 200)
try:
form = response.context[form_ctx]
self.assertIn("Permission refusée", form.non_field_errors())
errors = [y for x in form.errors.as_data().values() for y in x]
self.assertTrue(any(e.code == "permission-denied" for e in errors))
except (AssertionError, AttributeError, KeyError):
messages = [str(msg) for msg in response.context["messages"]]
self.assertIn("Permission refusée", messages)
self.assertTrue(
any(
"permission-denied" in msg.tags
for msg in response.context["messages"]
)
)
except AssertionError:
request = response.wsgi_request
raise AssertionError(