Fixed #26175 -- Removed SHA1 password hashes in tests.

This commit is contained in:
Tim Graham 2016-02-05 15:56:52 -05:00
parent f8e865d78f
commit 015fad9060
25 changed files with 220 additions and 832 deletions

View File

@ -480,9 +480,8 @@ class ChangeListTests(TestCase):
Regression test for #13196: output of functions should be localized Regression test for #13196: output of functions should be localized
in the changelist. in the changelist.
""" """
User.objects.create_superuser( superuser = User.objects.create_superuser(username='super', email='super@localhost', password='secret')
username='super', email='super@localhost', password='secret') self.client.force_login(superuser)
self.client.login(username='super', password='secret')
event = Event.objects.create(date=datetime.date.today()) event = Event.objects.create(date=datetime.date.today())
response = self.client.get(reverse('admin:admin_changelist_event_changelist')) response = self.client.get(reverse('admin:admin_changelist_event_changelist'))
self.assertContains(response, formats.localize(event.date)) self.assertContains(response, formats.localize(event.date))
@ -882,21 +881,14 @@ class AdminLogNodeTestCase(TestCase):
self.assertEqual(t.render(Context({})), 'Added "<User: jondoe>".') self.assertEqual(t.render(Context({})), 'Added "<User: jondoe>".')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_changelist.urls')
ROOT_URLCONF="admin_changelist.urls")
class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
available_apps = ['admin_changelist'] + AdminSeleniumWebDriverTestCase.available_apps available_apps = ['admin_changelist'] + AdminSeleniumWebDriverTestCase.available_apps
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
def setUp(self): def setUp(self):
# password = "secret" User.objects.create_superuser(username='super', password='secret', email=None)
User.objects.create(
pk=100, username='super', first_name='Super', last_name='User', email='super@example.com',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=True,
is_staff=True, last_login=datetime.datetime(2007, 5, 30, 13, 20, 10),
date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10)
)
def test_add_row_selection(self): def test_add_row_selection(self):
""" """

View File

@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
from django.contrib.admin.utils import quote from django.contrib.admin.utils import quote
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.template.response import TemplateResponse from django.template.response import TemplateResponse
@ -11,8 +9,7 @@ from django.urls import reverse
from .models import Action, Car, Person from .models import Action, Car, Person
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_custom_urls.urls',)
ROOT_URLCONF='admin_custom_urls.urls',)
class AdminCustomUrlsTest(TestCase): class AdminCustomUrlsTest(TestCase):
""" """
Remember that: Remember that:
@ -23,13 +20,7 @@ class AdminCustomUrlsTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
# password = "secret" cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
User.objects.create(
pk=100, username='super', first_name='Super', last_name='User', email='super@example.com',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=True,
is_staff=True, last_login=datetime.datetime(2007, 5, 30, 13, 20, 10),
date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10)
)
Action.objects.create(name='delete', description='Remove things.') Action.objects.create(name='delete', description='Remove things.')
Action.objects.create(name='rename', description='Gives things other names.') Action.objects.create(name='rename', description='Gives things other names.')
Action.objects.create(name='add', description='Add things.') Action.objects.create(name='add', description='Add things.')
@ -44,7 +35,7 @@ class AdminCustomUrlsTest(TestCase):
) )
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
def test_basic_add_GET(self): def test_basic_add_GET(self):
""" """

View File

@ -1,4 +1,3 @@
import datetime
import sys import sys
import unittest import unittest
@ -18,18 +17,10 @@ class TestDataMixin(object):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
# password = "secret" cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
User.objects.create(
pk=100, username='super', first_name='Super', last_name='User', email='super@example.com',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=True,
is_staff=True, last_login=datetime.datetime(2007, 5, 30, 13, 20, 10),
date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10)
)
@override_settings( @override_settings(ROOT_URLCONF='admin_docs.urls')
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF='admin_docs.urls')
@modify_settings(INSTALLED_APPS={'append': 'django.contrib.admindocs'}) @modify_settings(INSTALLED_APPS={'append': 'django.contrib.admindocs'})
class AdminDocsTestCase(TestCase): class AdminDocsTestCase(TestCase):
pass pass
@ -38,8 +29,8 @@ class AdminDocsTestCase(TestCase):
class MiscTests(AdminDocsTestCase): class MiscTests(AdminDocsTestCase):
def setUp(self): def setUp(self):
User.objects.create_superuser('super', None, 'secret') superuser = User.objects.create_superuser('super', None, 'secret')
self.client.login(username='super', password='secret') self.client.force_login(superuser)
@modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'}) @modify_settings(INSTALLED_APPS={'remove': 'django.contrib.sites'})
@override_settings(SITE_ID=None) # will restore SITE_ID after the test @override_settings(SITE_ID=None) # will restore SITE_ID after the test
@ -57,7 +48,7 @@ class MiscTests(AdminDocsTestCase):
class AdminDocViewTests(TestDataMixin, AdminDocsTestCase): class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
def test_index(self): def test_index(self):
self.client.logout() self.client.logout()
@ -65,7 +56,7 @@ class AdminDocViewTests(TestDataMixin, AdminDocsTestCase):
# Should display the login screen # Should display the login screen
self.assertContains(response, self.assertContains(response,
'<input type="hidden" name="next" value="/admindocs/" />', html=True) '<input type="hidden" name="next" value="/admindocs/" />', html=True)
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
response = self.client.get(reverse('django-admindocs-docroot')) response = self.client.get(reverse('django-admindocs-docroot'))
self.assertContains(response, '<h1>Documentation</h1>', html=True) self.assertContains(response, '<h1>Documentation</h1>', html=True)
self.assertContains(response, self.assertContains(response,
@ -168,7 +159,7 @@ class XViewMiddlewareTest(TestDataMixin, AdminDocsTestCase):
user = User.objects.get(username='super') user = User.objects.get(username='super')
response = self.client.head('/xview/func/') response = self.client.head('/xview/func/')
self.assertNotIn('X-View', response) self.assertNotIn('X-View', response)
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
response = self.client.head('/xview/func/') response = self.client.head('/xview/func/')
self.assertIn('X-View', response) self.assertIn('X-View', response)
self.assertEqual(response['X-View'], 'admin_docs.views.xview') self.assertEqual(response['X-View'], 'admin_docs.views.xview')
@ -186,7 +177,7 @@ class XViewMiddlewareTest(TestDataMixin, AdminDocsTestCase):
user = User.objects.get(username='super') user = User.objects.get(username='super')
response = self.client.head('/xview/class/') response = self.client.head('/xview/class/')
self.assertNotIn('X-View', response) self.assertNotIn('X-View', response)
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
response = self.client.head('/xview/class/') response = self.client.head('/xview/class/')
self.assertIn('X-View', response) self.assertIn('X-View', response)
self.assertEqual(response['X-View'], 'admin_docs.views.XViewClass') self.assertEqual(response['X-View'], 'admin_docs.views.XViewClass')
@ -244,7 +235,7 @@ class TestModelDetailView(TestDataMixin, AdminDocsTestCase):
""" """
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
with captured_stderr() as self.docutils_stderr: with captured_stderr() as self.docutils_stderr:
self.response = self.client.get(reverse('django-admindocs-models-detail', args=['admin_docs', 'Person'])) self.response = self.client.get(reverse('django-admindocs-models-detail', args=['admin_docs', 'Person']))

View File

@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
from django.contrib.admin import ModelAdmin, TabularInline from django.contrib.admin import ModelAdmin, TabularInline
from django.contrib.admin.helpers import InlineAdminForm from django.contrib.admin.helpers import InlineAdminForm
from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase from django.contrib.admin.tests import AdminSeleniumWebDriverTestCase
@ -26,17 +24,10 @@ class TestDataMixin(object):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
# password = "secret" cls.superuser = User.objects.create_superuser(username='super', email='super@example.com', password='secret')
User.objects.create(
pk=100, username='super', first_name='Super', last_name='User', email='super@example.com',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=True,
is_staff=True, last_login=datetime.datetime(2007, 5, 30, 13, 20, 10),
date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10)
)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_inlines.urls')
ROOT_URLCONF="admin_inlines.urls")
class TestInline(TestDataMixin, TestCase): class TestInline(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
@ -44,8 +35,7 @@ class TestInline(TestDataMixin, TestCase):
holder.save() holder.save()
Inner(dummy=42, holder=holder).save() Inner(dummy=42, holder=holder).save()
result = self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
self.assertEqual(result, True)
self.factory = RequestFactory() self.factory = RequestFactory()
def test_can_delete(self): def test_can_delete(self):
@ -418,13 +408,11 @@ class TestInline(TestDataMixin, TestCase):
self.assertNotContains(response, INLINE_CHANGELINK_HTML) self.assertNotContains(response, INLINE_CHANGELINK_HTML)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_inlines.urls')
ROOT_URLCONF="admin_inlines.urls")
class TestInlineMedia(TestDataMixin, TestCase): class TestInlineMedia(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
result = self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
self.assertEqual(result, True)
def test_inline_media_only_base(self): def test_inline_media_only_base(self):
holder = Holder(dummy=13) holder = Holder(dummy=13)
@ -452,7 +440,7 @@ class TestInlineMedia(TestDataMixin, TestCase):
self.assertContains(response, 'my_awesome_inline_scripts.js') self.assertContains(response, 'my_awesome_inline_scripts.js')
@override_settings(ROOT_URLCONF="admin_inlines.urls") @override_settings(ROOT_URLCONF='admin_inlines.urls')
class TestInlineAdminForm(TestCase): class TestInlineAdminForm(TestCase):
def test_immutable_content_type(self): def test_immutable_content_type(self):
@ -471,13 +459,11 @@ class TestInlineAdminForm(TestCase):
self.assertEqual(iaf.original.content_type, parent_ct) self.assertEqual(iaf.original.content_type, parent_ct)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_inlines.urls')
ROOT_URLCONF="admin_inlines.urls")
class TestInlineProtectedOnDelete(TestDataMixin, TestCase): class TestInlineProtectedOnDelete(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
result = self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
self.assertEqual(result, True)
def test_deleting_inline_with_protected_delete_does_not_validate(self): def test_deleting_inline_with_protected_delete_does_not_validate(self):
lotr = Novel.objects.create(name='Lord of the rings') lotr = Novel.objects.create(name='Lord of the rings')
@ -503,7 +489,7 @@ class TestInlineProtectedOnDelete(TestDataMixin, TestCase):
% (chapter, foot_note)) % (chapter, foot_note))
@override_settings(ROOT_URLCONF="admin_inlines.urls") @override_settings(ROOT_URLCONF='admin_inlines.urls')
class TestInlinePermissions(TestCase): class TestInlinePermissions(TestCase):
""" """
Make sure the admin respects permissions for objects that are edited Make sure the admin respects permissions for objects that are edited
@ -546,9 +532,7 @@ class TestInlinePermissions(TestCase):
self.holder_change_url = reverse('admin:admin_inlines_holder2_change', args=(holder.id,)) self.holder_change_url = reverse('admin:admin_inlines_holder2_change', args=(holder.id,))
self.inner2_id = inner2.id self.inner2_id = inner2.id
self.assertEqual( self.client.force_login(self.user)
self.client.login(username='admin', password='secret'),
True)
def test_inline_add_m2m_noperm(self): def test_inline_add_m2m_noperm(self):
response = self.client.get(reverse('admin:admin_inlines_author_add')) response = self.client.get(reverse('admin:admin_inlines_author_add'))
@ -703,21 +687,14 @@ class TestInlinePermissions(TestCase):
self.assertContains(response, 'id="id_inner2_set-0-DELETE"') self.assertContains(response, 'id="id_inner2_set-0-DELETE"')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_inlines.urls')
ROOT_URLCONF="admin_inlines.urls")
class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase): class SeleniumFirefoxTests(AdminSeleniumWebDriverTestCase):
available_apps = ['admin_inlines'] + AdminSeleniumWebDriverTestCase.available_apps available_apps = ['admin_inlines'] + AdminSeleniumWebDriverTestCase.available_apps
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
def setUp(self): def setUp(self):
# password = "secret" User.objects.create_superuser(username='super', password='secret', email='super@example.com')
User.objects.create(
pk=100, username='super', first_name='Super', last_name='User', email='super@example.com',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=True,
is_staff=True, last_login=datetime.datetime(2007, 5, 30, 13, 20, 10),
date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10)
)
def test_add_stackeds(self): def test_add_stackeds(self):
""" """

