I'm trying to test a protected view. Unauthenticated user are redirect to login page. When I run the test, it raises django.cose.exceptions.PermissionDenied
which is normal but how could I write it without getting a failure and how can I test if the redirection is correct?
Here is what I've done.
class TestProtectedRegistrationListView:
"""
Verify registration views are protected from unauthenticated access.
"""
def test_access_url(
self, user: settings.AUTH_USER_MODEL, request_factory: RequestFactory
):
view = RegistrationListView.as_view()
request = request_factory.get("/admin_staff/registrations")
request.user = user
resp = view(request)
assert resp == PermissionDenied
Aucun commentaire:
Enregistrer un commentaire