From c598dfa84a9363d38b020e544ea2fd5657f912b2 Mon Sep 17 00:00:00 2001 From: Adam Wester Date: Fri, 20 Nov 2015 12:02:38 -0500 Subject: [PATCH] [1.9.x] Fixed #25781 -- Simplified admin_views tests with client.force_login() Backport of 550107ff756beeb17b465e98c26c59e3dcc5eb3e from master --- tests/admin_views/tests.py | 485 ++++++++++--------------------------- 1 file changed, 131 insertions(+), 354 deletions(-) diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index cab70c6c23..0e47a43b1d 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -73,43 +73,12 @@ class AdminViewBasicTestCase(TestCase): @classmethod def setUpTestData(cls): - # password = "secret" - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u2 = User.objects.create( - id=101, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='adduser', - first_name='Add', last_name='User', email='auser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u3 = User.objects.create( - id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', - first_name='Change', last_name='User', email='cuser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u4 = User.objects.create( - id=103, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='deleteuser', - first_name='Delete', last_name='User', email='duser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u5 = User.objects.create( - id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', - first_name='Joe', last_name='Public', email='joepublic@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u6 = User.objects.create( - id=106, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='nostaff', - first_name='No', last_name='Staff', email='nostaff@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) cls.s1 = Section.objects.create(name='Test section') cls.a1 = Article.objects.create( content='

Middle content

', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 @@ -181,7 +150,7 @@ class AdminViewBasicTestCase(TestCase): } def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def tearDown(self): formats.reset_format_cache() @@ -1021,43 +990,12 @@ class AdminViewFormUrlTest(TestCase): @classmethod def setUpTestData(cls): - # password = "secret" - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u2 = User.objects.create( - id=101, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='adduser', - first_name='Add', last_name='User', email='auser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u3 = User.objects.create( - id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', - first_name='Change', last_name='User', email='cuser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u4 = User.objects.create( - id=103, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='deleteuser', - first_name='Delete', last_name='User', email='duser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u5 = User.objects.create( - id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', - first_name='Joe', last_name='Public', email='joepublic@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u6 = User.objects.create( - id=106, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='nostaff', - first_name='No', last_name='Staff', email='nostaff@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) cls.s1 = Section.objects.create(name='Test section') cls.a1 = Article.objects.create( content='

Middle content

', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 @@ -1071,7 +1009,7 @@ class AdminViewFormUrlTest(TestCase): cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_change_form_URL_has_correct_value(self): """ @@ -1106,7 +1044,7 @@ class AdminJavaScriptTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -1114,7 +1052,7 @@ class AdminJavaScriptTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_js_minified_only_if_debug_is_false(self): """ @@ -1154,7 +1092,7 @@ class SaveAsTests(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -1163,7 +1101,7 @@ class SaveAsTests(TestCase): cls.per1 = Person.objects.create(name='John Mauchly', gender=1, alive=True) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_save_as_duplication(self): """Ensure save as actually creates a new person""" @@ -1292,12 +1230,12 @@ class CustomModelAdminTest(AdminViewBasicTestCase): self.assertContains(response, 'Hello from a custom password change done template') def test_custom_admin_site_view(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) response = self.client.get(reverse('admin2:my_view')) self.assertEqual(response.content, b"Django is a magical pony!") def test_pwd_change_custom_template(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) su = User.objects.get(username='super') try: response = self.client.get( @@ -1321,38 +1259,37 @@ class AdminViewPermissionsTest(TestCase): @classmethod def setUpTestData(cls): - super(AdminViewPermissionsTest, cls).setUpTestData() - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u2 = User.objects.create( + cls.adduser = User.objects.create( id=101, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='adduser', first_name='Add', last_name='User', email='auser@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u3 = User.objects.create( + cls.changeuser = User.objects.create( id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', first_name='Change', last_name='User', email='cuser@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u4 = User.objects.create( + cls.deleteuser = User.objects.create( id=103, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='deleteuser', first_name='Delete', last_name='User', email='duser@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u5 = User.objects.create( + cls.joepublicuser = User.objects.create( id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', first_name='Joe', last_name='Public', email='joepublic@example.com', is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u6 = User.objects.create( + cls.nostaffuser = User.objects.create( id=106, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='nostaff', first_name='No', last_name='Staff', email='nostaff@example.com', @@ -1374,14 +1311,14 @@ class AdminViewPermissionsTest(TestCase): opts = Article._meta # User who can add Articles - cls.u2.user_permissions.add(get_perm(Article, get_permission_codename('add', opts))) + cls.adduser.user_permissions.add(get_perm(Article, get_permission_codename('add', opts))) # User who can change Articles - cls.u3.user_permissions.add(get_perm(Article, get_permission_codename('change', opts))) - cls.u6.user_permissions.add(get_perm(Article, get_permission_codename('change', opts))) + cls.changeuser.user_permissions.add(get_perm(Article, get_permission_codename('change', opts))) + cls.nostaffuser.user_permissions.add(get_perm(Article, get_permission_codename('change', opts))) # User who can delete Articles - cls.u4.user_permissions.add(get_perm(Article, get_permission_codename('delete', opts))) - cls.u4.user_permissions.add(get_perm(Section, get_permission_codename('delete', Section._meta))) + cls.deleteuser.user_permissions.add(get_perm(Article, get_permission_codename('delete', opts))) + cls.deleteuser.user_permissions.add(get_perm(Section, get_permission_codename('delete', Section._meta))) # login POST dicts cls.index_url = reverse('admin:index') @@ -1595,20 +1532,17 @@ class AdminViewPermissionsTest(TestCase): self.client.login(**self.nostaff_login) response = self.client.get(self.index_url, follow=True) self.assertContains(response, 'login-form') - self.assertContains(response, hint_template.format(self.u6.username), status_code=200) + self.assertContains(response, hint_template.format(self.nostaffuser.username), status_code=200) def test_add_view(self): """Test add view restricts access and actually adds items.""" - - login_url = '%s?next=%s' % (reverse('admin:login'), reverse('admin:index')) add_dict = {'title': 'Døm ikke', 'content': '

great article

', 'date_0': '2008-03-18', 'date_1': '10:54:39', 'section': self.s1.pk} # Change User should not have access to add articles - self.client.get(self.index_url) - self.client.post(login_url, self.changeuser_login) + self.client.force_login(self.changeuser) # make sure the view removes test cookie self.assertEqual(self.client.session.test_cookie_worked(), False) response = self.client.get(reverse('admin:admin_views_article_add')) @@ -1620,8 +1554,7 @@ class AdminViewPermissionsTest(TestCase): self.client.get(reverse('admin:logout')) # Add user may login and POST to add view, then redirect to admin root - self.client.get(self.index_url) - self.client.post(login_url, self.adduser_login) + self.client.force_login(self.adduser) addpage = self.client.get(reverse('admin:admin_views_article_add')) change_list_link = '› Articles' % reverse('admin:admin_views_article_changelist') self.assertNotContains(addpage, change_list_link, @@ -1637,7 +1570,7 @@ class AdminViewPermissionsTest(TestCase): addition_log = LogEntry.objects.all()[0] new_article = Article.objects.last() article_ct = ContentType.objects.get_for_model(Article) - self.assertEqual(addition_log.user_id, self.u2.pk) + self.assertEqual(addition_log.user_id, self.adduser.pk) self.assertEqual(addition_log.content_type_id, article_ct.pk) self.assertEqual(addition_log.object_id, str(new_article.pk)) self.assertEqual(addition_log.object_repr, "Døm ikke") @@ -1645,8 +1578,7 @@ class AdminViewPermissionsTest(TestCase): self.assertEqual(addition_log.change_message, "Added.") # Super can add too, but is redirected to the change list view - self.client.get(self.index_url) - self.client.post(login_url, self.super_login) + self.client.force_login(self.superuser) addpage = self.client.get(reverse('admin:admin_views_article_add')) self.assertContains(addpage, change_list_link, msg_prefix='Unrestricted user is not given link to change list view in breadcrumbs.') @@ -1657,17 +1589,14 @@ class AdminViewPermissionsTest(TestCase): # 8509 - if a normal user is already logged in, it is possible # to change user into the superuser without error - self.client.login(username='joepublic', password='secret') + self.client.force_login(self.joepublicuser) # Check and make sure that if user expires, data still persists - self.client.get(self.index_url) - self.client.post(login_url, self.super_login) + self.client.force_login(self.superuser) # make sure the view removes test cookie self.assertEqual(self.client.session.test_cookie_worked(), False) def test_change_view(self): """Change view should restrict access and allow users to edit items.""" - - login_url = '%s?next=%s' % (reverse('admin:login'), reverse('admin:index')) change_dict = {'title': 'Ikke fordømt', 'content': '

edited article

', 'date_0': '2008-03-18', 'date_1': '10:54:39', @@ -1676,8 +1605,7 @@ class AdminViewPermissionsTest(TestCase): article_changelist_url = reverse('admin:admin_views_article_changelist') # add user should not be able to view the list of article or change any of them - self.client.get(self.index_url) - self.client.post(login_url, self.adduser_login) + self.client.force_login(self.adduser) response = self.client.get(article_changelist_url) self.assertEqual(response.status_code, 403) response = self.client.get(article_change_url) @@ -1687,8 +1615,7 @@ class AdminViewPermissionsTest(TestCase): self.client.get(reverse('admin:logout')) # change user can view all items and edit them - self.client.get(self.index_url) - self.client.post(login_url, self.changeuser_login) + self.client.force_login(self.changeuser) response = self.client.get(article_changelist_url) self.assertEqual(response.status_code, 200) response = self.client.get(article_change_url) @@ -1714,8 +1641,8 @@ class AdminViewPermissionsTest(TestCase): r2 = RowLevelChangePermissionModel.objects.create(id=2, name="even id") change_url_1 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r1.pk,)) change_url_2 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r2.pk,)) - for login_dict in [self.super_login, self.changeuser_login, self.adduser_login, self.deleteuser_login]: - self.client.post(login_url, login_dict) + for login_user in [self.superuser, self.adduser, self.changeuser, self.deleteuser]: + 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'}) @@ -1728,8 +1655,8 @@ class AdminViewPermissionsTest(TestCase): self.assertRedirects(response, self.index_url) self.client.get(reverse('admin:logout')) - for login_dict in [self.joepublic_login, self.no_username_login]: - self.client.post(login_url, login_dict) + for login_user in [self.joepublicuser, self.nostaffuser]: + self.client.force_login(login_user) response = self.client.get(change_url_1, follow=True) self.assertEqual(response.status_code, 200) self.assertContains(response, 'login-form') @@ -1748,12 +1675,11 @@ class AdminViewPermissionsTest(TestCase): def test_delete_view(self): """Delete view should restrict access and actually delete items.""" - delete_dict = {'post': 'yes'} delete_url = reverse('admin:admin_views_article_delete', args=(self.a1.pk,)) # add user should not be able to delete articles - self.client.login(**self.adduser_login) + self.client.force_login(self.adduser) response = self.client.get(delete_url) self.assertEqual(response.status_code, 403) post = self.client.post(delete_url, delete_dict) @@ -1762,7 +1688,7 @@ class AdminViewPermissionsTest(TestCase): self.client.logout() # Delete user can delete - self.client.login(**self.deleteuser_login) + self.client.force_login(self.deleteuser) response = self.client.get(reverse('admin:admin_views_section_delete', args=(self.s1.pk,))) self.assertContains(response, "

Summary

") self.assertContains(response, "
  • Articles: 3
  • ") @@ -1785,27 +1711,22 @@ class AdminViewPermissionsTest(TestCase): def test_history_view(self): """History view should restrict access.""" - - login_url = '%s?next=%s' % (reverse('admin:login'), reverse('admin:index')) - # add user should not be able to view the list of article or change any of them - self.client.get(self.index_url) - self.client.post(login_url, self.adduser_login) + self.client.force_login(self.adduser) response = self.client.get(reverse('admin:admin_views_article_history', args=(self.a1.pk,))) self.assertEqual(response.status_code, 403) self.client.get(reverse('admin:logout')) # change user can view all items and edit them - self.client.get(self.index_url) - self.client.post(login_url, self.changeuser_login) + self.client.force_login(self.changeuser) response = self.client.get(reverse('admin:admin_views_article_history', args=(self.a1.pk,))) self.assertEqual(response.status_code, 200) # Test redirection when using row-level change permissions. Refs #11513. rl1 = RowLevelChangePermissionModel.objects.create(name="odd id") rl2 = RowLevelChangePermissionModel.objects.create(name="even id") - for login_dict in [self.super_login, self.changeuser_login, self.adduser_login, self.deleteuser_login]: - self.client.post(login_url, login_dict) + for login_user in [self.superuser, self.adduser, self.changeuser, self.deleteuser]: + 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) @@ -1816,8 +1737,8 @@ class AdminViewPermissionsTest(TestCase): self.client.get(reverse('admin:logout')) - for login_dict in [self.joepublic_login, self.no_username_login]: - self.client.post(login_url, login_dict) + 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.assertEqual(response.status_code, 200) @@ -1830,7 +1751,7 @@ class AdminViewPermissionsTest(TestCase): self.client.get(reverse('admin:logout')) def test_history_view_bad_url(self): - self.client.post(reverse('admin:login'), self.changeuser_login) + self.client.force_login(self.changeuser) response = self.client.get(reverse('admin:admin_views_article_history', args=('foo',))) self.assertEqual(response.status_code, 404) @@ -1839,7 +1760,7 @@ class AdminViewPermissionsTest(TestCase): The foreign key widget should only show the "add related" button if the user has permission to add that related item. """ - self.client.login(**self.adduser_login) + self.client.force_login(self.adduser) # The user can't add sections yet, so they shouldn't see the "add section" link. url = reverse('admin:admin_views_article_add') add_link_text = 'add_id_section' @@ -1860,7 +1781,7 @@ class AdminViewPermissionsTest(TestCase): def get_change_related(response): return response.context['adminform'].form.fields['section'].widget.can_change_related - self.client.login(**self.adduser_login) + self.client.force_login(self.adduser) # The user can't change sections yet, so they shouldn't see the "change section" link. url = reverse('admin:admin_views_article_add') change_link_text = 'change_id_section' @@ -1883,7 +1804,7 @@ class AdminViewPermissionsTest(TestCase): def get_delete_related(response): return response.context['adminform'].form.fields['sub_section'].widget.can_delete_related - self.client.login(**self.adduser_login) + self.client.force_login(self.adduser) # The user can't delete sections yet, so they shouldn't see the "delete section" link. url = reverse('admin:admin_views_article_add') delete_link_text = 'delete_id_sub_section' @@ -1899,7 +1820,7 @@ class AdminViewPermissionsTest(TestCase): self.assertContains(response, delete_link_text) def test_disabled_permissions_when_logged_in(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) superuser = User.objects.get(username='super') superuser.is_active = False superuser.save() @@ -1912,7 +1833,7 @@ class AdminViewPermissionsTest(TestCase): self.assertContains(response, 'id="login-form"') def test_disabled_staff_permissions_when_logged_in(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) superuser = User.objects.get(username='super') superuser.is_staff = False superuser.save() @@ -1933,7 +1854,7 @@ class AdminViewPermissionsTest(TestCase): change_user = User.objects.get(username='changeuser') permission = get_perm(Article, get_permission_codename('change', opts)) - self.client.login(**self.changeuser_login) + self.client.force_login(self.changeuser) # the user has no module permissions, because this module doesn't exist change_user.user_permissions.remove(permission) @@ -1958,7 +1879,7 @@ class AdminViewPermissionsTest(TestCase): self.assertTemplateUsed(response, 'admin/login.html') # Logged in? Redirect. - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) response = self.client.get(shortcut_url, follow=False) # Can't use self.assertRedirects() because User.get_absolute_url() is silly. self.assertEqual(response.status_code, 302) @@ -1971,25 +1892,25 @@ class AdminViewPermissionsTest(TestCase): have any permission for that module (add, change, or delete), so that the module is displayed on the admin index page. """ - self.client.login(**self.super_login) + self.client.force_login(self.superuser) response = self.client.get(self.index_url) self.assertContains(response, 'admin_views') self.assertContains(response, 'Articles') self.client.logout() - self.client.login(**self.adduser_login) + self.client.force_login(self.adduser) response = self.client.get(self.index_url) self.assertContains(response, 'admin_views') self.assertContains(response, 'Articles') self.client.logout() - self.client.login(**self.changeuser_login) + self.client.force_login(self.changeuser) response = self.client.get(self.index_url) self.assertContains(response, 'admin_views') self.assertContains(response, 'Articles') self.client.logout() - self.client.login(**self.deleteuser_login) + self.client.force_login(self.deleteuser) response = self.client.get(self.index_url) self.assertContains(response, 'admin_views') self.assertContains(response, 'Articles') @@ -2002,25 +1923,25 @@ class AdminViewPermissionsTest(TestCase): """ index_url = reverse('admin7:index') - self.client.login(**self.super_login) + self.client.force_login(self.superuser) response = self.client.get(index_url) self.assertNotContains(response, 'admin_views') self.assertNotContains(response, 'Articles') self.client.logout() - self.client.login(**self.adduser_login) + self.client.force_login(self.adduser) response = self.client.get(index_url) self.assertNotContains(response, 'admin_views') self.assertNotContains(response, 'Articles') self.client.logout() - self.client.login(**self.changeuser_login) + self.client.force_login(self.changeuser) response = self.client.get(index_url) self.assertNotContains(response, 'admin_views') self.assertNotContains(response, 'Articles') self.client.logout() - self.client.login(**self.deleteuser_login) + self.client.force_login(self.deleteuser) response = self.client.get(index_url) self.assertNotContains(response, 'admin_views') self.assertNotContains(response, 'Articles') @@ -2033,7 +1954,7 @@ class AdminViewsNoUrlTest(TestCase): @classmethod def setUpTestData(cls): - cls.u3 = User.objects.create( + cls.changeuser = User.objects.create( id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', first_name='Change', last_name='User', email='cuser@example.com', @@ -2042,19 +1963,11 @@ class AdminViewsNoUrlTest(TestCase): opts = Report._meta # User who can change Reports - cls.u3.user_permissions.add(get_perm(Report, get_permission_codename('change', opts))) - - # login POST dict - cls.changeuser_login = { - REDIRECT_FIELD_NAME: reverse('admin:index'), - 'username': 'changeuser', - 'password': 'secret', - } + cls.changeuser.user_permissions.add(get_perm(Report, get_permission_codename('change', opts))) def test_no_standard_modeladmin_urls(self): """Admin index views don't break when user's ModelAdmin removes standard urls""" - self.client.get(reverse('admin:index')) - r = self.client.post(reverse('admin:login'), self.changeuser_login) + self.client.force_login(self.changeuser) r = self.client.get(reverse('admin:index')) # we shouldn't get a 500 error caused by a NoReverseMatch self.assertEqual(r.status_code, 200) @@ -2068,42 +1981,18 @@ class AdminViewDeletedObjectsTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u2 = User.objects.create( - id=101, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='adduser', - first_name='Add', last_name='User', email='auser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u3 = User.objects.create( - id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', - first_name='Change', last_name='User', email='cuser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u4 = User.objects.create( + cls.deleteuser = User.objects.create( id=103, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='deleteuser', first_name='Delete', last_name='User', email='duser@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u5 = User.objects.create( - id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', - first_name='Joe', last_name='Public', email='joepublic@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u6 = User.objects.create( - id=106, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='nostaff', - first_name='No', last_name='Staff', email='nostaff@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) cls.s1 = Section.objects.create(name='Test section') cls.a1 = Article.objects.create( content='

    Middle content

    ', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 @@ -2130,7 +2019,7 @@ class AdminViewDeletedObjectsTest(TestCase): cls.cy2 = CyclicTwo.objects.create(name='I am recursive too', one_id=1) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_nesting(self): """ @@ -2278,7 +2167,7 @@ class TestGenericRelations(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -2288,7 +2177,7 @@ class TestGenericRelations(TestCase): cls.pl3 = Plot.objects.create(name='Corn Conspiracy', team_leader=cls.v1, contact=cls.v1) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_generic_content_object_in_list_display(self): FunkyTag.objects.create(content_object=self.pl3, name='hott') @@ -2302,42 +2191,12 @@ class AdminViewStringPrimaryKeyTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u2 = User.objects.create( - id=101, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='adduser', - first_name='Add', last_name='User', email='auser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u3 = User.objects.create( - id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', - first_name='Change', last_name='User', email='cuser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u4 = User.objects.create( - id=103, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='deleteuser', - first_name='Delete', last_name='User', email='duser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u5 = User.objects.create( - id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', - first_name='Joe', last_name='Public', email='joepublic@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u6 = User.objects.create( - id=106, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='nostaff', - first_name='No', last_name='Staff', email='nostaff@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) cls.s1 = Section.objects.create(name='Test section') cls.a1 = Article.objects.create( content='

    Middle content

    ', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 @@ -2358,7 +2217,7 @@ class AdminViewStringPrimaryKeyTest(TestCase): LogEntry.objects.log_action(100, content_type_pk, cls.pk, cls.pk, 2, change_message='Changed something') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_get_history_view(self): """ @@ -2541,15 +2400,6 @@ class SecureViewTests(TestCase): Test behavior of a view protected by the staff_member_required decorator. """ - @classmethod - def setUpTestData(cls): - cls.u1 = User.objects.create( - id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', - first_name='Super', last_name='User', email='super@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - def test_secure_view_shows_login_if_not_logged_in(self): """ Ensure that we see the admin login form. @@ -2577,7 +2427,7 @@ class AdminViewUnicodeTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -2600,7 +2450,7 @@ class AdminViewUnicodeTest(TestCase): cls.chap9 = ChapterXtra2.objects.create(chap=cls.chap3, xtra='') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_unicode_edit(self): """ @@ -2653,42 +2503,12 @@ class AdminViewListEditable(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u2 = User.objects.create( - id=101, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='adduser', - first_name='Add', last_name='User', email='auser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u3 = User.objects.create( - id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', - first_name='Change', last_name='User', email='cuser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u4 = User.objects.create( - id=103, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='deleteuser', - first_name='Delete', last_name='User', email='duser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u5 = User.objects.create( - id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', - first_name='Joe', last_name='Public', email='joepublic@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u6 = User.objects.create( - id=106, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='nostaff', - first_name='No', last_name='Staff', email='nostaff@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) cls.s1 = Section.objects.create(name='Test section') cls.a1 = Article.objects.create( content='

    Middle content

    ', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 @@ -2705,7 +2525,7 @@ class AdminViewListEditable(TestCase): cls.per3 = Person.objects.create(name='Guido van Rossum', gender=1, alive=True) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_inheritance(self): Podcast.objects.create(name="This Week in Django", @@ -3116,42 +2936,18 @@ class AdminSearchTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u2 = User.objects.create( - id=101, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='adduser', - first_name='Add', last_name='User', email='auser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u3 = User.objects.create( - id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', - first_name='Change', last_name='User', email='cuser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u4 = User.objects.create( - id=103, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='deleteuser', - first_name='Delete', last_name='User', email='duser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u5 = User.objects.create( + cls.joepublicuser = User.objects.create( id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', first_name='Joe', last_name='Public', email='joepublic@example.com', is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u6 = User.objects.create( - id=106, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='nostaff', - first_name='No', last_name='Staff', email='nostaff@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) cls.s1 = Section.objects.create(name='Test section') cls.a1 = Article.objects.create( content='

    Middle content

    ', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 @@ -3179,7 +2975,7 @@ class AdminSearchTest(TestCase): cls.tt4 = TitleTranslation.objects.create(title=cls.t4, text='Bas') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_search_on_sibling_models(self): "Check that a search that mentions sibling models" @@ -3264,7 +3060,7 @@ class AdminInheritedInlinesTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -3272,11 +3068,10 @@ class AdminInheritedInlinesTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_inline(self): "Ensure that inline models which inherit from a common parent are correctly handled by admin." - foo_user = "foo username" bar_user = "bar username" @@ -3357,7 +3152,7 @@ class AdminActionsTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -3367,7 +3162,7 @@ class AdminActionsTest(TestCase): cls.s2 = Subscriber.objects.create(name='Max Mustermann', email='max@example.org') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_model_admin_custom_action(self): "Tests a custom action defined in a ModelAdmin method" @@ -3668,7 +3463,7 @@ class TestCustomChangeList(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -3701,7 +3496,7 @@ class TestInlineNotEditable(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -3726,7 +3521,7 @@ class AdminCustomQuerysetTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -3734,7 +3529,7 @@ class AdminCustomQuerysetTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) self.pks = [EmptyModel.objects.create().id for i in range(3)] self.super_login = { REDIRECT_FIELD_NAME: reverse('admin:index'), @@ -3986,7 +3781,7 @@ class AdminInlineFileUploadTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -3994,7 +3789,7 @@ class AdminInlineFileUploadTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) # Set up test Picture and Gallery. # These must be set up here instead of in fixtures in order to allow Picture @@ -4038,7 +3833,7 @@ class AdminInlineTests(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -4364,7 +4159,7 @@ class NeverCacheTests(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -4373,7 +4168,7 @@ class NeverCacheTests(TestCase): cls.s1 = Section.objects.create(name='Test section') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_admin_index(self): "Check the never-cache status of the main index" @@ -4444,7 +4239,7 @@ class PrePopulatedTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -4453,7 +4248,7 @@ class PrePopulatedTest(TestCase): cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_prepopulated_on(self): response = self.client.get(reverse('admin:admin_views_prepopulatedpost_add')) @@ -4488,7 +4283,7 @@ class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase): webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver' def setUp(self): - self.u1 = User.objects.create( + self.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -4759,7 +4554,7 @@ class ReadonlyTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -4767,7 +4562,7 @@ class ReadonlyTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) @ignore_warnings(category=RemovedInDjango20Warning) # for allow_tags deprecation def test_readonly_get(self): @@ -4900,7 +4695,7 @@ class LimitChoicesToInAdminTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -4908,7 +4703,7 @@ class LimitChoicesToInAdminTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_limit_choices_to_as_callable(self): """Test for ticket 2445 changes to admin.""" @@ -4932,7 +4727,7 @@ class RawIdFieldsTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -4940,7 +4735,7 @@ class RawIdFieldsTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_limit_choices_to(self): """Regression test for 14880""" @@ -5030,42 +4825,24 @@ class UserAdminTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u2 = User.objects.create( + cls.adduser = User.objects.create( id=101, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='adduser', first_name='Add', last_name='User', email='auser@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u3 = User.objects.create( + cls.changeuser = User.objects.create( id=102, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='changeuser', first_name='Change', last_name='User', email='cuser@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u4 = User.objects.create( - id=103, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='deleteuser', - first_name='Delete', last_name='User', email='duser@example.com', - is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u5 = User.objects.create( - id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', - first_name='Joe', last_name='Public', email='joepublic@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) - cls.u6 = User.objects.create( - id=106, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', - last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='nostaff', - first_name='No', last_name='Staff', email='nostaff@example.com', - is_staff=False, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) - ) cls.s1 = Section.objects.create(name='Test section') cls.a1 = Article.objects.create( content='

    Middle content

    ', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 @@ -5083,7 +4860,7 @@ class UserAdminTest(TestCase): cls.per3 = Person.objects.create(name='Guido van Rossum', gender=1, alive=True) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_save_button(self): user_count = User.objects.count() @@ -5227,7 +5004,7 @@ class GroupAdminTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -5235,7 +5012,7 @@ class GroupAdminTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_save_button(self): group_count = Group.objects.count() @@ -5264,7 +5041,7 @@ class CSSTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -5283,7 +5060,7 @@ class CSSTest(TestCase): cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) @ignore_warnings(category=RemovedInDjango20Warning) # for allow_tags deprecation def test_field_prefix_css_classes(self): @@ -5407,7 +5184,7 @@ class AdminDocsTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -5415,7 +5192,7 @@ class AdminDocsTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_tags(self): response = self.client.get(reverse('django-admindocs-tags')) @@ -5470,7 +5247,7 @@ class ValidXHTMLTests(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -5478,7 +5255,7 @@ class ValidXHTMLTests(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_lang_name_present(self): response = self.client.get(reverse('admin:app_list', args=('admin_views',))) @@ -5493,7 +5270,7 @@ class DateHierarchyTests(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -5501,7 +5278,7 @@ class DateHierarchyTests(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def tearDown(self): formats.reset_format_cache() @@ -5627,7 +5404,7 @@ class AdminCustomSaveRelatedTests(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -5635,7 +5412,7 @@ class AdminCustomSaveRelatedTests(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_should_be_able_to_edit_related_objects_on_add_view(self): post = { @@ -5700,7 +5477,7 @@ class AdminViewLogoutTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -5708,7 +5485,7 @@ class AdminViewLogoutTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_client_logout_url_can_be_used_to_login(self): response = self.client.get(reverse('admin:logout')) @@ -5734,7 +5511,7 @@ class AdminUserMessageTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -5742,7 +5519,7 @@ class AdminUserMessageTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def send_message(self, level): """ @@ -5798,13 +5575,13 @@ class AdminKeepChangeListFiltersTests(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) ) - cls.u5 = User.objects.create( + cls.joepublicuser = User.objects.create( id=104, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=False, username='joepublic', first_name='Joe', last_name='Public', email='joepublic@example.com', @@ -5812,7 +5589,7 @@ class AdminKeepChangeListFiltersTests(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def assertURLEqual(self, url1, url2): """ @@ -5838,7 +5615,7 @@ class AdminKeepChangeListFiltersTests(TestCase): def test_assert_url_equal(self): # Test equality. - change_user_url = reverse('admin:auth_user_change', args=(self.u5.pk,)) + change_user_url = reverse('admin:auth_user_change', args=(self.joepublicuser.pk,)) self.assertURLEqual( 'http://testserver{}?_changelist_filters=is_staff__exact%3D0%26is_superuser__exact%3D0'.format( change_user_url @@ -5894,7 +5671,7 @@ class AdminKeepChangeListFiltersTests(TestCase): }) def get_sample_user_id(self): - return self.u5.pk + return self.joepublicuser.pk def get_changelist_url(self): return '%s?%s' % ( @@ -5943,7 +5720,7 @@ class AdminKeepChangeListFiltersTests(TestCase): # Check the `change_view` link has the correct querystring. detail_link = re.search( - '{}'.format(self.u5.username), + '{}'.format(self.joepublicuser.username), force_text(response.content) ) self.assertURLEqual(detail_link.group(1), self.get_change_url()) @@ -6102,7 +5879,7 @@ class TestLabelVisibility(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -6110,7 +5887,7 @@ class TestLabelVisibility(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_all_fields_visible(self): response = self.client.get(reverse('admin:admin_views_emptymodelvisible_add')) @@ -6149,7 +5926,7 @@ class AdminViewOnSiteTests(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -6173,7 +5950,7 @@ class AdminViewOnSiteTests(TestCase): cls.w3 = Worker.objects.create(work_at=cls.r1, name='John', surname='Doe') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_add_view_form_and_formsets_run_validation(self): """ @@ -6286,7 +6063,7 @@ class InlineAdminViewOnSiteTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -6310,7 +6087,7 @@ class InlineAdminViewOnSiteTest(TestCase): cls.w3 = Worker.objects.create(work_at=cls.r1, name='John', surname='Doe') def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_false(self): "Ensure that the 'View on site' button is not displayed if view_on_site is False" @@ -6361,7 +6138,7 @@ class GetFormsetsWithInlinesArgumentTest(TestCase): @classmethod def setUpTestData(cls): - cls.u1 = User.objects.create( + cls.superuser = User.objects.create( id=100, password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', first_name='Super', last_name='User', email='super@example.com', @@ -6369,7 +6146,7 @@ class GetFormsetsWithInlinesArgumentTest(TestCase): ) def setUp(self): - self.client.login(username='super', password='secret') + self.client.force_login(self.superuser) def test_explicitly_provided_pk(self): post_data = {'name': '1'}