View File

@ -20,12 +20,7 @@ from .models import Article, ArticleProxy, Site
@override_settings(ROOT_URLCONF="admin_utils.urls") @override_settings(ROOT_URLCONF="admin_utils.urls")
class LogEntryTests(TestCase): class LogEntryTests(TestCase):
def setUp(self): def setUp(self):
self.user = User.objects.create( self.user = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158',
is_superuser=True, username='super',
first_name='Super', last_name='User', email='super@example.com',
is_staff=True, is_active=True, date_joined=datetime(2007, 5, 30, 13, 20, 10)
)
self.site = Site.objects.create(domain='example.org') self.site = Site.objects.create(domain='example.org')
self.a1 = Article.objects.create( self.a1 = Article.objects.create(
site=self.site, site=self.site,

View File

@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
from django.conf.urls import url from django.conf.urls import url
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -20,10 +18,7 @@ urlpatterns = [
] ]
@override_settings( @override_settings(ROOT_URLCONF='admin_views.test_adminsite')
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF="admin_views.test_adminsite",
)
class SiteEachContextTest(TestCase): class SiteEachContextTest(TestCase):
""" """
Check each_context contains the documented variables and that available_apps context Check each_context contains the documented variables and that available_apps context
@ -31,12 +26,7 @@ class SiteEachContextTest(TestCase):
""" """
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = User.objects.create( cls.u1 = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
factory = RequestFactory() factory = RequestFactory()

View File

@ -104,19 +104,12 @@ class AdminFieldExtractionMixin(object):
return field return field
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls', USE_I18N=True, USE_L10N=False, LANGUAGE_CODE='en')
ROOT_URLCONF="admin_views.urls",
USE_I18N=True, USE_L10N=False, LANGUAGE_CODE='en')
class AdminViewBasicTestCase(TestCase): class AdminViewBasicTestCase(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
@ -995,19 +988,13 @@ class AdminCustomTemplateTests(AdminViewBasicTestCase):
self.assertTemplateUsed(response, 'custom_filter_template.html') self.assertTemplateUsed(response, 'custom_filter_template.html')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewFormUrlTest(TestCase): class AdminViewFormUrlTest(TestCase):
current_app = "admin3" current_app = "admin3"
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
@ -1050,18 +1037,12 @@ class AdminViewFormUrlTest(TestCase):
self.assertContains(response, 'value="overridden_value"') self.assertContains(response, 'value="overridden_value"')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminJavaScriptTest(TestCase): class AdminJavaScriptTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -1098,18 +1079,12 @@ class AdminJavaScriptTest(TestCase):
self.assertNotContains(response, 'inlines.min.js') self.assertNotContains(response, 'inlines.min.js')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class SaveAsTests(TestCase): class SaveAsTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.per1 = Person.objects.create(name='John Mauchly', gender=1, alive=True) cls.per1 = Person.objects.create(name='John Mauchly', gender=1, alive=True)
def setUp(self): def setUp(self):
@ -1177,7 +1152,7 @@ class SaveAsTests(TestCase):
self.assertTrue(response.context['show_save_as_new']) self.assertTrue(response.context['show_save_as_new'])
@override_settings(ROOT_URLCONF="admin_views.urls") @override_settings(ROOT_URLCONF='admin_views.urls')
class CustomModelAdminTest(AdminViewBasicTestCase): class CustomModelAdminTest(AdminViewBasicTestCase):
def test_custom_admin_site_login_form(self): def test_custom_admin_site_login_form(self):
@ -1264,49 +1239,18 @@ def get_perm(Model, perm):
return Permission.objects.get(content_type=ct, codename=perm) return Permission.objects.get(content_type=ct, codename=perm)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewPermissionsTest(TestCase): class AdminViewPermissionsTest(TestCase):
"""Tests for Admin Views Permissions.""" """Tests for Admin Views Permissions."""
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', cls.adduser = User.objects.create_user(username='adduser', password='secret', is_staff=True)
last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', cls.changeuser = User.objects.create_user(username='changeuser', password='secret', is_staff=True)
first_name='Super', last_name='User', email='super@example.com', cls.deleteuser = User.objects.create_user(username='deleteuser', password='secret', is_staff=True)
is_staff=True, is_active=True, date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10) cls.joepublicuser = User.objects.create_user(username='joepublic', password='secret')
) cls.nostaffuser = User.objects.create_user(username='nostaff', password='secret')
cls.adduser = User.objects.create(
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.changeuser = User.objects.create(
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.deleteuser = User.objects.create(
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.joepublicuser = User.objects.create(
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.nostaffuser = User.objects.create(
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.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1, content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1,
@ -1542,7 +1486,7 @@ class AdminViewPermissionsTest(TestCase):
self.assertNotContains(response, hint_template.format(''), status_code=200) self.assertNotContains(response, hint_template.format(''), status_code=200)
# Non-staff user should be shown the hint # Non-staff user should be shown the hint
self.client.login(**self.nostaff_login) self.client.force_login(self.nostaffuser)
response = self.client.get(self.index_url, follow=True) response = self.client.get(self.index_url, follow=True)
self.assertContains(response, 'login-form') self.assertContains(response, 'login-form')
self.assertContains(response, hint_template.format(self.nostaffuser.username), status_code=200) self.assertContains(response, hint_template.format(self.nostaffuser.username), status_code=200)
@ -1987,8 +1931,7 @@ class AdminViewPermissionsTest(TestCase):
Post-save message shouldn't contain a link to the change form if the Post-save message shouldn't contain a link to the change form if the
user doen't have the change permission. user doen't have the change permission.
""" """
login = self.client.post(reverse('admin:login'), self.adduser_login) self.client.force_login(self.adduser)
self.assertRedirects(login, self.index_url)
# Emulate Article creation for user with add-only permission. # Emulate Article creation for user with add-only permission.
post_data = { post_data = {
"title": "Fun & games", "title": "Fun & games",
@ -2005,23 +1948,15 @@ class AdminViewPermissionsTest(TestCase):
) )
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewsNoUrlTest(TestCase): class AdminViewsNoUrlTest(TestCase):
"""Regression test for #17333""" """Regression test for #17333"""
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.changeuser = User.objects.create(
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)
)
opts = Report._meta
# User who can change Reports # User who can change Reports
cls.changeuser.user_permissions.add(get_perm(Report, get_permission_codename('change', opts))) cls.changeuser = User.objects.create_user(username='changeuser', password='secret', is_staff=True)
cls.changeuser.user_permissions.add(get_perm(Report, get_permission_codename('change', Report._meta)))
def test_no_standard_modeladmin_urls(self): def test_no_standard_modeladmin_urls(self):
"""Admin index views don't break when user's ModelAdmin removes standard urls""" """Admin index views don't break when user's ModelAdmin removes standard urls"""
@ -2033,24 +1968,13 @@ class AdminViewsNoUrlTest(TestCase):
@skipUnlessDBFeature('can_defer_constraint_checks') @skipUnlessDBFeature('can_defer_constraint_checks')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewDeletedObjectsTest(TestCase): class AdminViewDeletedObjectsTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', cls.deleteuser = User.objects.create_user(username='deleteuser', password='secret', is_staff=True)
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.deleteuser = User.objects.create(
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
@ -2115,12 +2039,9 @@ class AdminViewDeletedObjectsTest(TestCase):
def test_perms_needed(self): def test_perms_needed(self):
self.client.logout() self.client.logout()
delete_user = User.objects.get(username='deleteuser') delete_user = User.objects.get(username='deleteuser')
delete_user.user_permissions.add(get_perm(Plot, delete_user.user_permissions.add(get_perm(Plot, get_permission_codename('delete', Plot._meta)))
get_permission_codename('delete', Plot._meta)))
self.assertTrue(self.client.login(username='deleteuser',
password='secret'))
self.client.force_login(self.deleteuser)
response = self.client.get(reverse('admin:admin_views_plot_delete', args=(self.pl1.pk,))) response = self.client.get(reverse('admin:admin_views_plot_delete', args=(self.pl1.pk,)))
self.assertContains(response, "your account doesn't have permission to delete the following types of objects") self.assertContains(response, "your account doesn't have permission to delete the following types of objects")
self.assertContains(response, "<li>plot details</li>") self.assertContains(response, "<li>plot details</li>")
@ -2219,18 +2140,12 @@ class AdminViewDeletedObjectsTest(TestCase):
self.assertContains(response, should_contain) self.assertContains(response, should_contain)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class TestGenericRelations(TestCase): class TestGenericRelations(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.v1 = Villain.objects.create(name='Adam') cls.v1 = Villain.objects.create(name='Adam')
cls.pl3 = Plot.objects.create(name='Corn Conspiracy', team_leader=cls.v1, contact=cls.v1) cls.pl3 = Plot.objects.create(name='Corn Conspiracy', team_leader=cls.v1, contact=cls.v1)
@ -2243,18 +2158,12 @@ class TestGenericRelations(TestCase):
self.assertContains(response, "%s</td>" % self.pl3) self.assertContains(response, "%s</td>" % self.pl3)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewStringPrimaryKeyTest(TestCase): class AdminViewStringPrimaryKeyTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
@ -2400,8 +2309,7 @@ class AdminViewStringPrimaryKeyTest(TestCase):
self.assertIn('/123_2Fhistory/', response['location']) # PK is quoted self.assertIn('/123_2Fhistory/', response['location']) # PK is quoted
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class SecureViewTests(TestCase): class SecureViewTests(TestCase):
""" """
Test behavior of a view protected by the staff_member_required decorator. Test behavior of a view protected by the staff_member_required decorator.
@ -2428,18 +2336,12 @@ class SecureViewTests(TestCase):
self.assertRedirects(response, '%s?myfield=%s' % (reverse('admin:login'), secure_url)) self.assertRedirects(response, '%s?myfield=%s' % (reverse('admin:login'), secure_url))
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewUnicodeTest(TestCase): class AdminViewUnicodeTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.b1 = Book.objects.create(name='Lærdommer') cls.b1 = Book.objects.create(name='Lærdommer')
cls.p1 = Promo.objects.create(name='<Promo for Lærdommer>', book=cls.b1) cls.p1 = Promo.objects.create(name='<Promo for Lærdommer>', book=cls.b1)
cls.chap1 = Chapter.objects.create( cls.chap1 = Chapter.objects.create(
@ -2504,18 +2406,12 @@ class AdminViewUnicodeTest(TestCase):
self.assertRedirects(response, reverse('admin:admin_views_book_changelist')) self.assertRedirects(response, reverse('admin:admin_views_book_changelist'))
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewListEditable(TestCase): class AdminViewListEditable(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
@ -2937,24 +2833,13 @@ class AdminViewListEditable(TestCase):
self.assertContains(response, '<th class="field-id"><a href="%s">%d</a></th>' % (link2, story2.id), 1) self.assertContains(response, '<th class="field-id"><a href="%s">%d</a></th>' % (link2, story2.id), 1)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminSearchTest(TestCase): class AdminSearchTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', cls.joepublicuser = User.objects.create_user(username='joepublic', password='secret')
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.joepublicuser = User.objects.create(
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
@ -3061,18 +2946,12 @@ class AdminSearchTest(TestCase):
self.assertTrue(response.context['cl'].show_admin_actions) self.assertTrue(response.context['cl'].show_admin_actions)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminInheritedInlinesTest(TestCase): class AdminInheritedInlinesTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -3153,18 +3032,12 @@ class AdminInheritedInlinesTest(TestCase):
self.assertEqual(Persona.objects.all()[0].accounts.count(), 2) self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminActionsTest(TestCase): class AdminActionsTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = ExternalSubscriber.objects.create(name='John Doe', email='john@example.org') cls.s1 = ExternalSubscriber.objects.create(name='John Doe', email='john@example.org')
cls.s2 = Subscriber.objects.create(name='Max Mustermann', email='max@example.org') cls.s2 = Subscriber.objects.create(name='Max Mustermann', email='max@example.org')
@ -3460,22 +3333,15 @@ action)</option>
) )
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class TestCustomChangeList(TestCase): class TestCustomChangeList(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
result = self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
self.assertEqual(result, True)
def test_custom_changelist(self): def test_custom_changelist(self):
""" """
@ -3493,22 +3359,15 @@ class TestCustomChangeList(TestCase):
self.assertNotContains(response, 'First Gadget') self.assertNotContains(response, 'First Gadget')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class TestInlineNotEditable(TestCase): class TestInlineNotEditable(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
result = self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
self.assertEqual(result, True)
def test_GET_parent_add(self): def test_GET_parent_add(self):
""" """
@ -3518,18 +3377,12 @@ class TestInlineNotEditable(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminCustomQuerysetTest(TestCase): class AdminCustomQuerysetTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -3787,18 +3640,12 @@ class AdminCustomQuerysetTest(TestCase):
) )
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminInlineFileUploadTest(TestCase): class AdminInlineFileUploadTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -3839,18 +3686,12 @@ class AdminInlineFileUploadTest(TestCase):
self.assertContains(response, b"Currently") self.assertContains(response, b"Currently")
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminInlineTests(TestCase): class AdminInlineTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.post_data = { self.post_data = {
@ -3938,8 +3779,7 @@ class AdminInlineTests(TestCase):
"category_set-2-collector": "1", "category_set-2-collector": "1",
} }
result = self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
self.assertEqual(result, True)
self.collector = Collector(pk=1, name='John Fowles') self.collector = Collector(pk=1, name='John Fowles')
self.collector.save() self.collector.save()
@ -4165,18 +4005,12 @@ class AdminInlineTests(TestCase):
self.assertEqual(Category.objects.get(id=4).order, 0) self.assertEqual(Category.objects.get(id=4).order, 0)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class NeverCacheTests(TestCase): class NeverCacheTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
def setUp(self): def setUp(self):
@ -4245,18 +4079,12 @@ class NeverCacheTests(TestCase):
self.assertEqual(get_max_age(response), None) self.assertEqual(get_max_age(response), None)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class PrePopulatedTest(TestCase): class PrePopulatedTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title') cls.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
def setUp(self): def setUp(self):
@ -4288,20 +4116,14 @@ class PrePopulatedTest(TestCase):
self.assertContains(response, "&quot;maxLength&quot;: 1000") # instead of 1,000 self.assertContains(response, "&quot;maxLength&quot;: 1000") # instead of 1,000
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase): class SeleniumAdminViewsFirefoxTests(AdminSeleniumWebDriverTestCase):
available_apps = ['admin_views'] + AdminSeleniumWebDriverTestCase.available_apps available_apps = ['admin_views'] + AdminSeleniumWebDriverTestCase.available_apps
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
def setUp(self): def setUp(self):
self.superuser = User.objects.create( self.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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)
)
self.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title') self.p1 = PrePopulatedPost.objects.create(title='A Long Title', published=True, slug='a-long-title')
def test_prepopulated_fields(self): def test_prepopulated_fields(self):
@ -4629,18 +4451,12 @@ class SeleniumAdminViewsIETests(SeleniumAdminViewsFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class ReadonlyTest(AdminFieldExtractionMixin, TestCase): class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -4805,18 +4621,12 @@ class ReadonlyTest(AdminFieldExtractionMixin, TestCase):
self.assertContains(response, "&lt;a&gt;evil&lt;/a&gt;", status_code=200) self.assertContains(response, "&lt;a&gt;evil&lt;/a&gt;", status_code=200)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class LimitChoicesToInAdminTest(TestCase): class LimitChoicesToInAdminTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -4837,18 +4647,12 @@ class LimitChoicesToInAdminTest(TestCase):
self.assertNotContains(response, marley.username) self.assertNotContains(response, marley.username)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class RawIdFieldsTest(TestCase): class RawIdFieldsTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -4932,8 +4736,7 @@ class RawIdFieldsTest(TestCase):
self.assertContains(response, 'list-display-sketch') self.assertContains(response, 'list-display-sketch')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class UserAdminTest(TestCase): class UserAdminTest(TestCase):
""" """
Tests user CRUD functionality. Tests user CRUD functionality.
@ -4941,24 +4744,9 @@ class UserAdminTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', cls.adduser = User.objects.create_user(username='adduser', password='secret', is_staff=True)
last_login=datetime.datetime(2007, 5, 30, 13, 20, 10), is_superuser=True, username='super', cls.changeuser = User.objects.create_user(username='changeuser', password='secret', is_staff=True)
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.adduser = User.objects.create(
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.changeuser = User.objects.create(
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
@ -5104,8 +4892,7 @@ class UserAdminTest(TestCase):
self.assertEqual(response.context['form_url'], 'pony') self.assertEqual(response.context['form_url'], 'pony')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class GroupAdminTest(TestCase): class GroupAdminTest(TestCase):
""" """
Tests group CRUD functionality. Tests group CRUD functionality.
@ -5113,12 +4900,7 @@ class GroupAdminTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -5144,18 +4926,12 @@ class GroupAdminTest(TestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class CSSTest(TestCase): class CSSTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = Section.objects.create(name='Test section') cls.s1 = Section.objects.create(name='Test section')
cls.a1 = Article.objects.create( cls.a1 = Article.objects.create(
content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1 content='<p>Middle content</p>', date=datetime.datetime(2008, 3, 18, 11, 54, 58), section=cls.s1
@ -5281,19 +5057,13 @@ except ImportError:
@unittest.skipUnless(docutils, "no docutils installed.") @unittest.skipUnless(docutils, "no docutils installed.")
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.admindocs', 'django.contrib.flatpages']}) @modify_settings(INSTALLED_APPS={'append': ['django.contrib.admindocs', 'django.contrib.flatpages']})
class AdminDocsTest(TestCase): class AdminDocsTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -5331,8 +5101,7 @@ class AdminDocsTest(TestCase):
@override_settings( @override_settings(
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], ROOT_URLCONF='admin_views.urls',
ROOT_URLCONF="admin_views.urls",
TEMPLATES=[{ TEMPLATES=[{
'BACKEND': 'django.template.backends.django.DjangoTemplates', 'BACKEND': 'django.template.backends.django.DjangoTemplates',
'APP_DIRS': True, 'APP_DIRS': True,
@ -5351,12 +5120,7 @@ class ValidXHTMLTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -5367,19 +5131,12 @@ class ValidXHTMLTests(TestCase):
self.assertNotContains(response, ' xml:lang=""') self.assertNotContains(response, ' xml:lang=""')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls', USE_THOUSAND_SEPARATOR=True, USE_L10N=True)
ROOT_URLCONF="admin_views.urls",
USE_THOUSAND_SEPARATOR=True, USE_L10N=True)
class DateHierarchyTests(TestCase): class DateHierarchyTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -5498,8 +5255,7 @@ class DateHierarchyTests(TestCase):
self.assert_non_localized_year(response, 2005) self.assert_non_localized_year(response, 2005)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminCustomSaveRelatedTests(TestCase): class AdminCustomSaveRelatedTests(TestCase):
""" """
Ensure that one can easily customize the way related objects are saved. Ensure that one can easily customize the way related objects are saved.
@ -5508,12 +5264,7 @@ class AdminCustomSaveRelatedTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -5575,18 +5326,12 @@ class AdminCustomSaveRelatedTests(TestCase):
self.assertEqual(['Catherine Stone', 'Paul Stone'], children_names) self.assertEqual(['Catherine Stone', 'Paul Stone'], children_names)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewLogoutTests(TestCase): class AdminViewLogoutTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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_logout(self): def test_logout(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -5609,18 +5354,12 @@ class AdminViewLogoutTests(TestCase):
self.assertContains(response, '<input type="hidden" name="next" value="%s" />' % reverse('admin:index')) self.assertContains(response, '<input type="hidden" name="next" value="%s" />' % reverse('admin:index'))
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminUserMessageTest(TestCase): class AdminUserMessageTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -5672,25 +5411,14 @@ class AdminUserMessageTest(TestCase):
html=True) html=True)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminKeepChangeListFiltersTests(TestCase): class AdminKeepChangeListFiltersTests(TestCase):
admin_site = site admin_site = site
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', cls.joepublicuser = User.objects.create_user(username='joepublic', password='secret')
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.joepublicuser = User.objects.create(
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)
)
def setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -5976,19 +5704,13 @@ class NamespacedAdminKeepChangeListFiltersTests(AdminKeepChangeListFiltersTests)
admin_site = site2 admin_site = site2
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class TestLabelVisibility(TestCase): class TestLabelVisibility(TestCase):
""" #11277 -Labels of hidden fields in admin were not hidden. """ """ #11277 -Labels of hidden fields in admin were not hidden. """
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)
@ -6024,18 +5746,12 @@ class TestLabelVisibility(TestCase):
self.assertContains(response, '<div class="form-row hidden') self.assertContains(response, '<div class="form-row hidden')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class AdminViewOnSiteTests(TestCase): class AdminViewOnSiteTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = State.objects.create(name='New York') cls.s1 = State.objects.create(name='New York')
cls.s2 = State.objects.create(name='Illinois') cls.s2 = State.objects.create(name='Illinois')
@ -6161,18 +5877,12 @@ class AdminViewOnSiteTests(TestCase):
self.assertIsNone(model_admin.get_view_on_site_url(Worker())) self.assertIsNone(model_admin.get_view_on_site_url(Worker()))
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_views.urls')
ROOT_URLCONF="admin_views.urls")
class InlineAdminViewOnSiteTest(TestCase): class InlineAdminViewOnSiteTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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.s1 = State.objects.create(name='New York') cls.s1 = State.objects.create(name='New York')
cls.s2 = State.objects.create(name='Illinois') cls.s2 = State.objects.create(name='Illinois')
@ -6211,7 +5921,7 @@ class InlineAdminViewOnSiteTest(TestCase):
self.assertContains(response, '"/worker_inline/%s/%s/"' % (self.w1.surname, self.w1.name)) self.assertContains(response, '"/worker_inline/%s/%s/"' % (self.w1.surname, self.w1.name))
@override_settings(ROOT_URLCONF="admin_views.urls") @override_settings(ROOT_URLCONF='admin_views.urls')
class TestEtagWithAdminView(SimpleTestCase): class TestEtagWithAdminView(SimpleTestCase):
# See https://code.djangoproject.com/ticket/16003 # See https://code.djangoproject.com/ticket/16003
@ -6227,10 +5937,7 @@ class TestEtagWithAdminView(SimpleTestCase):
self.assertTrue(response.has_header('ETag')) self.assertTrue(response.has_header('ETag'))
@override_settings( @override_settings(ROOT_URLCONF='admin_views.urls')
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF="admin_views.urls",
)
class GetFormsetsWithInlinesArgumentTest(TestCase): class GetFormsetsWithInlinesArgumentTest(TestCase):
""" """
#23934 - When adding a new model instance in the admin, the 'obj' argument #23934 - When adding a new model instance in the admin, the 'obj' argument
@ -6242,12 +5949,7 @@ class GetFormsetsWithInlinesArgumentTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.superuser = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
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 setUp(self): def setUp(self):
self.client.force_login(self.superuser) self.client.force_login(self.superuser)

View File

@ -33,30 +33,15 @@ class TestDataMixin(object):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = User.objects.create( cls.superuser = User.objects.create_superuser(username='super', password='secret', email=None)
pk=100, username='super', first_name='Super', last_name='User', email='super@example.com', cls.u2 = User.objects.create_user(username='testser', password='secret')
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=True, models.Car.objects.create(owner=cls.superuser, make='Volkswagen', model='Passat')
is_staff=True, last_login=datetime(2007, 5, 30, 13, 20, 10), models.Car.objects.create(owner=cls.u2, make='BMW', model='M3')
date_joined=datetime(2007, 5, 30, 13, 20, 10)
)
cls.u2 = User.objects.create(
pk=101, username='testser', first_name='Add', last_name='User', email='auser@example.com',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=False,
is_staff=True, last_login=datetime(2007, 5, 30, 13, 20, 10),
date_joined=datetime(2007, 5, 30, 13, 20, 10)
)
models.Car.objects.create(id=1, owner=cls.u1, make='Volkswagen', model='Passat')
models.Car.objects.create(id=2, owner=cls.u2, make='BMW', model='M3')
class SeleniumDataMixin(object): class SeleniumDataMixin(object):
def setUp(self): def setUp(self):
self.u1 = User.objects.create( self.u1 = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
pk=100, username='super', first_name='Super', last_name='User', email='super@example.com',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=True,
is_staff=True, last_login=datetime(2007, 5, 30, 13, 20, 10),
date_joined=datetime(2007, 5, 30, 13, 20, 10)
)
class AdminFormfieldForDBFieldTests(SimpleTestCase): class AdminFormfieldForDBFieldTests(SimpleTestCase):
@ -195,38 +180,35 @@ class AdminFormfieldForDBFieldTests(SimpleTestCase):
) )
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_widgets.urls')
ROOT_URLCONF='admin_widgets.urls')
class AdminFormfieldForDBFieldWithRequestTests(TestDataMixin, TestCase): class AdminFormfieldForDBFieldWithRequestTests(TestDataMixin, TestCase):
def test_filter_choices_by_request_user(self): def test_filter_choices_by_request_user(self):
""" """
Ensure the user can only see their own cars in the foreign key dropdown. Ensure the user can only see their own cars in the foreign key dropdown.
""" """
self.client.login(username="super", password="secret") self.client.force_login(self.superuser)
response = self.client.get(reverse('admin:admin_widgets_cartire_add')) response = self.client.get(reverse('admin:admin_widgets_cartire_add'))
self.assertNotContains(response, "BMW M3") self.assertNotContains(response, "BMW M3")
self.assertContains(response, "Volkswagen Passat") self.assertContains(response, "Volkswagen Passat")
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_widgets.urls')
ROOT_URLCONF='admin_widgets.urls')
class AdminForeignKeyWidgetChangeList(TestDataMixin, TestCase): class AdminForeignKeyWidgetChangeList(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
self.client.login(username="super", password="secret") self.client.force_login(self.superuser)
def test_changelist_ForeignKey(self): def test_changelist_ForeignKey(self):
response = self.client.get(reverse('admin:admin_widgets_car_changelist')) response = self.client.get(reverse('admin:admin_widgets_car_changelist'))
self.assertContains(response, '/auth/user/add/') self.assertContains(response, '/auth/user/add/')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_widgets.urls')
ROOT_URLCONF='admin_widgets.urls')
class AdminForeignKeyRawIdWidget(TestDataMixin, TestCase): class AdminForeignKeyRawIdWidget(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
self.client.login(username="super", password="secret") self.client.force_login(self.superuser)
def test_nonexistent_target_id(self): def test_nonexistent_target_id(self):
band = models.Band.objects.create(name='Bogey Blues') band = models.Band.objects.create(name='Bogey Blues')
@ -407,10 +389,7 @@ class AdminURLWidgetTest(SimpleTestCase):
) )
@override_settings( @override_settings(ROOT_URLCONF='admin_widgets.urls')
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF='admin_widgets.urls',
)
class AdminFileWidgetTests(TestDataMixin, TestCase): class AdminFileWidgetTests(TestDataMixin, TestCase):
@classmethod @classmethod
@ -443,7 +422,7 @@ class AdminFileWidgetTests(TestDataMixin, TestCase):
""" """
File widgets should render as a link when they're marked "read only." File widgets should render as a link when they're marked "read only."
""" """
self.client.login(username="super", password="secret") self.client.force_login(self.superuser)
response = self.client.get(reverse('admin:admin_widgets_album_change', args=(self.album.id,))) response = self.client.get(reverse('admin:admin_widgets_album_change', args=(self.album.id,)))
self.assertContains( self.assertContains(
response, response,
@ -639,8 +618,7 @@ class RelatedFieldWidgetWrapperTests(SimpleTestCase):
self.assertFalse(wrapper.can_delete_related) self.assertFalse(wrapper.can_delete_related)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_widgets.urls')
ROOT_URLCONF='admin_widgets.urls')
class DateTimePickerSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase): class DateTimePickerSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase):
available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps
@ -818,8 +796,7 @@ class DateTimePickerSeleniumIETests(DateTimePickerSeleniumFirefoxTests):
@skipIf(pytz is None, "this test requires pytz") @skipIf(pytz is None, "this test requires pytz")
@override_settings(TIME_ZONE='Asia/Singapore') @override_settings(TIME_ZONE='Asia/Singapore')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_widgets.urls')
ROOT_URLCONF='admin_widgets.urls')
class DateTimePickerShortcutsSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase): class DateTimePickerShortcutsSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase):
available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
@ -900,8 +877,7 @@ class DateTimePickerAltTimezoneSeleniumIETests(DateTimePickerAltTimezoneSelenium
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_widgets.urls')
ROOT_URLCONF='admin_widgets.urls')
class HorizontalVerticalFilterSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase): class HorizontalVerticalFilterSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase):
available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps
@ -1201,8 +1177,7 @@ class HorizontalVerticalFilterSeleniumIETests(HorizontalVerticalFilterSeleniumFi
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_widgets.urls')
ROOT_URLCONF='admin_widgets.urls')
class AdminRawIdWidgetSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase): class AdminRawIdWidgetSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase):
available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'
@ -1297,8 +1272,7 @@ class AdminRawIdWidgetSeleniumIETests(AdminRawIdWidgetSeleniumFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='admin_widgets.urls')
ROOT_URLCONF='admin_widgets.urls')
class RelatedFieldWidgetSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase): class RelatedFieldWidgetSeleniumFirefoxTests(SeleniumDataMixin, AdminSeleniumWebDriverTestCase):
available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps available_apps = ['admin_widgets'] + AdminSeleniumWebDriverTestCase.available_apps
webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.firefox.webdriver.WebDriver'

