Refs #27804 -- Used subTest in AdminViewPermissionsTest.
This commit is contained in:
parent
d3449faaa9
commit
f5e7506cff
|
@ -1813,43 +1813,45 @@ class AdminViewPermissionsTest(TestCase):
|
||||||
change_url_6 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r6.pk,))
|
change_url_6 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r6.pk,))
|
||||||
logins = [self.superuser, self.viewuser, self.adduser, self.changeuser, self.deleteuser]
|
logins = [self.superuser, self.viewuser, self.adduser, self.changeuser, self.deleteuser]
|
||||||
for login_user in logins:
|
for login_user in logins:
|
||||||
self.client.force_login(login_user)
|
with self.subTest(login_user.username):
|
||||||
response = self.client.get(change_url_1)
|
self.client.force_login(login_user)
|
||||||
self.assertEqual(response.status_code, 403)
|
response = self.client.get(change_url_1)
|
||||||
response = self.client.post(change_url_1, {'name': 'changed'})
|
self.assertEqual(response.status_code, 403)
|
||||||
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id')
|
response = self.client.post(change_url_1, {'name': 'changed'})
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id')
|
||||||
response = self.client.get(change_url_2)
|
self.assertEqual(response.status_code, 403)
|
||||||
self.assertEqual(response.status_code, 200)
|
response = self.client.get(change_url_2)
|
||||||
response = self.client.post(change_url_2, {'name': 'changed'})
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
|
response = self.client.post(change_url_2, {'name': 'changed'})
|
||||||
self.assertRedirects(response, self.index_url)
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
|
||||||
response = self.client.get(change_url_3)
|
self.assertRedirects(response, self.index_url)
|
||||||
self.assertEqual(response.status_code, 200)
|
response = self.client.get(change_url_3)
|
||||||
response = self.client.post(change_url_3, {'name': 'changed'})
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertRedirects(response, self.index_url)
|
response = self.client.post(change_url_3, {'name': 'changed'})
|
||||||
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=3).name, 'odd id mult 3')
|
self.assertRedirects(response, self.index_url)
|
||||||
response = self.client.get(change_url_6)
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=3).name, 'odd id mult 3')
|
||||||
self.assertEqual(response.status_code, 200)
|
response = self.client.get(change_url_6)
|
||||||
response = self.client.post(change_url_6, {'name': 'changed'})
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=6).name, 'changed')
|
response = self.client.post(change_url_6, {'name': 'changed'})
|
||||||
self.assertRedirects(response, self.index_url)
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=6).name, 'changed')
|
||||||
|
self.assertRedirects(response, self.index_url)
|
||||||
|
|
||||||
self.client.get(reverse('admin:logout'))
|
self.client.get(reverse('admin:logout'))
|
||||||
|
|
||||||
for login_user in [self.joepublicuser, self.nostaffuser]:
|
for login_user in [self.joepublicuser, self.nostaffuser]:
|
||||||
self.client.force_login(login_user)
|
with self.subTest(login_user.username):
|
||||||
response = self.client.get(change_url_1, follow=True)
|
self.client.force_login(login_user)
|
||||||
self.assertContains(response, 'login-form')
|
response = self.client.get(change_url_1, follow=True)
|
||||||
response = self.client.post(change_url_1, {'name': 'changed'}, follow=True)
|
self.assertContains(response, 'login-form')
|
||||||
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id')
|
response = self.client.post(change_url_1, {'name': 'changed'}, follow=True)
|
||||||
self.assertContains(response, 'login-form')
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id')
|
||||||
response = self.client.get(change_url_2, follow=True)
|
self.assertContains(response, 'login-form')
|
||||||
self.assertContains(response, 'login-form')
|
response = self.client.get(change_url_2, follow=True)
|
||||||
response = self.client.post(change_url_2, {'name': 'changed again'}, follow=True)
|
self.assertContains(response, 'login-form')
|
||||||
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
|
response = self.client.post(change_url_2, {'name': 'changed again'}, follow=True)
|
||||||
self.assertContains(response, 'login-form')
|
self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
|
||||||
self.client.get(reverse('admin:logout'))
|
self.assertContains(response, 'login-form')
|
||||||
|
self.client.get(reverse('admin:logout'))
|
||||||
|
|
||||||
def test_change_view_without_object_change_permission(self):
|
def test_change_view_without_object_change_permission(self):
|
||||||
"""
|
"""
|
||||||
|
@ -1997,27 +1999,29 @@ class AdminViewPermissionsTest(TestCase):
|
||||||
rl2 = RowLevelChangePermissionModel.objects.create(name="even id")
|
rl2 = RowLevelChangePermissionModel.objects.create(name="even id")
|
||||||
logins = [self.superuser, self.viewuser, self.adduser, self.changeuser, self.deleteuser]
|
logins = [self.superuser, self.viewuser, self.adduser, self.changeuser, self.deleteuser]
|
||||||
for login_user in logins:
|
for login_user in logins:
|
||||||
self.client.force_login(login_user)
|
with self.subTest(login_user.username):
|
||||||
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,))
|
self.client.force_login(login_user)
|
||||||
response = self.client.get(url)
|
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,))
|
||||||
self.assertEqual(response.status_code, 403)
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, 403)
|
||||||
|
|
||||||
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,))
|
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,))
|
||||||
response = self.client.get(url)
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
self.client.get(reverse('admin:logout'))
|
self.client.get(reverse('admin:logout'))
|
||||||
|
|
||||||
for login_user in [self.joepublicuser, self.nostaffuser]:
|
for login_user in [self.joepublicuser, self.nostaffuser]:
|
||||||
self.client.force_login(login_user)
|
with self.subTest(login_user.username):
|
||||||
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,))
|
self.client.force_login(login_user)
|
||||||
response = self.client.get(url, follow=True)
|
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,))
|
||||||
self.assertContains(response, 'login-form')
|
response = self.client.get(url, follow=True)
|
||||||
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,))
|
self.assertContains(response, 'login-form')
|
||||||
response = self.client.get(url, follow=True)
|
url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,))
|
||||||
self.assertContains(response, 'login-form')
|
response = self.client.get(url, follow=True)
|
||||||
|
self.assertContains(response, 'login-form')
|
||||||
|
|
||||||
self.client.get(reverse('admin:logout'))
|
self.client.get(reverse('admin:logout'))
|
||||||
|
|
||||||
def test_history_view_bad_url(self):
|
def test_history_view_bad_url(self):
|
||||||
self.client.force_login(self.changeuser)
|
self.client.force_login(self.changeuser)
|
||||||
|
|
Loading…
Reference in New Issue