Corrected admin_views tests following removal of the email fallback on admin logins.

This commit is contained in:
Russell Keith-Magee 2012-09-09 07:53:46 +08:00
parent 20d1892491
commit 2c5e833a30
1 changed files with 58 additions and 45 deletions

View File

@ -52,6 +52,7 @@ from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
ERROR_MESSAGE = "Please enter the correct username and password \ ERROR_MESSAGE = "Please enter the correct username and password \
for a staff account. Note that both fields are case-sensitive." for a staff account. Note that both fields are case-sensitive."
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminViewBasicTest(TestCase): class AdminViewBasicTest(TestCase):
fixtures = ['admin-views-users.xml', 'admin-views-colors.xml', fixtures = ['admin-views-users.xml', 'admin-views-colors.xml',
@ -141,7 +142,7 @@ class AdminViewBasicTest(TestCase):
"article_set-MAX_NUM_FORMS": "0", "article_set-MAX_NUM_FORMS": "0",
} }
response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data) response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data)
self.assertEqual(response.status_code, 302) # redirect somewhere self.assertEqual(response.status_code, 302) # redirect somewhere
def testPopupAddPost(self): def testPopupAddPost(self):
""" """
@ -205,7 +206,7 @@ class AdminViewBasicTest(TestCase):
A smoke test to ensure POST on edit_view works. A smoke test to ensure POST on edit_view works.
""" """
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, self.inline_post_data) response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, self.inline_post_data)
self.assertEqual(response.status_code, 302) # redirect somewhere self.assertEqual(response.status_code, 302) # redirect somewhere
def testEditSaveAs(self): def testEditSaveAs(self):
""" """
@ -221,7 +222,7 @@ class AdminViewBasicTest(TestCase):
"article_set-5-section": "1", "article_set-5-section": "1",
}) })
response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data) response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
self.assertEqual(response.status_code, 302) # redirect somewhere self.assertEqual(response.status_code, 302) # redirect somewhere
def testChangeListSortingCallable(self): def testChangeListSortingCallable(self):
""" """
@ -303,7 +304,7 @@ class AdminViewBasicTest(TestCase):
self.assertContentBefore(response, link % l2.pk, link % l1.pk) self.assertContentBefore(response, link % l2.pk, link % l1.pk)
# Test we can override with query string # Test we can override with query string
response = self.client.get('/test_admin/admin/admin_views/language/', {'o':'-1'}) response = self.client.get('/test_admin/admin/admin_views/language/', {'o': '-1'})
self.assertContentBefore(response, link % l1.pk, link % l2.pk) self.assertContentBefore(response, link % l1.pk, link % l2.pk)
def testChangeListSortingOverrideModelAdmin(self): def testChangeListSortingOverrideModelAdmin(self):
@ -350,13 +351,13 @@ class AdminViewBasicTest(TestCase):
kinds of 'ordering' fields: field names, method on the model kinds of 'ordering' fields: field names, method on the model
admin and model itself, and other callables. See #17252. admin and model itself, and other callables. See #17252.
""" """
models = [(AdminOrderedField, 'adminorderedfield' ), models = [(AdminOrderedField, 'adminorderedfield'),
(AdminOrderedModelMethod, 'adminorderedmodelmethod'), (AdminOrderedModelMethod, 'adminorderedmodelmethod'),
(AdminOrderedAdminMethod, 'adminorderedadminmethod'), (AdminOrderedAdminMethod, 'adminorderedadminmethod'),
(AdminOrderedCallable, 'adminorderedcallable' )] (AdminOrderedCallable, 'adminorderedcallable')]
for model, url in models: for model, url in models:
a1 = model.objects.create(stuff='The Last Item', order=3) a1 = model.objects.create(stuff='The Last Item', order=3)
a2 = model.objects.create(stuff='The First Item', order=1) a2 = model.objects.create(stuff='The First Item', order=1)
a3 = model.objects.create(stuff='The Middle Item', order=2) a3 = model.objects.create(stuff='The Middle Item', order=2)
response = self.client.get('/test_admin/admin/admin_views/%s/' % url, {}) response = self.client.get('/test_admin/admin/admin_views/%s/' % url, {})
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@ -578,6 +579,7 @@ class AdminViewBasicTest(TestCase):
(self.urlbit, instance.pk)) (self.urlbit, instance.pk))
self.assertNotContains(response, 'deletelink') self.assertNotContains(response, 'deletelink')
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminViewFormUrlTest(TestCase): class AdminViewFormUrlTest(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
@ -643,7 +645,6 @@ class AdminJavaScriptTest(TestCase):
'<script type="text/javascript">document.getElementById("id_start_date_0").focus();</script>' '<script type="text/javascript">document.getElementById("id_start_date_0").focus();</script>'
) )
def test_js_minified_only_if_debug_is_false(self): def test_js_minified_only_if_debug_is_false(self):
""" """
Ensure that the minified versions of the JS files are only used when Ensure that the minified versions of the JS files are only used when
@ -681,7 +682,7 @@ class AdminJavaScriptTest(TestCase):
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class SaveAsTests(TestCase): class SaveAsTests(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
fixtures = ['admin-views-users.xml','admin-views-person.xml'] fixtures = ['admin-views-users.xml', 'admin-views-person.xml']
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.login(username='super', password='secret')
@ -691,7 +692,7 @@ class SaveAsTests(TestCase):
def test_save_as_duplication(self): def test_save_as_duplication(self):
"""Ensure save as actually creates a new person""" """Ensure save as actually creates a new person"""
post_data = {'_saveasnew':'', 'name':'John M', 'gender':1, 'age': 42} post_data = {'_saveasnew': '', 'name': 'John M', 'gender': 1, 'age': 42}
response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data) response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data)
self.assertEqual(len(Person.objects.filter(name='John M')), 1) self.assertEqual(len(Person.objects.filter(name='John M')), 1)
self.assertEqual(len(Person.objects.filter(id=1)), 1) self.assertEqual(len(Person.objects.filter(id=1)), 1)
@ -704,10 +705,11 @@ class SaveAsTests(TestCase):
""" """
response = self.client.get('/test_admin/admin/admin_views/person/1/') response = self.client.get('/test_admin/admin/admin_views/person/1/')
self.assertTrue(response.context['save_as']) self.assertTrue(response.context['save_as'])
post_data = {'_saveasnew':'', 'name':'John M', 'gender':3, 'alive':'checked'} post_data = {'_saveasnew': '', 'name': 'John M', 'gender': 3, 'alive': 'checked'}
response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data) response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data)
self.assertEqual(response.context['form_url'], '/test_admin/admin/admin_views/person/add/') self.assertEqual(response.context['form_url'], '/test_admin/admin/admin_views/person/add/')
class CustomModelAdminTest(AdminViewBasicTest): class CustomModelAdminTest(AdminViewBasicTest):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
urlbit = "admin2" urlbit = "admin2"
@ -763,11 +765,13 @@ class CustomModelAdminTest(AdminViewBasicTest):
response = self.client.get('/test_admin/%s/my_view/' % self.urlbit) response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
self.assertEqual(response.content, b"Django is a magical pony!") self.assertEqual(response.content, b"Django is a magical pony!")
def get_perm(Model, perm): def get_perm(Model, perm):
"""Return the permission object, for the Model""" """Return the permission object, for the Model"""
ct = ContentType.objects.get_for_model(Model) ct = ContentType.objects.get_for_model(Model)
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(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminViewPermissionsTest(TestCase): class AdminViewPermissionsTest(TestCase):
"""Tests for Admin Views Permissions.""" """Tests for Admin Views Permissions."""
@ -870,7 +874,7 @@ class AdminViewPermissionsTest(TestCase):
response = self.client.get('/test_admin/admin/') response = self.client.get('/test_admin/admin/')
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
login = self.client.post('/test_admin/admin/', self.super_email_login) login = self.client.post('/test_admin/admin/', self.super_email_login)
self.assertContains(login, "Your e-mail address is not your username") self.assertContains(login, ERROR_MESSAGE)
# only correct passwords get a username hint # only correct passwords get a username hint
login = self.client.post('/test_admin/admin/', self.super_email_bad_login) login = self.client.post('/test_admin/admin/', self.super_email_bad_login)
self.assertContains(login, ERROR_MESSAGE) self.assertContains(login, ERROR_MESSAGE)
@ -931,7 +935,7 @@ class AdminViewPermissionsTest(TestCase):
def testAddView(self): def testAddView(self):
"""Test add view restricts access and actually adds items.""" """Test add view restricts access and actually adds items."""
add_dict = {'title' : 'Døm ikke', add_dict = {'title': 'Døm ikke',
'content': '<p>great article</p>', 'content': '<p>great article</p>',
'date_0': '2008-03-18', 'date_1': '10:54:39', 'date_0': '2008-03-18', 'date_1': '10:54:39',
'section': 1} 'section': 1}
@ -986,7 +990,7 @@ class AdminViewPermissionsTest(TestCase):
def testChangeView(self): def testChangeView(self):
"""Change view should restrict access and allow users to edit items.""" """Change view should restrict access and allow users to edit items."""
change_dict = {'title' : 'Ikke fordømt', change_dict = {'title': 'Ikke fordømt',
'content': '<p>edited article</p>', 'content': '<p>edited article</p>',
'date_0': '2008-03-18', 'date_1': '10:54:39', 'date_0': '2008-03-18', 'date_1': '10:54:39',
'section': 1} 'section': 1}
@ -1318,6 +1322,7 @@ class AdminViewDeletedObjectsTest(TestCase):
response = self.client.get('/test_admin/admin/admin_views/plot/%s/delete/' % quote(3)) response = self.client.get('/test_admin/admin/admin_views/plot/%s/delete/' % quote(3))
self.assertContains(response, should_contain) self.assertContains(response, should_contain)
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminViewStringPrimaryKeyTest(TestCase): class AdminViewStringPrimaryKeyTest(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
@ -1369,7 +1374,7 @@ class AdminViewStringPrimaryKeyTest(TestCase):
response = self.client.get('/test_admin/admin/') response = self.client.get('/test_admin/admin/')
should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk)) should_contain = """<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>""" % (escape(quote(self.pk)), escape(self.pk))
self.assertContains(response, should_contain) self.assertContains(response, should_contain)
should_contain = "Model with string primary key" # capitalized in Recent Actions should_contain = "Model with string primary key" # capitalized in Recent Actions
self.assertContains(response, should_contain) self.assertContains(response, should_contain)
logentry = LogEntry.objects.get(content_type__name__iexact=should_contain) logentry = LogEntry.objects.get(content_type__name__iexact=should_contain)
# http://code.djangoproject.com/ticket/10275 # http://code.djangoproject.com/ticket/10275
@ -1479,7 +1484,7 @@ class SecureViewTests(TestCase):
def test_secure_view_shows_login_if_not_logged_in(self): def test_secure_view_shows_login_if_not_logged_in(self):
"Ensure that we see the login form" "Ensure that we see the login form"
response = self.client.get('/test_admin/admin/secure-view/' ) response = self.client.get('/test_admin/admin/secure-view/')
self.assertTemplateUsed(response, 'admin/login.html') self.assertTemplateUsed(response, 'admin/login.html')
def test_secure_view_login_successfully_redirects_to_original_url(self): def test_secure_view_login_successfully_redirects_to_original_url(self):
@ -1513,7 +1518,7 @@ class SecureViewTests(TestCase):
response = self.client.get('/test_admin/admin/secure-view/') response = self.client.get('/test_admin/admin/secure-view/')
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login) login = self.client.post('/test_admin/admin/secure-view/', self.super_email_login)
self.assertContains(login, "Your e-mail address is not your username") self.assertContains(login, ERROR_MESSAGE)
# only correct passwords get a username hint # only correct passwords get a username hint
login = self.client.post('/test_admin/admin/secure-view/', self.super_email_bad_login) login = self.client.post('/test_admin/admin/secure-view/', self.super_email_bad_login)
self.assertContains(login, ERROR_MESSAGE) self.assertContains(login, ERROR_MESSAGE)
@ -1583,6 +1588,7 @@ class SecureViewTests(TestCase):
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], 'http://example.com/users/super/') self.assertEqual(response['Location'], 'http://example.com/users/super/')
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminViewUnicodeTest(TestCase): class AdminViewUnicodeTest(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
@ -1625,7 +1631,7 @@ class AdminViewUnicodeTest(TestCase):
} }
response = self.client.post('/test_admin/admin/admin_views/book/1/', post_data) response = self.client.post('/test_admin/admin/admin_views/book/1/', post_data)
self.assertEqual(response.status_code, 302) # redirect somewhere self.assertEqual(response.status_code, 302) # redirect somewhere
def testUnicodeDelete(self): def testUnicodeDelete(self):
""" """
@ -1992,7 +1998,7 @@ class AdminViewListEditable(TestCase):
story1 = Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...') story1 = Story.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
story2 = Story.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...') story2 = Story.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
response = self.client.get('/test_admin/admin/admin_views/story/') response = self.client.get('/test_admin/admin/admin_views/story/')
self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table. self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table.
self.assertContains(response, 'id="id_form-1-id"', 1) self.assertContains(response, 'id="id_form-1-id"', 1)
self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' % (story2.id, story1.id), html=True) self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' % (story2.id, story1.id), html=True)
self.assertContains(response, '<td>%d</td>' % story1.id, 1) self.assertContains(response, '<td>%d</td>' % story1.id, 1)
@ -2006,7 +2012,7 @@ class AdminViewListEditable(TestCase):
story1 = OtherStory.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...') story1 = OtherStory.objects.create(title='The adventures of Guido', content='Once upon a time in Djangoland...')
story2 = OtherStory.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...') story2 = OtherStory.objects.create(title='Crouching Tiger, Hidden Python', content='The Python was sneaking into...')
response = self.client.get('/test_admin/admin/admin_views/otherstory/') response = self.client.get('/test_admin/admin/admin_views/otherstory/')
self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table. self.assertContains(response, 'id="id_form-0-id"', 1) # Only one hidden field, in a separate place than the table.
self.assertContains(response, 'id="id_form-1-id"', 1) self.assertContains(response, 'id="id_form-1-id"', 1)
self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' % (story2.id, story1.id), html=True) self.assertContains(response, '<div class="hiddenfields">\n<input type="hidden" name="form-0-id" value="%d" id="id_form-0-id" /><input type="hidden" name="form-1-id" value="%d" id="id_form-1-id" />\n</div>' % (story2.id, story1.id), html=True)
self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story1.id, story1.id), 1) self.assertContains(response, '<th><a href="%d/">%d</a></th>' % (story1.id, story1.id), 1)
@ -2064,7 +2070,7 @@ class AdminSearchTest(TestCase):
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminInheritedInlinesTest(TestCase): class AdminInheritedInlinesTest(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
fixtures = ['admin-views-users.xml',] fixtures = ['admin-views-users.xml']
def setUp(self): def setUp(self):
self.client.login(username='super', password='secret') self.client.login(username='super', password='secret')
@ -2101,7 +2107,7 @@ class AdminInheritedInlinesTest(TestCase):
} }
response = self.client.post('/test_admin/admin/admin_views/persona/add/', post_data) response = self.client.post('/test_admin/admin/admin_views/persona/add/', post_data)
self.assertEqual(response.status_code, 302) # redirect somewhere self.assertEqual(response.status_code, 302) # redirect somewhere
self.assertEqual(Persona.objects.count(), 1) self.assertEqual(Persona.objects.count(), 1)
self.assertEqual(FooAccount.objects.count(), 1) self.assertEqual(FooAccount.objects.count(), 1)
self.assertEqual(BarAccount.objects.count(), 1) self.assertEqual(BarAccount.objects.count(), 1)
@ -2148,6 +2154,7 @@ class AdminInheritedInlinesTest(TestCase):
self.assertEqual(BarAccount.objects.all()[0].username, "%s-1" % bar_user) self.assertEqual(BarAccount.objects.all()[0].username, "%s-1" % bar_user)
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(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminActionsTest(TestCase): class AdminActionsTest(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
@ -2163,7 +2170,7 @@ class AdminActionsTest(TestCase):
"Tests a custom action defined in a ModelAdmin method" "Tests a custom action defined in a ModelAdmin method"
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [1], ACTION_CHECKBOX_NAME: [1],
'action' : 'mail_admin', 'action': 'mail_admin',
'index': 0, 'index': 0,
} }
response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
@ -2174,12 +2181,12 @@ class AdminActionsTest(TestCase):
"Tests the default delete action defined as a ModelAdmin method" "Tests the default delete action defined as a ModelAdmin method"
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [1, 2], ACTION_CHECKBOX_NAME: [1, 2],
'action' : 'delete_selected', 'action': 'delete_selected',
'index': 0, 'index': 0,
} }
delete_confirmation_data = { delete_confirmation_data = {
ACTION_CHECKBOX_NAME: [1, 2], ACTION_CHECKBOX_NAME: [1, 2],
'action' : 'delete_selected', 'action': 'delete_selected',
'post': 'yes', 'post': 'yes',
} }
confirmation = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) confirmation = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
@ -2203,12 +2210,12 @@ class AdminActionsTest(TestCase):
subscriber.save() subscriber.save()
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [9999, 2], ACTION_CHECKBOX_NAME: [9999, 2],
'action' : 'delete_selected', 'action': 'delete_selected',
'index': 0, 'index': 0,
} }
response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
self.assertTemplateUsed(response, 'admin/delete_selected_confirmation.html') self.assertTemplateUsed(response, 'admin/delete_selected_confirmation.html')
self.assertContains(response, 'value="9999"') # Instead of 9,999 self.assertContains(response, 'value="9999"') # Instead of 9,999
self.assertContains(response, 'value="2"') self.assertContains(response, 'value="2"')
settings.USE_THOUSAND_SEPARATOR = self.old_USE_THOUSAND_SEPARATOR settings.USE_THOUSAND_SEPARATOR = self.old_USE_THOUSAND_SEPARATOR
settings.USE_L10N = self.old_USE_L10N settings.USE_L10N = self.old_USE_L10N
@ -2225,7 +2232,7 @@ class AdminActionsTest(TestCase):
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [q1.pk, q2.pk], ACTION_CHECKBOX_NAME: [q1.pk, q2.pk],
'action' : 'delete_selected', 'action': 'delete_selected',
'index': 0, 'index': 0,
} }
@ -2239,7 +2246,7 @@ class AdminActionsTest(TestCase):
"Tests a custom action defined in a function" "Tests a custom action defined in a function"
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [1], ACTION_CHECKBOX_NAME: [1],
'action' : 'external_mail', 'action': 'external_mail',
'index': 0, 'index': 0,
} }
response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data) response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
@ -2250,7 +2257,7 @@ class AdminActionsTest(TestCase):
"Tests a custom action defined in a function" "Tests a custom action defined in a function"
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [1], ACTION_CHECKBOX_NAME: [1],
'action' : 'redirect_to', 'action': 'redirect_to',
'index': 0, 'index': 0,
} }
response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data) response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
@ -2264,7 +2271,7 @@ class AdminActionsTest(TestCase):
""" """
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [1], ACTION_CHECKBOX_NAME: [1],
'action' : 'external_mail', 'action': 'external_mail',
'index': 0, 'index': 0,
} }
url = '/test_admin/admin/admin_views/externalsubscriber/?o=1' url = '/test_admin/admin/admin_views/externalsubscriber/?o=1'
@ -2329,7 +2336,7 @@ class AdminActionsTest(TestCase):
""" """
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [], ACTION_CHECKBOX_NAME: [],
'action' : 'delete_selected', 'action': 'delete_selected',
'index': 0, 'index': 0,
} }
response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
@ -2343,7 +2350,7 @@ class AdminActionsTest(TestCase):
""" """
action_data = { action_data = {
ACTION_CHECKBOX_NAME: [1, 2], ACTION_CHECKBOX_NAME: [1, 2],
'action' : '', 'action': '',
'index': 0, 'index': 0,
} }
response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data)
@ -2387,7 +2394,7 @@ class TestCustomChangeList(TestCase):
# Insert some data # Insert some data
post_data = {"name": "First Gadget"} post_data = {"name": "First Gadget"}
response = self.client.post('/test_admin/%s/admin_views/gadget/add/' % self.urlbit, post_data) response = self.client.post('/test_admin/%s/admin_views/gadget/add/' % self.urlbit, post_data)
self.assertEqual(response.status_code, 302) # redirect somewhere self.assertEqual(response.status_code, 302) # redirect somewhere
# Hit the page once to get messages out of the queue message list # Hit the page once to get messages out of the queue message list
response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit) response = self.client.get('/test_admin/%s/admin_views/gadget/' % self.urlbit)
# Ensure that that data is still not visible on the page # Ensure that that data is still not visible on the page
@ -2415,6 +2422,7 @@ class TestInlineNotEditable(TestCase):
response = self.client.get('/test_admin/admin/admin_views/parent/add/') response = self.client.get('/test_admin/admin/admin_views/parent/add/')
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminCustomQuerysetTest(TestCase): class AdminCustomQuerysetTest(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
@ -2471,6 +2479,7 @@ class AdminCustomQuerysetTest(TestCase):
# Message should contain non-ugly model name. Instance representation is set by model's __unicode__() # Message should contain non-ugly model name. Instance representation is set by model's __unicode__()
self.assertContains(response, '<li class="info">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True) self.assertContains(response, '<li class="info">The cover letter &quot;John Doe II&quot; was changed successfully.</li>', html=True)
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminInlineFileUploadTest(TestCase): class AdminInlineFileUploadTest(TestCase):
urls = "regressiontests.admin_views.urls" urls = "regressiontests.admin_views.urls"
@ -2611,7 +2620,7 @@ class AdminInlineTests(TestCase):
result = self.client.login(username='super', password='secret') result = self.client.login(username='super', password='secret')
self.assertEqual(result, True) 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()
def tearDown(self): def tearDown(self):
@ -2937,14 +2946,14 @@ class PrePopulatedTest(TestCase):
self.assertNotContains(response, "field['dependency_ids'].push('#id_title');") self.assertNotContains(response, "field['dependency_ids'].push('#id_title');")
self.assertNotContains(response, "id: '#id_prepopulatedsubpost_set-0-subslug',") self.assertNotContains(response, "id: '#id_prepopulatedsubpost_set-0-subslug',")
@override_settings(USE_THOUSAND_SEPARATOR = True, USE_L10N = True) @override_settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=True)
def test_prepopulated_maxlength_localized(self): def test_prepopulated_maxlength_localized(self):
""" """
Regression test for #15938: if USE_THOUSAND_SEPARATOR is set, make sure Regression test for #15938: if USE_THOUSAND_SEPARATOR is set, make sure
that maxLength (in the JavaScript) is rendered without separators. that maxLength (in the JavaScript) is rendered without separators.
""" """
response = self.client.get('/test_admin/admin/admin_views/prepopulatedpostlargeslug/add/') response = self.client.get('/test_admin/admin/admin_views/prepopulatedpostlargeslug/add/')
self.assertContains(response, "maxLength: 1000") # instead of 1,000 self.assertContains(response, "maxLength: 1000") # instead of 1,000
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
@ -2990,8 +2999,8 @@ class SeleniumPrePopulatedFirefoxTests(AdminSeleniumWebDriverTestCase):
self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-name').send_keys(' now you haVe anöther sŤāÇkeð inline with a very ... loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text... ') self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-name').send_keys(' now you haVe anöther sŤāÇkeð inline with a very ... loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text... ')
slug1 = self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-slug1').get_attribute('value') slug1 = self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-slug1').get_attribute('value')
slug2 = self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-slug2').get_attribute('value') slug2 = self.selenium.find_element_by_css_selector('#id_relatedprepopulated_set-1-slug2').get_attribute('value')
self.assertEqual(slug1, 'now-you-have-another-stacked-inline-very-loooooooo') # 50 characters maximum for slug1 field self.assertEqual(slug1, 'now-you-have-another-stacked-inline-very-loooooooo') # 50 characters maximum for slug1 field
self.assertEqual(slug2, 'option-two-now-you-have-another-stacked-inline-very-looooooo') # 60 characters maximum for slug2 field self.assertEqual(slug2, 'option-two-now-you-have-another-stacked-inline-very-looooooo') # 60 characters maximum for slug2 field
# Tabular inlines ---------------------------------------------------- # Tabular inlines ----------------------------------------------------
# Initial inline # Initial inline
@ -3042,7 +3051,7 @@ class SeleniumPrePopulatedFirefoxTests(AdminSeleniumWebDriverTestCase):
slug2='option-one-here-stacked-inline', slug2='option-one-here-stacked-inline',
) )
RelatedPrepopulated.objects.get( RelatedPrepopulated.objects.get(
name=' now you haVe anöther sŤāÇkeð inline with a very ... loooooooooooooooooo', # 75 characters in name field name=' now you haVe anöther sŤāÇkeð inline with a very ... loooooooooooooooooo', # 75 characters in name field
pubdate='1999-01-25', pubdate='1999-01-25',
status='option two', status='option two',
slug1='now-you-have-another-stacked-inline-very-loooooooo', slug1='now-you-have-another-stacked-inline-very-loooooooo',
@ -3067,6 +3076,7 @@ class SeleniumPrePopulatedFirefoxTests(AdminSeleniumWebDriverTestCase):
class SeleniumPrePopulatedChromeTests(SeleniumPrePopulatedFirefoxTests): class SeleniumPrePopulatedChromeTests(SeleniumPrePopulatedFirefoxTests):
webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.chrome.webdriver.WebDriver'
class SeleniumPrePopulatedIETests(SeleniumPrePopulatedFirefoxTests): class SeleniumPrePopulatedIETests(SeleniumPrePopulatedFirefoxTests):
webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver' webdriver_class = 'selenium.webdriver.ie.webdriver.WebDriver'
@ -3127,7 +3137,7 @@ class ReadonlyTest(TestCase):
p = Post.objects.get() p = Post.objects.get()
self.assertEqual(p.posted, datetime.date.today()) self.assertEqual(p.posted, datetime.date.today())
data["posted"] = "10-8-1990" # some date that's not today data["posted"] = "10-8-1990" # some date that's not today
response = self.client.post('/test_admin/admin/admin_views/post/add/', data) response = self.client.post('/test_admin/admin/admin_views/post/add/', data)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertEqual(Post.objects.count(), 2) self.assertEqual(Post.objects.count(), 2)
@ -3169,7 +3179,7 @@ class RawIdFieldsTest(TestCase):
response = self.client.get('/test_admin/admin/admin_views/sketch/add/') response = self.client.get('/test_admin/admin/admin_views/sketch/add/')
# Find the link # Find the link
m = re.search(br'<a href="([^"]*)"[^>]* id="lookup_id_inquisition"', response.content) m = re.search(br'<a href="([^"]*)"[^>]* id="lookup_id_inquisition"', response.content)
self.assertTrue(m) # Got a match self.assertTrue(m) # Got a match
popup_url = m.groups()[0].decode().replace("&amp;", "&") popup_url = m.groups()[0].decode().replace("&amp;", "&")
# Handle relative links # Handle relative links
@ -3179,6 +3189,7 @@ class RawIdFieldsTest(TestCase):
self.assertContains(response2, "Spain") self.assertContains(response2, "Spain")
self.assertNotContains(response2, "England") self.assertNotContains(response2, "England")
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class UserAdminTest(TestCase): class UserAdminTest(TestCase):
""" """
@ -3333,7 +3344,7 @@ class CSSTest(TestCase):
self.assertContains(response, 'class="form-row field-awesomeness_level"') self.assertContains(response, 'class="form-row field-awesomeness_level"')
self.assertContains(response, 'class="form-row field-coolness"') self.assertContains(response, 'class="form-row field-coolness"')
self.assertContains(response, 'class="form-row field-value"') self.assertContains(response, 'class="form-row field-value"')
self.assertContains(response, 'class="form-row"') # The lambda function self.assertContains(response, 'class="form-row"') # The lambda function
# The tabular inline # The tabular inline
self.assertContains(response, '<td class="field-url">') self.assertContains(response, '<td class="field-url">')
@ -3345,6 +3356,7 @@ try:
except ImportError: except ImportError:
docutils = None docutils = None
@unittest.skipUnless(docutils, "no docutils installed.") @unittest.skipUnless(docutils, "no docutils installed.")
@override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',)) @override_settings(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminDocsTest(TestCase): class AdminDocsTest(TestCase):
@ -3403,7 +3415,7 @@ class ValidXHTMLTests(TestCase):
@override_settings( @override_settings(
TEMPLATE_CONTEXT_PROCESSORS=filter( TEMPLATE_CONTEXT_PROCESSORS=filter(
lambda t:t!='django.core.context_processors.i18n', lambda t: t != 'django.core.context_processors.i18n',
global_settings.TEMPLATE_CONTEXT_PROCESSORS), global_settings.TEMPLATE_CONTEXT_PROCESSORS),
USE_I18N=False, USE_I18N=False,
) )
@ -3540,6 +3552,7 @@ class DateHierarchyTests(TestCase):
self.assert_non_localized_year(response, 2003) self.assert_non_localized_year(response, 2003)
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(PASSWORD_HASHERS=('django.contrib.auth.hashers.SHA1PasswordHasher',))
class AdminCustomSaveRelatedTests(TestCase): class AdminCustomSaveRelatedTests(TestCase):
""" """