View File

@ -1,5 +1,3 @@
import datetime
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from django.contrib.auth.context_processors import PermLookupDict, PermWrapper from django.contrib.auth.context_processors import PermLookupDict, PermWrapper
from django.contrib.auth.models import Permission, User from django.contrib.auth.models import Permission, User
@ -59,12 +57,7 @@ class PermWrapperTests(SimpleTestCase):
self.EQLimiterObject() in pldict self.EQLimiterObject() in pldict
@override_settings( @override_settings(ROOT_URLCONF='auth_tests.urls', TEMPLATES=AUTH_TEMPLATES)
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF='auth_tests.urls',
TEMPLATES=AUTH_TEMPLATES,
USE_TZ=False, # required for loading the fixture
)
class AuthContextProcessorTests(TestCase): class AuthContextProcessorTests(TestCase):
""" """
Tests for the ``django.contrib.auth.context_processors.auth`` processor Tests for the ``django.contrib.auth.context_processors.auth`` processor
@ -72,13 +65,7 @@ class AuthContextProcessorTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
# password = "secret" cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
cls.u1 = User.objects.create(
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)
)
@override_settings(MIDDLEWARE_CLASSES=AUTH_MIDDLEWARE_CLASSES) @override_settings(MIDDLEWARE_CLASSES=AUTH_MIDDLEWARE_CLASSES)
def test_session_not_accessed(self): def test_session_not_accessed(self):
@ -104,7 +91,7 @@ class AuthContextProcessorTests(TestCase):
Permission.objects.get( Permission.objects.get(
content_type=ContentType.objects.get_for_model(Permission), content_type=ContentType.objects.get_for_model(Permission),
codename='add_permission')) codename='add_permission'))
self.client.login(username='normal', password='secret') self.client.force_login(u)
response = self.client.get('/auth_processor_perms/') response = self.client.get('/auth_processor_perms/')
self.assertContains(response, "Has auth permissions") self.assertContains(response, "Has auth permissions")
self.assertContains(response, "Has auth.add_permission permissions") self.assertContains(response, "Has auth.add_permission permissions")
@ -123,7 +110,7 @@ class AuthContextProcessorTests(TestCase):
self.assertNotContains(response, "nonexisting") self.assertNotContains(response, "nonexisting")
def test_message_attrs(self): def test_message_attrs(self):
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
response = self.client.get('/auth_processor_messages/') response = self.client.get('/auth_processor_messages/')
self.assertContains(response, "Message 1") self.assertContains(response, "Message 1")
@ -138,7 +125,7 @@ class AuthContextProcessorTests(TestCase):
user = authenticate(username='super', password='secret') user = authenticate(username='super', password='secret')
response = self.client.get('/auth_processor_user/') response = self.client.get('/auth_processor_user/')
self.assertContains(response, "unicode: super") self.assertContains(response, "unicode: super")
self.assertContains(response, "id: %d" % self.u1.pk) self.assertContains(response, "id: %d" % self.superuser.pk)
self.assertContains(response, "username: super") self.assertContains(response, "username: super")
# bug #12037 is tested by the {% url %} in the template: # bug #12037 is tested by the {% url %} in the template:
self.assertContains(response, "url: /userpage/super/") self.assertContains(response, "url: /userpage/super/")

