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)