I write detailed functional tests for my views to complement unit tests on my models. This is a Django project, and I am using the Django embedded test environment with unittest. Obviously, one of the important things to check for these functional tests is that the permissions are configured correctly. With that in mind, I'm trying something like this:
anonclient = Client()
userclient = Client()
userclient.login(username='test_user', password='test')
adminclient = Client()
adminclient.login(username='test_admin', password='test')
path = "/path/to/my/page"
anonresponse = anonclient.get(path)
userresponse = userclient.get(path)
adminresponse = adminclient.get(path)
I need to be able to confirm that anonclient and userclient were denied access while the admin client was working correctly. Howerver, I canβt find a way to verify that this has happened reliably!
, 302 ( ), , , . ( self.assertRedirects(, url), URL- login_url !)
, user_passes_test, , ? . , , , . , , .
, , ?
!