View File

@ -1,6 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
import re import re
from django import forms from django import forms
@ -27,44 +26,14 @@ class TestDataMixin(object):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = User.objects.create( cls.u1 = User.objects.create_user(username='testclient', password='password', email='testclient@example.com')
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161', cls.u2 = User.objects.create_user(username='inactive', password='password', is_active=False)
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='testclient', cls.u3 = User.objects.create_user(username='staff', password='password')
first_name='Test', last_name='Client', email='testclient@example.com', is_staff=False, is_active=True, cls.u4 = User.objects.create(username='empty_password', password='')
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31) cls.u5 = User.objects.create(username='unmanageable_password', password='$')
) cls.u6 = User.objects.create(username='unknown_password', password='foo$bar')
cls.u2 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='inactive',
first_name='Inactive', last_name='User', email='testclient2@example.com', is_staff=False, is_active=False,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u3 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='staff',
first_name='Staff', last_name='Member', email='staffmember@example.com', is_staff=True, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u4 = User.objects.create(
password='', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='empty_password', first_name='Empty', last_name='Password', email='empty_password@example.com',
is_staff=False, is_active=True, date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u5 = User.objects.create(
password='$', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='unmanageable_password', first_name='Unmanageable', last_name='Password',
email='unmanageable_password@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u6 = User.objects.create(
password='foo$bar', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='unknown_password', first_name='Unknown', last_name='Password',
email='unknown_password@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
@override_settings(USE_TZ=False, PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'])
class UserCreationFormTest(TestDataMixin, TestCase): class UserCreationFormTest(TestDataMixin, TestCase):
def test_user_already_exists(self): def test_user_already_exists(self):
@ -154,7 +123,6 @@ class UserCreationFormTest(TestDataMixin, TestCase):
) )
@override_settings(USE_TZ=False, PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'])
class AuthenticationFormTest(TestDataMixin, TestCase): class AuthenticationFormTest(TestDataMixin, TestCase):
def test_invalid_username(self): def test_invalid_username(self):
@ -264,7 +232,6 @@ class AuthenticationFormTest(TestDataMixin, TestCase):
self.assertEqual(form.fields['username'].label, "") self.assertEqual(form.fields['username'].label, "")
@override_settings(USE_TZ=False, PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'])
class SetPasswordFormTest(TestDataMixin, TestCase): class SetPasswordFormTest(TestDataMixin, TestCase):
def test_password_verification(self): def test_password_verification(self):
@ -315,7 +282,6 @@ class SetPasswordFormTest(TestDataMixin, TestCase):
) )
@override_settings(USE_TZ=False, PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'])
class PasswordChangeFormTest(TestDataMixin, TestCase): class PasswordChangeFormTest(TestDataMixin, TestCase):
def test_incorrect_password(self): def test_incorrect_password(self):
@ -366,7 +332,6 @@ class PasswordChangeFormTest(TestDataMixin, TestCase):
['old_password', 'new_password1', 'new_password2']) ['old_password', 'new_password1', 'new_password2'])
@override_settings(USE_TZ=False, PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'])
class UserChangeFormTest(TestDataMixin, TestCase): class UserChangeFormTest(TestDataMixin, TestCase):
def test_username_validity(self): def test_username_validity(self):
@ -431,7 +396,8 @@ class UserChangeFormTest(TestDataMixin, TestCase):
form = UserChangeForm(instance=user, data=post_data) form = UserChangeForm(instance=user, data=post_data)
self.assertTrue(form.is_valid()) self.assertTrue(form.is_valid())
self.assertEqual(form.cleaned_data['password'], 'sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161') # original hashed password contains $
self.assertIn('$', form.cleaned_data['password'])
def test_bug_19349_bound_password_field(self): def test_bug_19349_bound_password_field(self):
user = User.objects.get(username='testclient') user = User.objects.get(username='testclient')
@ -442,11 +408,7 @@ class UserChangeFormTest(TestDataMixin, TestCase):
self.assertEqual(form.initial['password'], form['password'].value()) self.assertEqual(form.initial['password'], form['password'].value())
@override_settings( @override_settings(TEMPLATES=AUTH_TEMPLATES)
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
TEMPLATES=AUTH_TEMPLATES,
USE_TZ=False,
)
class PasswordResetFormTest(TestDataMixin, TestCase): class PasswordResetFormTest(TestDataMixin, TestCase):
@classmethod @classmethod
@ -623,7 +585,6 @@ class ReadOnlyPasswordHashTest(SimpleTestCase):
self.assertFalse(field.has_changed('aaa', 'bbb')) self.assertFalse(field.has_changed('aaa', 'bbb'))
@override_settings(USE_TZ=False, PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'])
class AdminPasswordChangeFormTest(TestDataMixin, TestCase): class AdminPasswordChangeFormTest(TestDataMixin, TestCase):
@mock.patch('django.contrib.auth.password_validation.password_changed') @mock.patch('django.contrib.auth.password_validation.password_changed')

View File

@ -1,5 +1,3 @@
import datetime
from django.conf.global_settings import PASSWORD_HASHERS from django.conf.global_settings import PASSWORD_HASHERS
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.hashers import get_hasher from django.contrib.auth.hashers import get_hasher
@ -12,49 +10,10 @@ from django.db.models.signals import post_save
from django.test import TestCase, mock, override_settings from django.test import TestCase, mock, override_settings
@override_settings(USE_TZ=False)
class NaturalKeysTestCase(TestCase): class NaturalKeysTestCase(TestCase):
@classmethod
def setUpTestData(cls):
cls.u1 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='testclient',
first_name='Test', last_name='Client', email='testclient@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u2 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='inactive',
first_name='Inactive', last_name='User', email='testclient2@example.com', is_staff=False, is_active=False,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u3 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='staff',
first_name='Staff', last_name='Member', email='staffmember@example.com', is_staff=True, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u4 = User.objects.create(
password='', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='empty_password', first_name='Empty', last_name='Password', email='empty_password@example.com',
is_staff=False, is_active=True, date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u5 = User.objects.create(
password='$', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='unmanageable_password', first_name='Unmanageable', last_name='Password',
email='unmanageable_password@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u6 = User.objects.create(
password='foo$bar', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='unknown_password', first_name='Unknown', last_name='Password',
email='unknown_password@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
def test_user_natural_key(self): def test_user_natural_key(self):
staff_user = User.objects.get(username='staff') staff_user = User.objects.create_user(username='staff')
self.assertEqual(User.objects.get_by_natural_key('staff'), staff_user) self.assertEqual(User.objects.get_by_natural_key('staff'), staff_user)
self.assertEqual(staff_user.natural_key(), ('staff',)) self.assertEqual(staff_user.natural_key(), ('staff',))
@ -63,7 +22,6 @@ class NaturalKeysTestCase(TestCase):
self.assertEqual(Group.objects.get_by_natural_key('users'), users_group) self.assertEqual(Group.objects.get_by_natural_key('users'), users_group)
@override_settings(USE_TZ=False)
class LoadDataWithoutNaturalKeysTestCase(TestCase): class LoadDataWithoutNaturalKeysTestCase(TestCase):
fixtures = ['regular.json'] fixtures = ['regular.json']
@ -73,7 +31,6 @@ class LoadDataWithoutNaturalKeysTestCase(TestCase):
self.assertEqual(group, user.groups.get()) self.assertEqual(group, user.groups.get())
@override_settings(USE_TZ=False)
class LoadDataWithNaturalKeysTestCase(TestCase): class LoadDataWithNaturalKeysTestCase(TestCase):
fixtures = ['natural.json'] fixtures = ['natural.json']

View File

@ -1,30 +1,16 @@
import datetime
from django.contrib.auth import signals from django.contrib.auth import signals
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.test import TestCase, override_settings from django.test import TestCase, override_settings
from django.test.client import RequestFactory from django.test.client import RequestFactory
@override_settings(USE_TZ=False, @override_settings(ROOT_URLCONF='auth_tests.urls')
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF='auth_tests.urls')
class SignalTestCase(TestCase): class SignalTestCase(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = User.objects.create( cls.u1 = User.objects.create_user(username='testclient', password='password')
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161', cls.u3 = User.objects.create_user(username='staff', password='password')
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='testclient',
first_name='Test', last_name='Client', email='testclient@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u3 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='staff',
first_name='Staff', last_name='Member', email='staffmember@example.com', is_staff=True, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
def listener_login(self, user, **kwargs): def listener_login(self, user, **kwargs):
self.logged_in.append(user) self.logged_in.append(user)
@ -87,8 +73,7 @@ class SignalTestCase(TestCase):
user.username = "This username shouldn't get saved" user.username = "This username shouldn't get saved"
request = RequestFactory().get('/login') request = RequestFactory().get('/login')
signals.user_logged_in.send(sender=user.__class__, request=request, signals.user_logged_in.send(sender=user.__class__, request=request, user=user)
user=user) user.refresh_from_db()
user = User.objects.get(pk=self.u3.pk)
self.assertEqual(user.username, 'staff') self.assertEqual(user.username, 'staff')
self.assertNotEqual(user.last_login, old_last_login) self.assertNotEqual(user.last_login, old_last_login)

View File

@ -10,10 +10,7 @@ from django.utils.encoding import force_bytes, force_text
from django.utils.http import urlsafe_base64_encode from django.utils.http import urlsafe_base64_encode
@override_settings( @override_settings(ROOT_URLCONF='auth_tests.urls')
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF='auth_tests.urls',
)
class AuthTemplateTests(TestCase): class AuthTemplateTests(TestCase):
def test_titles(self): def test_titles(self):

View File

@ -97,9 +97,9 @@ class MinimumLengthValidatorTest(TestCase):
class UserAttributeSimilarityValidatorTest(TestCase): class UserAttributeSimilarityValidatorTest(TestCase):
def test_validate(self): def test_validate(self):
user = User.objects.create( user = User.objects.create_user(
username='testclient', first_name='Test', last_name='Client', email='testclient@example.com', username='testclient', password='password', email='testclient@example.com',
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161', first_name='Test', last_name='Client',
) )
expected_error = "The password is too similar to the %s." expected_error = "The password is too similar to the %s."

View File

@ -35,13 +35,9 @@ from .settings import AUTH_TEMPLATES
@override_settings( @override_settings(
LANGUAGES=[ LANGUAGES=[('en', 'English')],
('en', 'English'),
],
LANGUAGE_CODE='en', LANGUAGE_CODE='en',
TEMPLATES=AUTH_TEMPLATES, TEMPLATES=AUTH_TEMPLATES,
USE_TZ=False,
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF='auth_tests.urls', ROOT_URLCONF='auth_tests.urls',
) )
class AuthViewsTestCase(TestCase): class AuthViewsTestCase(TestCase):
@ -51,41 +47,8 @@ class AuthViewsTestCase(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = User.objects.create( cls.u1 = User.objects.create_user(username='testclient', password='password', email='testclient@example.com')
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161', cls.u3 = User.objects.create_user(username='staff', password='password', email='staffmember@example.com')
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='testclient',
first_name='Test', last_name='Client', email='testclient@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u2 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='inactive',
first_name='Inactive', last_name='User', email='testclient2@example.com', is_staff=False, is_active=False,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u3 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='staff',
first_name='Staff', last_name='Member', email='staffmember@example.com', is_staff=True, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u4 = User.objects.create(
password='', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='empty_password', first_name='Empty', last_name='Password', email='empty_password@example.com',
is_staff=False, is_active=True, date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u5 = User.objects.create(
password='$', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='unmanageable_password', first_name='Unmanageable', last_name='Password',
email='unmanageable_password@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u6 = User.objects.create(
password='foo$bar', last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False,
username='unknown_password', first_name='Unknown', last_name='Password',
email='unknown_password@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
def login(self, username='testclient', password='password'): def login(self, username='testclient', password='password'):
response = self.client.post('/login/', { response = self.client.post('/login/', {
@ -373,10 +336,11 @@ class CustomUserPasswordResetTest(AuthViewsTestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = CustomUser.custom_objects.create( cls.u1 = CustomUser.custom_objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161', email='staffmember@example.com',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), email='staffmember@example.com', is_active=True, date_of_birth=datetime.date(1976, 11, 8),
is_admin=False, date_of_birth=datetime.date(1976, 11, 8)
) )
cls.u1.set_password('password')
cls.u1.save()
def _test_confirm_start(self): def _test_confirm_start(self):
# Start by creating the email # Start by creating the email
@ -892,10 +856,7 @@ class LogoutTest(AuthViewsTestCase):
# Redirect in test_user_change_password will fail if session auth hash # Redirect in test_user_change_password will fail if session auth hash
# isn't updated after password change (#21649) # isn't updated after password change (#21649)
@override_settings( @override_settings(ROOT_URLCONF='auth_tests.urls_admin')
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF='auth_tests.urls_admin',
)
class ChangelistTests(AuthViewsTestCase): class ChangelistTests(AuthViewsTestCase):
def setUp(self): def setUp(self):

View File

@ -68,8 +68,8 @@ class FlatpageCSRFTests(TestCase):
"A flatpage served through a view can require authentication" "A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')
self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/') self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/')
User.objects.create_user('testuser', 'test@example.com', 's3krit') user = User.objects.create_user('testuser', 'test@example.com', 's3krit')
self.client.login(username='testuser', password='s3krit') self.client.force_login(user)
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')
self.assertContains(response, "<p>Isn't it sekrit!</p>") self.assertContains(response, "<p>Isn't it sekrit!</p>")

View File

@ -68,8 +68,8 @@ class FlatpageMiddlewareTests(TestDataMixin, TestCase):
"A flatpage served through a view can require authentication" "A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')
self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/') self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/')
User.objects.create_user('testuser', 'test@example.com', 's3krit') user = User.objects.create_user('testuser', 'test@example.com', 's3krit')
self.client.login(username='testuser', password='s3krit') self.client.force_login(user)
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')
self.assertContains(response, "<p>Isn't it sekrit!</p>") self.assertContains(response, "<p>Isn't it sekrit!</p>")
@ -87,8 +87,8 @@ class FlatpageMiddlewareTests(TestDataMixin, TestCase):
"A flatpage served by the middleware can require authentication" "A flatpage served by the middleware can require authentication"
response = self.client.get('/sekrit/') response = self.client.get('/sekrit/')
self.assertRedirects(response, '/accounts/login/?next=/sekrit/') self.assertRedirects(response, '/accounts/login/?next=/sekrit/')
User.objects.create_user('testuser', 'test@example.com', 's3krit') user = User.objects.create_user('testuser', 'test@example.com', 's3krit')
self.client.login(username='testuser', password='s3krit') self.client.force_login(user)
response = self.client.get('/sekrit/') response = self.client.get('/sekrit/')
self.assertContains(response, "<p>Isn't it sekrit!</p>") self.assertContains(response, "<p>Isn't it sekrit!</p>")

View File

@ -68,8 +68,8 @@ class FlatpageViewTests(TestDataMixin, TestCase):
"A flatpage served through a view can require authentication" "A flatpage served through a view can require authentication"
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')
self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/') self.assertRedirects(response, '/accounts/login/?next=/flatpage_root/sekrit/')
User.objects.create_user('testuser', 'test@example.com', 's3krit') user = User.objects.create_user('testuser', 'test@example.com', 's3krit')
self.client.login(username='testuser', password='s3krit') self.client.force_login(user)
response = self.client.get('/flatpage_root/sekrit/') response = self.client.get('/flatpage_root/sekrit/')
self.assertContains(response, "<p>Isn't it sekrit!</p>") self.assertContains(response, "<p>Isn't it sekrit!</p>")

View File

@ -1,8 +1,6 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
from django.contrib import admin from django.contrib import admin
from django.contrib.admin.sites import AdminSite from django.contrib.admin.sites import AdminSite
from django.contrib.auth.models import User from django.contrib.auth.models import User
@ -24,30 +22,17 @@ class TestDataMixin(object):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
# password = "secret" cls.superuser = User.objects.create_superuser(username='super', password='secret', email='super@example.com')
User.objects.create(
pk=100, username='super', first_name='Super', last_name='User', email='super@example.com',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158', is_active=True, is_superuser=True,
is_staff=True, last_login=datetime.datetime(2007, 5, 30, 13, 20, 10),
date_joined=datetime.datetime(2007, 5, 30, 13, 20, 10)
)
# Set DEBUG to True to ensure {% include %} will raise exceptions. # Set DEBUG to True to ensure {% include %} will raise exceptions.
# That is how inlines are rendered and #9498 will bubble up if it is an issue. # That is how inlines are rendered and #9498 will bubble up if it is an issue.
@override_settings( @override_settings(DEBUG=True, ROOT_URLCONF='generic_inline_admin.urls')
DEBUG=True,
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
ROOT_URLCONF="generic_inline_admin.urls",
)
class GenericAdminViewTest(TestDataMixin, TestCase): class GenericAdminViewTest(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
# Can't load content via a fixture (since the GenericForeignKey
# relies on content type IDs, which will vary depending on what
# other tests have been run), thus we do it here.
e = Episode.objects.create(name='This Week in Django') e = Episode.objects.create(name='This Week in Django')
self.episode_pk = e.pk self.episode_pk = e.pk
m = Media(content_object=e, url='http://example.com/podcast.mp3') m = Media(content_object=e, url='http://example.com/podcast.mp3')
@ -215,12 +200,11 @@ class GenericAdminViewTest(TestDataMixin, TestCase):
self.assertTrue(formset.get_queryset().ordered) self.assertTrue(formset.get_queryset().ordered)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='generic_inline_admin.urls')
ROOT_URLCONF="generic_inline_admin.urls")
class GenericInlineAdminParametersTest(TestDataMixin, TestCase): class GenericInlineAdminParametersTest(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
self.factory = RequestFactory() self.factory = RequestFactory()
def _create_object(self, model): def _create_object(self, model):
@ -361,12 +345,11 @@ class GenericInlineAdminParametersTest(TestDataMixin, TestCase):
self.assertEqual(formset.max_num, 2) self.assertEqual(formset.max_num, 2)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='generic_inline_admin.urls')
ROOT_URLCONF="generic_inline_admin.urls")
class GenericInlineAdminWithUniqueTogetherTest(TestDataMixin, TestCase): class GenericInlineAdminWithUniqueTogetherTest(TestDataMixin, TestCase):
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
def test_add(self): def test_add(self):
category_id = Category.objects.create(name='male').pk category_id = Category.objects.create(name='male').pk

View File

@ -1,7 +1,5 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
from django.contrib import admin from django.contrib import admin
from django.contrib.auth.models import User as AuthUser from django.contrib.auth.models import User as AuthUser
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
@ -382,18 +380,12 @@ class ProxyModelTests(TestCase):
self.assertEqual(MyPerson(id=100), Person(id=100)) self.assertEqual(MyPerson(id=100), Person(id=100))
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='proxy_models.urls')
ROOT_URLCONF='proxy_models.urls',)
class ProxyModelAdminTests(TestCase): class ProxyModelAdminTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = AuthUser.objects.create( cls.superuser = AuthUser.objects.create(is_superuser=True, is_staff=True)
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.tu1 = ProxyTrackerUser.objects.create(name='Django Pony', status='emperor') cls.tu1 = ProxyTrackerUser.objects.create(name='Django Pony', status='emperor')
cls.i1 = Issue.objects.create(summary="Pony's Issue", assignee=cls.tu1) cls.i1 = Issue.objects.create(summary="Pony's Issue", assignee=cls.tu1)
@ -427,11 +419,10 @@ class ProxyModelAdminTests(TestCase):
reverse('admin_proxy:proxy_models_proxytrackeruser_change', args=(proxy.pk,)), proxy reverse('admin_proxy:proxy_models_proxytrackeruser_change', args=(proxy.pk,)), proxy
) )
self.client.login(username='super', password='secret') self.client.force_login(self.superuser)
response = self.client.get(reverse('admin_proxy:proxy_models_trackeruser_delete', args=(user.pk,))) response = self.client.get(reverse('admin_proxy:proxy_models_trackeruser_delete', args=(user.pk,)))
delete_str = response.context['deleted_objects'][0] delete_str = response.context['deleted_objects'][0]
self.assertEqual(delete_str, user_str) self.assertEqual(delete_str, user_str)
response = self.client.get(reverse('admin_proxy:proxy_models_proxytrackeruser_delete', args=(proxy.pk,))) response = self.client.get(reverse('admin_proxy:proxy_models_proxytrackeruser_delete', args=(proxy.pk,)))
delete_str = response.context['deleted_objects'][0] delete_str = response.context['deleted_objects'][0]
self.assertEqual(delete_str, proxy_str) self.assertEqual(delete_str, proxy_str)
self.client.logout()

View File

@ -22,8 +22,6 @@ rather than the HTML rendered to the end-user.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core import mail from django.core import mail
from django.http import HttpResponse from django.http import HttpResponse
@ -35,30 +33,13 @@ from django.urls import reverse_lazy
from .views import get_view, post_view, trace_view from .views import get_view, post_view, trace_view
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='test_client.urls')
ROOT_URLCONF='test_client.urls',)
class ClientTest(TestCase): class ClientTest(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = User.objects.create( cls.u1 = User.objects.create_user(username='testclient', password='password')
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161', cls.u2 = User.objects.create_user(username='inactive', password='password', is_active=False)
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='testclient',
first_name='Test', last_name='Client', email='testclient@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u2 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='inactive',
first_name='Inactive', last_name='User', email='testclient@example.com', is_staff=False, is_active=False,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u3 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='staff',
first_name='Staff', last_name='Member', email='testclient@example.com', is_staff=True, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
def test_get_view(self): def test_get_view(self):
"GET a view" "GET a view"

View File

@ -4,7 +4,6 @@ Regression tests for the Test Client, especially the customized assertions.
""" """
from __future__ import unicode_literals from __future__ import unicode_literals
import datetime
import itertools import itertools
import os import os
@ -33,24 +32,8 @@ class TestDataMixin(object):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
cls.u1 = User.objects.create( cls.u1 = User.objects.create_user(username='testclient', password='password')
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161', cls.staff = User.objects.create_user(username='staff', password='password', is_staff=True)
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='testclient',
first_name='Test', last_name='Client', email='testclient@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u2 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='inactive',
first_name='Inactive', last_name='User', email='testclient@example.com', is_staff=False, is_active=False,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
cls.u3 = User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='staff',
first_name='Staff', last_name='Member', email='testclient@example.com', is_staff=True, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
@override_settings(ROOT_URLCONF='test_client_regress.urls') @override_settings(ROOT_URLCONF='test_client_regress.urls')
@ -217,8 +200,7 @@ class AssertContainsTests(SimpleTestCase):
self.assertNotContains(response, 'Bye') self.assertNotContains(response, 'Bye')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='test_client_regress.urls')
ROOT_URLCONF='test_client_regress.urls',)
class AssertTemplateUsedTests(TestDataMixin, TestCase): class AssertTemplateUsedTests(TestDataMixin, TestCase):
def test_no_context(self): def test_no_context(self):
@ -881,8 +863,7 @@ class AssertFormsetErrorTests(SimpleTestCase):
**kwargs) **kwargs)
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='test_client_regress.urls')
ROOT_URLCONF='test_client_regress.urls',)
class LoginTests(TestDataMixin, TestCase): class LoginTests(TestDataMixin, TestCase):
def test_login_different_client(self): def test_login_different_client(self):
@ -903,7 +884,6 @@ class LoginTests(TestDataMixin, TestCase):
@override_settings( @override_settings(
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'],
SESSION_ENGINE='test_client_regress.session', SESSION_ENGINE='test_client_regress.session',
ROOT_URLCONF='test_client_regress.urls', ROOT_URLCONF='test_client_regress.urls',
) )
@ -948,8 +928,7 @@ class URLEscapingTests(SimpleTestCase):
self.assertEqual(response.content, b'Hi, Arthur') self.assertEqual(response.content, b'Hi, Arthur')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='test_client_regress.urls')
ROOT_URLCONF='test_client_regress.urls',)
class ExceptionTests(TestDataMixin, TestCase): class ExceptionTests(TestDataMixin, TestCase):
def test_exception_cleared(self): def test_exception_cleared(self):
@ -1016,8 +995,7 @@ class zzUrlconfSubstitutionTests(SimpleTestCase):
reverse('arg_view', args=['somename']) reverse('arg_view', args=['somename'])
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='test_client_regress.urls')
ROOT_URLCONF='test_client_regress.urls',)
class ContextTests(TestDataMixin, TestCase): class ContextTests(TestDataMixin, TestCase):
def test_single_context(self): def test_single_context(self):
@ -1089,8 +1067,7 @@ class ContextTests(TestDataMixin, TestCase):
self.assertEqual(response.context['nested'], 'yes') self.assertEqual(response.context['nested'], 'yes')
@override_settings(PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], @override_settings(ROOT_URLCONF='test_client_regress.urls')
ROOT_URLCONF='test_client_regress.urls',)
class SessionTests(TestDataMixin, TestCase): class SessionTests(TestDataMixin, TestCase):
def test_session(self): def test_session(self):

