From f5e7506cffc7f2c37718a0ca55de2dedbad3e23a Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Sun, 12 Aug 2018 18:27:19 -0700 Subject: [PATCH] Refs #27804 -- Used subTest in AdminViewPermissionsTest. --- tests/admin_views/tests.py | 104 +++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 50 deletions(-) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index 6b1d23e31e..83f94a3d2c 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -1813,43 +1813,45 @@ class AdminViewPermissionsTest(TestCase): change_url_6 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r6.pk,)) logins = [self.superuser, self.viewuser, self.adduser, self.changeuser, self.deleteuser] for login_user in logins: - self.client.force_login(login_user) - response = self.client.get(change_url_1) - self.assertEqual(response.status_code, 403) - response = self.client.post(change_url_1, {'name': 'changed'}) - self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id') - self.assertEqual(response.status_code, 403) - response = self.client.get(change_url_2) - self.assertEqual(response.status_code, 200) - response = self.client.post(change_url_2, {'name': 'changed'}) - self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed') - self.assertRedirects(response, self.index_url) - response = self.client.get(change_url_3) - self.assertEqual(response.status_code, 200) - response = self.client.post(change_url_3, {'name': 'changed'}) - self.assertRedirects(response, self.index_url) - self.assertEqual(RowLevelChangePermissionModel.objects.get(id=3).name, 'odd id mult 3') - response = self.client.get(change_url_6) - self.assertEqual(response.status_code, 200) - response = self.client.post(change_url_6, {'name': 'changed'}) - self.assertEqual(RowLevelChangePermissionModel.objects.get(id=6).name, 'changed') - self.assertRedirects(response, self.index_url) + with self.subTest(login_user.username): + self.client.force_login(login_user) + response = self.client.get(change_url_1) + self.assertEqual(response.status_code, 403) + response = self.client.post(change_url_1, {'name': 'changed'}) + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id') + self.assertEqual(response.status_code, 403) + response = self.client.get(change_url_2) + self.assertEqual(response.status_code, 200) + response = self.client.post(change_url_2, {'name': 'changed'}) + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed') + self.assertRedirects(response, self.index_url) + response = self.client.get(change_url_3) + self.assertEqual(response.status_code, 200) + response = self.client.post(change_url_3, {'name': 'changed'}) + self.assertRedirects(response, self.index_url) + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=3).name, 'odd id mult 3') + response = self.client.get(change_url_6) + self.assertEqual(response.status_code, 200) + response = self.client.post(change_url_6, {'name': 'changed'}) + 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]: - self.client.force_login(login_user) - response = self.client.get(change_url_1, follow=True) - self.assertContains(response, 'login-form') - response = self.client.post(change_url_1, {'name': 'changed'}, follow=True) - self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id') - self.assertContains(response, 'login-form') - response = self.client.get(change_url_2, follow=True) - self.assertContains(response, 'login-form') - response = self.client.post(change_url_2, {'name': 'changed again'}, follow=True) - self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed') - self.assertContains(response, 'login-form') - self.client.get(reverse('admin:logout')) + with self.subTest(login_user.username): + self.client.force_login(login_user) + response = self.client.get(change_url_1, follow=True) + self.assertContains(response, 'login-form') + response = self.client.post(change_url_1, {'name': 'changed'}, follow=True) + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id') + self.assertContains(response, 'login-form') + response = self.client.get(change_url_2, follow=True) + self.assertContains(response, 'login-form') + response = self.client.post(change_url_2, {'name': 'changed again'}, follow=True) + self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed') + self.assertContains(response, 'login-form') + self.client.get(reverse('admin:logout')) def test_change_view_without_object_change_permission(self): """ @@ -1997,27 +1999,29 @@ class AdminViewPermissionsTest(TestCase): rl2 = RowLevelChangePermissionModel.objects.create(name="even id") logins = [self.superuser, self.viewuser, self.adduser, self.changeuser, self.deleteuser] for login_user in logins: - self.client.force_login(login_user) - url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,)) - response = self.client.get(url) - self.assertEqual(response.status_code, 403) + with self.subTest(login_user.username): + self.client.force_login(login_user) + url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,)) + response = self.client.get(url) + self.assertEqual(response.status_code, 403) - url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,)) - response = self.client.get(url) - self.assertEqual(response.status_code, 200) + url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,)) + response = self.client.get(url) + 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]: - self.client.force_login(login_user) - url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,)) - response = self.client.get(url, follow=True) - self.assertContains(response, 'login-form') - url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,)) - response = self.client.get(url, follow=True) - self.assertContains(response, 'login-form') + with self.subTest(login_user.username): + self.client.force_login(login_user) + url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl1.pk,)) + response = self.client.get(url, follow=True) + self.assertContains(response, 'login-form') + url = reverse('admin:admin_views_rowlevelchangepermissionmodel_history', args=(rl2.pk,)) + 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): self.client.force_login(self.changeuser)