View File

@ -1200,16 +1200,19 @@ class NewFormsTests(TestCase):
self.assertIn("2011-09-01 17:20:30", str(form)) self.assertIn("2011-09-01 17:20:30", str(form))
@override_settings(DATETIME_FORMAT='c', TIME_ZONE='Africa/Nairobi', USE_L10N=False, USE_TZ=True, @override_settings(
PASSWORD_HASHERS=['django.contrib.auth.hashers.SHA1PasswordHasher'], DATETIME_FORMAT='c',
ROOT_URLCONF='timezones.urls') TIME_ZONE='Africa/Nairobi',
USE_L10N=False,
USE_TZ=True,
ROOT_URLCONF='timezones.urls',
)
class AdminTests(TestCase): class AdminTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
# password = "secret" cls.u1 = User.objects.create_user(
cls.u1 = User.objects.create( password='secret',
password='sha1$995a3$6011485ea3834267d719b4c801409b8b1ddd0158',
last_login=datetime.datetime(2007, 5, 30, 13, 20, 10, tzinfo=UTC), last_login=datetime.datetime(2007, 5, 30, 13, 20, 10, tzinfo=UTC),
is_superuser=True, username='super', first_name='Super', last_name='User', is_superuser=True, username='super', first_name='Super', last_name='User',
email='super@example.com', is_staff=True, is_active=True, email='super@example.com', is_staff=True, is_active=True,
@ -1217,7 +1220,7 @@ class AdminTests(TestCase):
) )
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.force_login(self.u1)
@requires_tz_support @requires_tz_support
def test_changelist(self): def test_changelist(self):

View File

@ -437,10 +437,10 @@ class ReverseLazyTest(TestCase):
self.assertRedirects(response, "/redirected_to/", status_code=302) self.assertRedirects(response, "/redirected_to/", status_code=302)
def test_user_permission_with_lazy_reverse(self): def test_user_permission_with_lazy_reverse(self):
User.objects.create_user('alfred', 'alfred@example.com', password='testpw') alfred = User.objects.create_user('alfred', 'alfred@example.com', password='testpw')
response = self.client.get('/login_required_view/') response = self.client.get('/login_required_view/')
self.assertRedirects(response, "/login/?next=/login_required_view/", status_code=302) self.assertRedirects(response, "/login/?next=/login_required_view/", status_code=302)
self.client.login(username='alfred', password='testpw') self.client.force_login(alfred)
response = self.client.get('/login_required_view/') response = self.client.get('/login_required_view/')
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)

View File

@ -2,7 +2,6 @@ from __future__ import unicode_literals
import datetime import datetime
from django.contrib.auth.models import User
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.http import Http404 from django.http import Http404
from django.template import TemplateDoesNotExist from django.template import TemplateDoesNotExist
@ -23,12 +22,6 @@ class DefaultsTests(TestCase):
@classmethod @classmethod
def setUpTestData(cls): def setUpTestData(cls):
User.objects.create(
password='sha1$6efc0$f93efe9fd7542f25a7be94871ea45aa95de57161',
last_login=datetime.datetime(2006, 12, 17, 7, 3, 31), is_superuser=False, username='testclient',
first_name='Test', last_name='Client', email='testclient@example.com', is_staff=False, is_active=True,
date_joined=datetime.datetime(2006, 12, 17, 7, 3, 31)
)
Author.objects.create(name='Boris') Author.objects.create(name='Boris')
Article.objects.create( Article.objects.create(
title='Old Article', slug='old_article', author_id=1, title='Old Article', slug='old_article', author_id=1,