desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'Cyclic relationships should still cause each object to only be
listed once.'
| def test_cyclic(self):
| one = u'<li>Cyclic one: <a href="/test_admin/admin/admin_views/cyclicone/1/">I am recursive</a>'
two = u'<li>Cyclic two: <a href="/test_admin/admin/admin_views/cyclictwo/1/">I am recursive too</a>'
response = self.client.get((u'/test_admin/admin/admin_views/cyclicone/%s/delete/' % quote(1)))
self.assertContains(response, one, 1)
self.assertContains(response, two, 1)
|
'If a deleted object has two relationships from another model,
both of those should be followed in looking for related
objects to delete.'
| def test_multiple_fkeys_to_same_model(self):
| should_contain = u'<li>Plot: <a href="/test_admin/admin/admin_views/plot/1/">World Domination</a>'
response = self.client.get((u'/test_admin/admin/admin_views/villain/%s/delete/' % quote(1)))
self.assertContains(response, should_contain)
response = self.client.get((u'/test_admin/admin/admin_views/villain/%s/delete/' % quote(2)))
self.assertContains(response, should_contain)
|
'If a deleted object has two relationships pointing to it from
another object, the other object should still only be listed
once.'
| def test_multiple_fkeys_to_same_instance(self):
| should_contain = u'<li>Plot: <a href="/test_admin/admin/admin_views/plot/2/">World Peace</a></li>'
response = self.client.get((u'/test_admin/admin/admin_views/villain/%s/delete/' % quote(2)))
self.assertContains(response, should_contain, 1)
|
'In the case of an inherited model, if either the child or
parent-model instance is deleted, both instances are listed
for deletion, as well as any relationships they have.'
| def test_inheritance(self):
| should_contain = [u'<li>Villain: <a href="/test_admin/admin/admin_views/villain/3/">Bob</a>', u'<li>Super villain: <a href="/test_admin/admin/admin_views/supervillain/3/">Bob</a>', u'<li>Secret hideout: floating castle', u'<li>Super secret hideout: super floating castle!']
response = self.client.get((u'/test_admin/admin/admin_views/villain/%s/delete/' % quote(3)))
for should in should_contain:
self.assertContains(response, should, 1)
response = self.client.get((u'/test_admin/admin/admin_views/supervillain/%s/delete/' % quote(3)))
for should in should_contain:
self.assertContains(response, should, 1)
|
'If a deleted object has GenericForeignKeys pointing to it,
those objects should be listed for deletion.'
| def test_generic_relations(self):
| plot = Plot.objects.get(pk=3)
tag = FunkyTag.objects.create(content_object=plot, name=u'hott')
should_contain = u'<li>Funky tag: hott'
response = self.client.get((u'/test_admin/admin/admin_views/plot/%s/delete/' % quote(3)))
self.assertContains(response, should_contain)
|
'Retrieving the history for an object using urlencoded form of primary
key should work.
Refs #12349, #18550.'
| def test_get_history_view(self):
| response = self.client.get((u'/test_admin/admin/admin_views/modelwithstringprimarykey/%s/history/' % quote(self.pk)))
self.assertContains(response, escape(self.pk))
self.assertContains(response, u'Changed something')
self.assertEqual(response.status_code, 200)
|
'Retrieving the object using urlencoded form of primary key should work'
| def test_get_change_view(self):
| response = self.client.get((u'/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(self.pk)))
self.assertContains(response, escape(self.pk))
self.assertEqual(response.status_code, 200)
|
'Link to the changeform of the object in changelist should use reverse() and be quoted -- #18072'
| def test_changelist_to_changeform_link(self):
| prefix = u'/test_admin/admin/admin_views/modelwithstringprimarykey/'
response = self.client.get(prefix)
pk_final_url = escape(iri_to_uri(quote(self.pk)))
should_contain = (u'<th><a href="%s%s/">%s</a></th>' % (prefix, pk_final_url, escape(self.pk)))
self.assertContains(response, should_contain)
|
'The link from the recent actions list referring to the changeform of the object should be quoted'
| def test_recentactions_link(self):
| response = self.client.get(u'/test_admin/admin/')
should_contain = (u'<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>' % (escape(quote(self.pk)), escape(self.pk)))
self.assertContains(response, should_contain)
|
'If a LogEntry is missing content_type it will not display it in span tag under the hyperlink.'
| def test_recentactions_without_content_type(self):
| response = self.client.get(u'/test_admin/admin/')
should_contain = (u'<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>' % (escape(quote(self.pk)), escape(self.pk)))
self.assertContains(response, should_contain)
should_contain = u'Model with string primary key'
self.assertContains(response, should_contain)
logentry = LogEntry.objects.get(content_type__name__iexact=should_contain)
logentry.content_type = None
logentry.save()
counted_presence_before = response.content.count(force_bytes(should_contain))
response = self.client.get(u'/test_admin/admin/')
counted_presence_after = response.content.count(force_bytes(should_contain))
self.assertEqual((counted_presence_before - 1), counted_presence_after)
|
'The link from the delete confirmation page referring back to the changeform of the object should be quoted'
| def test_deleteconfirmation_link(self):
| response = self.client.get((u'/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/' % quote(self.pk)))
should_contain = (u'/%s/">%s</a>' % (escape(iri_to_uri(quote(self.pk))), escape(self.pk)))
self.assertContains(response, should_contain)
|
'A model with a primary key that ends with add should be visible'
| def test_url_conflicts_with_add(self):
| add_model = ModelWithStringPrimaryKey(pk=u'i have something to add')
add_model.save()
response = self.client.get((u'/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(add_model.pk)))
should_contain = u'<h1>Change model with string primary key</h1>'
self.assertContains(response, should_contain)
|
'A model with a primary key that ends with delete should be visible'
| def test_url_conflicts_with_delete(self):
| delete_model = ModelWithStringPrimaryKey(pk=u'delete')
delete_model.save()
response = self.client.get((u'/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(delete_model.pk)))
should_contain = u'<h1>Change model with string primary key</h1>'
self.assertContains(response, should_contain)
|
'A model with a primary key that ends with history should be visible'
| def test_url_conflicts_with_history(self):
| history_model = ModelWithStringPrimaryKey(pk=u'history')
history_model.save()
response = self.client.get((u'/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(history_model.pk)))
should_contain = u'<h1>Change model with string primary key</h1>'
self.assertContains(response, should_contain)
|
'\'View on site should\' work properly with char fields'
| def test_shortcut_view_with_escaping(self):
| model = ModelWithStringPrimaryKey(pk=u'abc_123')
model.save()
response = self.client.get((u'/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(model.pk)))
should_contain = (u'/%s/" class="viewsitelink">' % model.pk)
self.assertContains(response, should_contain)
|
'Object history button link should work and contain the pk value quoted.'
| def test_change_view_history_link(self):
| url = reverse((u'admin:%s_modelwithstringprimarykey_change' % ModelWithStringPrimaryKey._meta.app_label), args=(quote(self.pk),))
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
expected_link = reverse((u'admin:%s_modelwithstringprimarykey_history' % ModelWithStringPrimaryKey._meta.app_label), args=(quote(self.pk),))
self.assertContains(response, (u'<a href="%s" class="historylink"' % expected_link))
|
'Ensure that we see the login form'
| def test_secure_view_shows_login_if_not_logged_in(self):
| response = self.client.get(u'/test_admin/admin/secure-view/')
self.assertTemplateUsed(response, u'admin/login.html')
|
'Make sure only staff members can log in.
Successful posts to the login page will redirect to the orignal url.
Unsuccessfull attempts will continue to render the login page with
a 200 status code.'
| def test_staff_member_required_decorator_works_as_per_admin_login(self):
| response = self.client.get(u'/test_admin/admin/secure-view/')
self.assertEqual(response.status_code, 200)
login = self.client.post(u'/test_admin/admin/secure-view/', self.super_login)
self.assertRedirects(login, u'/test_admin/admin/secure-view/')
self.assertFalse(login.context)
self.client.get(u'/test_admin/admin/logout/')
self.assertEqual(self.client.session.test_cookie_worked(), False)
response = self.client.get(u'/test_admin/admin/secure-view/')
self.assertEqual(response.status_code, 200)
login = self.client.post(u'/test_admin/admin/secure-view/', self.super_email_login)
self.assertContains(login, ERROR_MESSAGE)
login = self.client.post(u'/test_admin/admin/secure-view/', self.super_email_bad_login)
self.assertContains(login, ERROR_MESSAGE)
new_user = User(username=u'jondoe', password=u'secret', email=u'[email protected]')
new_user.save()
login = self.client.post(u'/test_admin/admin/secure-view/', self.super_email_login)
self.assertContains(login, ERROR_MESSAGE)
response = self.client.get(u'/test_admin/admin/secure-view/')
self.assertEqual(response.status_code, 200)
login = self.client.post(u'/test_admin/admin/secure-view/', self.adduser_login)
self.assertRedirects(login, u'/test_admin/admin/secure-view/')
self.assertFalse(login.context)
self.client.get(u'/test_admin/admin/logout/')
response = self.client.get(u'/test_admin/admin/secure-view/')
self.assertEqual(response.status_code, 200)
login = self.client.post(u'/test_admin/admin/secure-view/', self.changeuser_login)
self.assertRedirects(login, u'/test_admin/admin/secure-view/')
self.assertFalse(login.context)
self.client.get(u'/test_admin/admin/logout/')
response = self.client.get(u'/test_admin/admin/secure-view/')
self.assertEqual(response.status_code, 200)
login = self.client.post(u'/test_admin/admin/secure-view/', self.deleteuser_login)
self.assertRedirects(login, u'/test_admin/admin/secure-view/')
self.assertFalse(login.context)
self.client.get(u'/test_admin/admin/logout/')
response = self.client.get(u'/test_admin/admin/secure-view/')
self.assertEqual(response.status_code, 200)
login = self.client.post(u'/test_admin/admin/secure-view/', self.joepublic_login)
self.assertEqual(login.status_code, 200)
self.assertContains(login, ERROR_MESSAGE)
login = self.client.login(username=u'joepublic', password=u'secret')
self.client.get(u'/test_admin/admin/secure-view/')
self.client.post(u'/test_admin/admin/secure-view/', self.super_login)
self.assertEqual(self.client.session.test_cookie_worked(), False)
|
'Only admin users should be able to use the admin shortcut view.'
| def test_shortcut_view_only_available_to_staff(self):
| user_ctype = ContentType.objects.get_for_model(User)
user = User.objects.get(username=u'super')
shortcut_url = (u'/test_admin/admin/r/%s/%s/' % (user_ctype.pk, user.pk))
response = self.client.get(shortcut_url, follow=False)
self.assertTemplateUsed(response, u'admin/login.html')
self.client.login(username=u'super', password=u'secret')
response = self.client.get(shortcut_url, follow=False)
self.assertEqual(response.status_code, 302)
self.assertEqual(response[u'Location'], u'http://example.com/users/super/')
|
'A test to ensure that POST on edit_view handles non-ascii characters.'
| def testUnicodeEdit(self):
| post_data = {u'name': u'Test l\xe6rdommer', u'chapter_set-TOTAL_FORMS': u'6', u'chapter_set-INITIAL_FORMS': u'3', u'chapter_set-MAX_NUM_FORMS': u'0', u'chapter_set-0-id': u'1', u'chapter_set-0-title': u'Norske bostaver \xe6\xf8\xe5 skaper problemer', u'chapter_set-0-content': u'<p>Sv\xe6rt frustrerende med UnicodeDecodeError</p>', u'chapter_set-1-id': u'2', u'chapter_set-1-title': u'Kj\xe6rlighet.', u'chapter_set-1-content': u'<p>La kj\xe6rligheten til de lidende seire.</p>', u'chapter_set-2-id': u'3', u'chapter_set-2-title': u'Need a title.', u'chapter_set-2-content': u'<p>Newest content</p>', u'chapter_set-3-id': u'', u'chapter_set-3-title': u'', u'chapter_set-3-content': u'', u'chapter_set-4-id': u'', u'chapter_set-4-title': u'', u'chapter_set-4-content': u'', u'chapter_set-5-id': u'', u'chapter_set-5-title': u'', u'chapter_set-5-content': u''}
response = self.client.post(u'/test_admin/admin/admin_views/book/1/', post_data)
self.assertEqual(response.status_code, 302)
|
'Ensure that the delete_view handles non-ascii characters'
| def testUnicodeDelete(self):
| delete_dict = {u'post': u'yes'}
response = self.client.get(u'/test_admin/admin/admin_views/book/1/delete/')
self.assertEqual(response.status_code, 200)
response = self.client.post(u'/test_admin/admin/admin_views/book/1/delete/', delete_dict)
self.assertRedirects(response, u'/test_admin/admin/admin_views/book/')
|
'Ensure that non field errors are displayed for each of the
forms in the changelist\'s formset. Refs #13126.'
| def test_non_field_errors(self):
| fd1 = FoodDelivery.objects.create(reference=u'123', driver=u'bill', restaurant=u'thai')
fd2 = FoodDelivery.objects.create(reference=u'456', driver=u'bill', restaurant=u'india')
fd3 = FoodDelivery.objects.create(reference=u'789', driver=u'bill', restaurant=u'pizza')
data = {u'form-TOTAL_FORMS': u'3', u'form-INITIAL_FORMS': u'3', u'form-MAX_NUM_FORMS': u'0', u'form-0-id': str(fd1.id), u'form-0-reference': u'123', u'form-0-driver': u'bill', u'form-0-restaurant': u'thai', u'form-1-id': str(fd2.id), u'form-1-reference': u'456', u'form-1-driver': u'bill', u'form-1-restaurant': u'thai', u'form-2-id': str(fd3.id), u'form-2-reference': u'789', u'form-2-driver': u'bill', u'form-2-restaurant': u'pizza', u'_save': u'Save'}
response = self.client.post(u'/test_admin/admin/admin_views/fooddelivery/', data)
self.assertContains(response, u'<tr><td colspan="4"><ul class="errorlist"><li>Food delivery with this Driver and Restaurant already exists.</li></ul></td></tr>', 1, html=True)
data = {u'form-TOTAL_FORMS': u'3', u'form-INITIAL_FORMS': u'3', u'form-MAX_NUM_FORMS': u'0', u'form-0-id': str(fd1.id), u'form-0-reference': u'123', u'form-0-driver': u'bill', u'form-0-restaurant': u'thai', u'form-1-id': str(fd2.id), u'form-1-reference': u'456', u'form-1-driver': u'bill', u'form-1-restaurant': u'thai', u'form-2-id': str(fd3.id), u'form-2-reference': u'789', u'form-2-driver': u'bill', u'form-2-restaurant': u'thai', u'_save': u'Save'}
response = self.client.post(u'/test_admin/admin/admin_views/fooddelivery/', data)
self.assertContains(response, u'<tr><td colspan="4"><ul class="errorlist"><li>Food delivery with this Driver and Restaurant already exists.</li></ul></td></tr>', 2, html=True)
|
'Ensure that pagination works for list_editable items.
Refs #16819.'
| def test_list_editable_pagination(self):
| UnorderedObject.objects.create(id=1, name=u'Unordered object #1')
UnorderedObject.objects.create(id=2, name=u'Unordered object #2')
UnorderedObject.objects.create(id=3, name=u'Unordered object #3')
response = self.client.get(u'/test_admin/admin/admin_views/unorderedobject/')
self.assertContains(response, u'Unordered object #3')
self.assertContains(response, u'Unordered object #2')
self.assertNotContains(response, u'Unordered object #1')
response = self.client.get(u'/test_admin/admin/admin_views/unorderedobject/?p=1')
self.assertNotContains(response, u'Unordered object #3')
self.assertNotContains(response, u'Unordered object #2')
self.assertContains(response, u'Unordered object #1')
|
'Fields should not be list-editable in popups.'
| def test_list_editable_popup(self):
| response = self.client.get(u'/test_admin/admin/admin_views/person/')
self.assertNotEqual(response.context[u'cl'].list_editable, ())
response = self.client.get((u'/test_admin/admin/admin_views/person/?%s' % IS_POPUP_VAR))
self.assertEqual(response.context[u'cl'].list_editable, ())
|
'Ensure that hidden pk fields aren\'t displayed in the table body and
that their corresponding human-readable value is displayed instead.
Note that the hidden pk fields are in fact be displayed but
separately (not in the table), and only once.
Refs #12475.'
| def test_pk_hidden_fields(self):
| story1 = Story.objects.create(title=u'The adventures of Guido', content=u'Once upon a time in Djangoland...')
story2 = Story.objects.create(title=u'Crouching Tiger, Hidden Python', content=u'The Python was sneaking into...')
response = self.client.get(u'/test_admin/admin/admin_views/story/')
self.assertContains(response, u'id="id_form-0-id"', 1)
self.assertContains(response, u'id="id_form-1-id"', 1)
self.assertContains(response, (u'<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, (u'<td>%d</td>' % story1.id), 1)
self.assertContains(response, (u'<td>%d</td>' % story2.id), 1)
|
'Similarly as test_pk_hidden_fields, but when the hidden pk fields are
referenced in list_display_links.
Refs #12475.'
| def test_pk_hidden_fields_with_list_display_links(self):
| story1 = OtherStory.objects.create(title=u'The adventures of Guido', content=u'Once upon a time in Djangoland...')
story2 = OtherStory.objects.create(title=u'Crouching Tiger, Hidden Python', content=u'The Python was sneaking into...')
link1 = reverse(u'admin:admin_views_otherstory_change', args=(story1.pk,))
link2 = reverse(u'admin:admin_views_otherstory_change', args=(story2.pk,))
response = self.client.get(u'/test_admin/admin/admin_views/otherstory/')
self.assertContains(response, u'id="id_form-0-id"', 1)
self.assertContains(response, u'id="id_form-1-id"', 1)
self.assertContains(response, (u'<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, (u'<th><a href="%s">%d</a></th>' % (link1, story1.id)), 1)
self.assertContains(response, (u'<th><a href="%s">%d</a></th>' % (link2, story2.id)), 1)
|
'Check that a search that mentions sibling models'
| def test_search_on_sibling_models(self):
| response = self.client.get(u'/test_admin/admin/admin_views/recommendation/?q=bar')
self.assertContains(response, u'\n1 recommendation\n')
|
'Ensure that the to_field GET parameter is preserved when a search
is performed. Refs #10918.'
| def test_with_fk_to_field(self):
| from django.contrib.admin.views.main import TO_FIELD_VAR
response = self.client.get((u'/test_admin/admin/auth/user/?q=joe&%s=username' % TO_FIELD_VAR))
self.assertContains(response, u'\n1 user\n')
self.assertContains(response, u'<input type="hidden" name="t" value="username"/>', html=True)
|
'Ensure that inline models which inherit from a common parent are correctly handled by admin.'
| def testInline(self):
| foo_user = u'foo username'
bar_user = u'bar username'
name_re = re.compile('name="(.*?)"')
response = self.client.get(u'/test_admin/admin/admin_views/persona/add/')
names = name_re.findall(response.content)
self.assertEqual(len(names), len(set(names)))
post_data = {u'name': u'Test Name', u'accounts-TOTAL_FORMS': u'1', u'accounts-INITIAL_FORMS': u'0', u'accounts-MAX_NUM_FORMS': u'0', u'accounts-0-username': foo_user, u'accounts-2-TOTAL_FORMS': u'1', u'accounts-2-INITIAL_FORMS': u'0', u'accounts-2-MAX_NUM_FORMS': u'0', u'accounts-2-0-username': bar_user}
response = self.client.post(u'/test_admin/admin/admin_views/persona/add/', post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Persona.objects.count(), 1)
self.assertEqual(FooAccount.objects.count(), 1)
self.assertEqual(BarAccount.objects.count(), 1)
self.assertEqual(FooAccount.objects.all()[0].username, foo_user)
self.assertEqual(BarAccount.objects.all()[0].username, bar_user)
self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
persona_id = Persona.objects.all()[0].id
foo_id = FooAccount.objects.all()[0].id
bar_id = BarAccount.objects.all()[0].id
response = self.client.get((u'/test_admin/admin/admin_views/persona/%d/' % persona_id))
names = name_re.findall(response.content)
self.assertEqual(len(names), len(set(names)))
post_data = {u'name': u'Test Name', u'accounts-TOTAL_FORMS': u'2', u'accounts-INITIAL_FORMS': u'1', u'accounts-MAX_NUM_FORMS': u'0', u'accounts-0-username': (u'%s-1' % foo_user), u'accounts-0-account_ptr': str(foo_id), u'accounts-0-persona': str(persona_id), u'accounts-2-TOTAL_FORMS': u'2', u'accounts-2-INITIAL_FORMS': u'1', u'accounts-2-MAX_NUM_FORMS': u'0', u'accounts-2-0-username': (u'%s-1' % bar_user), u'accounts-2-0-account_ptr': str(bar_id), u'accounts-2-0-persona': str(persona_id)}
response = self.client.post((u'/test_admin/admin/admin_views/persona/%d/' % persona_id), post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Persona.objects.count(), 1)
self.assertEqual(FooAccount.objects.count(), 1)
self.assertEqual(BarAccount.objects.count(), 1)
self.assertEqual(FooAccount.objects.all()[0].username, (u'%s-1' % foo_user))
self.assertEqual(BarAccount.objects.all()[0].username, (u'%s-1' % bar_user))
self.assertEqual(Persona.objects.all()[0].accounts.count(), 2)
|
'Tests a custom action defined in a ModelAdmin method'
| def test_model_admin_custom_action(self):
| action_data = {ACTION_CHECKBOX_NAME: [1], u'action': u'mail_admin', u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/subscriber/', action_data)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, u'Greetings from a ModelAdmin action')
|
'Tests the default delete action defined as a ModelAdmin method'
| def test_model_admin_default_delete_action(self):
| action_data = {ACTION_CHECKBOX_NAME: [1, 2], u'action': u'delete_selected', u'index': 0}
delete_confirmation_data = {ACTION_CHECKBOX_NAME: [1, 2], u'action': u'delete_selected', u'post': u'yes'}
confirmation = self.client.post(u'/test_admin/admin/admin_views/subscriber/', action_data)
self.assertIsInstance(confirmation, TemplateResponse)
self.assertContains(confirmation, u'Are you sure you want to delete the selected subscribers?')
self.assertContains(confirmation, ACTION_CHECKBOX_NAME, count=2)
response = self.client.post(u'/test_admin/admin/admin_views/subscriber/', delete_confirmation_data)
self.assertEqual(Subscriber.objects.count(), 0)
|
'If USE_THOUSAND_SEPARATOR is set, make sure that the ids for
the objects selected for deletion are rendered without separators.
Refs #14895.'
| def test_non_localized_pk(self):
| self.old_USE_THOUSAND_SEPARATOR = settings.USE_THOUSAND_SEPARATOR
self.old_USE_L10N = settings.USE_L10N
settings.USE_THOUSAND_SEPARATOR = True
settings.USE_L10N = True
subscriber = Subscriber.objects.get(id=1)
subscriber.id = 9999
subscriber.save()
action_data = {ACTION_CHECKBOX_NAME: [9999, 2], u'action': u'delete_selected', u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/subscriber/', action_data)
self.assertTemplateUsed(response, u'admin/delete_selected_confirmation.html')
self.assertContains(response, u'value="9999"')
self.assertContains(response, u'value="2"')
settings.USE_THOUSAND_SEPARATOR = self.old_USE_THOUSAND_SEPARATOR
settings.USE_L10N = self.old_USE_L10N
|
'Tests the default delete action defined as a ModelAdmin method in the
case where some related objects are protected from deletion.'
| def test_model_admin_default_delete_action_protected(self):
| q1 = Question.objects.create(question=u'Why?')
a1 = Answer.objects.create(question=q1, answer=u'Because.')
a2 = Answer.objects.create(question=q1, answer=u'Yes.')
q2 = Question.objects.create(question=u'Wherefore?')
action_data = {ACTION_CHECKBOX_NAME: [q1.pk, q2.pk], u'action': u'delete_selected', u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/question/', action_data)
self.assertContains(response, u'would require deleting the following protected related objects')
self.assertContains(response, (u'<li>Answer: <a href="/test_admin/admin/admin_views/answer/%s/">Because.</a></li>' % a1.pk), html=True)
self.assertContains(response, (u'<li>Answer: <a href="/test_admin/admin/admin_views/answer/%s/">Yes.</a></li>' % a2.pk), html=True)
|
'Tests a custom action defined in a function'
| def test_custom_function_mail_action(self):
| action_data = {ACTION_CHECKBOX_NAME: [1], u'action': u'external_mail', u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/externalsubscriber/', action_data)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, u'Greetings from a function action')
|
'Tests a custom action defined in a function'
| def test_custom_function_action_with_redirect(self):
| action_data = {ACTION_CHECKBOX_NAME: [1], u'action': u'redirect_to', u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/externalsubscriber/', action_data)
self.assertEqual(response.status_code, 302)
|
'Test that actions which don\'t return an HttpResponse are redirected to
the same page, retaining the querystring (which may contain changelist
information).'
| def test_default_redirect(self):
| action_data = {ACTION_CHECKBOX_NAME: [1], u'action': u'external_mail', u'index': 0}
url = u'/test_admin/admin/admin_views/externalsubscriber/?o=1'
response = self.client.post(url, action_data)
self.assertRedirects(response, url)
|
'Ensure that actions are ordered as expected.
Refs #15964.'
| def test_actions_ordering(self):
| response = self.client.get(u'/test_admin/admin/admin_views/externalsubscriber/')
self.assertContains(response, u'<label>Action: <select name="action">\n<option value="" selected="selected">---------</option>\n<option value="delete_selected">Delete selected external subscribers</option>\n<option value="redirect_to">Redirect to (Awesome action)</option>\n<option value="external_mail">External mail (Another awesome action)</option>\n</select>', html=True)
|
'Tests a ModelAdmin without any action'
| def test_model_without_action(self):
| response = self.client.get(u'/test_admin/admin/admin_views/oldsubscriber/')
self.assertEqual(response.context[u'action_form'], None)
self.assertNotContains(response, u'<input type="checkbox" class="action-select"', msg_prefix=u'Found an unexpected action toggle checkboxbox in response')
self.assertNotContains(response, u'<input type="checkbox" class="action-select"')
|
'Tests that a ModelAdmin without any actions still gets jQuery included in page'
| def test_model_without_action_still_has_jquery(self):
| response = self.client.get(u'/test_admin/admin/admin_views/oldsubscriber/')
self.assertEqual(response.context[u'action_form'], None)
self.assertContains(response, u'jquery.min.js', msg_prefix=u'jQuery missing from admin pages for model with no admin actions')
|
'Tests that the checkbox column class is present in the response'
| def test_action_column_class(self):
| response = self.client.get(u'/test_admin/admin/admin_views/subscriber/')
self.assertNotEqual(response.context[u'action_form'], None)
self.assertContains(response, u'action-checkbox-column')
|
'Test that actions come from the form whose submit button was pressed (#10618).'
| def test_multiple_actions_form(self):
| action_data = {ACTION_CHECKBOX_NAME: [1], u'action': [u'external_mail', u'delete_selected'], u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/externalsubscriber/', action_data)
self.assertEqual(len(mail.outbox), 1)
self.assertEqual(mail.outbox[0].subject, u'Greetings from a function action')
|
'User should see a warning when \'Go\' is pressed and no items are selected.'
| def test_user_message_on_none_selected(self):
| action_data = {ACTION_CHECKBOX_NAME: [], u'action': u'delete_selected', u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/subscriber/', action_data)
msg = u'Items must be selected in order to perform actions on them. No items have been changed.'
self.assertContains(response, msg)
self.assertEqual(Subscriber.objects.count(), 2)
|
'User should see a warning when \'Go\' is pressed and no action is selected.'
| def test_user_message_on_no_action(self):
| action_data = {ACTION_CHECKBOX_NAME: [1, 2], u'action': u'', u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/subscriber/', action_data)
msg = u'No action selected.'
self.assertContains(response, msg)
self.assertEqual(Subscriber.objects.count(), 2)
|
'Check if the selection counter is there.'
| def test_selection_counter(self):
| response = self.client.get(u'/test_admin/admin/admin_views/subscriber/')
self.assertContains(response, u'0 of 2 selected')
|
'Actions should not be shown in popups.'
| def test_popup_actions(self):
| response = self.client.get(u'/test_admin/admin/admin_views/subscriber/')
self.assertNotEqual(response.context[u'action_form'], None)
response = self.client.get((u'/test_admin/admin/admin_views/subscriber/?%s' % IS_POPUP_VAR))
self.assertEqual(response.context[u'action_form'], None)
|
'Validate that a custom ChangeList class can be used (#9749)'
| def test_custom_changelist(self):
| post_data = {u'name': u'First Gadget'}
response = self.client.post((u'/test_admin/%s/admin_views/gadget/add/' % self.urlbit), post_data)
self.assertEqual(response.status_code, 302)
response = self.client.get((u'/test_admin/%s/admin_views/gadget/' % self.urlbit))
response = self.client.get((u'/test_admin/%s/admin_views/gadget/' % self.urlbit))
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, u'First Gadget')
|
'InlineModelAdmin broken?'
| def test(self):
| response = self.client.get(u'/test_admin/admin/admin_views/parent/add/')
self.assertEqual(response.status_code, 200)
|
'Test that inline file uploads correctly display prior data (#10002).'
| def test_inline_file_upload_edit_validation_error_post(self):
| post_data = {u'name': u'Test Gallery', u'pictures-TOTAL_FORMS': u'2', u'pictures-INITIAL_FORMS': u'1', u'pictures-MAX_NUM_FORMS': u'0', u'pictures-0-id': six.text_type(self.picture.id), u'pictures-0-gallery': six.text_type(self.gallery.id), u'pictures-0-name': u'Test Picture', u'pictures-0-image': u'', u'pictures-1-id': u'', u'pictures-1-gallery': str(self.gallery.id), u'pictures-1-name': u'Test Picture 2', u'pictures-1-image': u''}
response = self.client.post((u'/test_admin/%s/admin_views/gallery/%d/' % (self.urlbit, self.gallery.id)), post_data)
self.assertTrue((response._container[0].find(u'Currently:') > (-1)))
|
'A simple model can be saved as inlines'
| def test_simple_inline(self):
| self.post_data[u'widget_set-0-name'] = u'Widget 1'
collector_url = (u'/test_admin/admin/admin_views/collector/%d/' % self.collector.pk)
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Widget.objects.count(), 1)
self.assertEqual(Widget.objects.all()[0].name, u'Widget 1')
widget_id = Widget.objects.all()[0].id
response = self.client.get(collector_url)
self.assertContains(response, u'name="widget_set-0-id"')
self.post_data[u'widget_set-INITIAL_FORMS'] = u'1'
self.post_data[u'widget_set-0-id'] = str(widget_id)
self.post_data[u'widget_set-0-name'] = u'Widget 1'
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Widget.objects.count(), 1)
self.assertEqual(Widget.objects.all()[0].name, u'Widget 1')
self.post_data[u'widget_set-INITIAL_FORMS'] = u'1'
self.post_data[u'widget_set-0-id'] = str(widget_id)
self.post_data[u'widget_set-0-name'] = u'Widget 1 Updated'
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Widget.objects.count(), 1)
self.assertEqual(Widget.objects.all()[0].name, u'Widget 1 Updated')
|
'A model with an explicit autofield primary key can be saved as inlines. Regression for #8093'
| def test_explicit_autofield_inline(self):
| self.post_data[u'grommet_set-0-name'] = u'Grommet 1'
collector_url = (u'/test_admin/admin/admin_views/collector/%d/' % self.collector.pk)
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Grommet.objects.count(), 1)
self.assertEqual(Grommet.objects.all()[0].name, u'Grommet 1')
response = self.client.get(collector_url)
self.assertContains(response, u'name="grommet_set-0-code"')
self.post_data[u'grommet_set-INITIAL_FORMS'] = u'1'
self.post_data[u'grommet_set-0-code'] = str(Grommet.objects.all()[0].code)
self.post_data[u'grommet_set-0-name'] = u'Grommet 1'
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Grommet.objects.count(), 1)
self.assertEqual(Grommet.objects.all()[0].name, u'Grommet 1')
self.post_data[u'grommet_set-INITIAL_FORMS'] = u'1'
self.post_data[u'grommet_set-0-code'] = str(Grommet.objects.all()[0].code)
self.post_data[u'grommet_set-0-name'] = u'Grommet 1 Updated'
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Grommet.objects.count(), 1)
self.assertEqual(Grommet.objects.all()[0].name, u'Grommet 1 Updated')
|
'A model with a character PK can be saved as inlines. Regression for #10992'
| def test_char_pk_inline(self):
| self.post_data[u'doohickey_set-0-code'] = u'DH1'
self.post_data[u'doohickey_set-0-name'] = u'Doohickey 1'
collector_url = (u'/test_admin/admin/admin_views/collector/%d/' % self.collector.pk)
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(DooHickey.objects.count(), 1)
self.assertEqual(DooHickey.objects.all()[0].name, u'Doohickey 1')
response = self.client.get(collector_url)
self.assertContains(response, u'name="doohickey_set-0-code"')
self.post_data[u'doohickey_set-INITIAL_FORMS'] = u'1'
self.post_data[u'doohickey_set-0-code'] = u'DH1'
self.post_data[u'doohickey_set-0-name'] = u'Doohickey 1'
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(DooHickey.objects.count(), 1)
self.assertEqual(DooHickey.objects.all()[0].name, u'Doohickey 1')
self.post_data[u'doohickey_set-INITIAL_FORMS'] = u'1'
self.post_data[u'doohickey_set-0-code'] = u'DH1'
self.post_data[u'doohickey_set-0-name'] = u'Doohickey 1 Updated'
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(DooHickey.objects.count(), 1)
self.assertEqual(DooHickey.objects.all()[0].name, u'Doohickey 1 Updated')
|
'A model with an integer PK can be saved as inlines. Regression for #10992'
| def test_integer_pk_inline(self):
| self.post_data[u'whatsit_set-0-index'] = u'42'
self.post_data[u'whatsit_set-0-name'] = u'Whatsit 1'
response = self.client.post(u'/test_admin/admin/admin_views/collector/1/', self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Whatsit.objects.count(), 1)
self.assertEqual(Whatsit.objects.all()[0].name, u'Whatsit 1')
response = self.client.get(u'/test_admin/admin/admin_views/collector/1/')
self.assertContains(response, u'name="whatsit_set-0-index"')
self.post_data[u'whatsit_set-INITIAL_FORMS'] = u'1'
self.post_data[u'whatsit_set-0-index'] = u'42'
self.post_data[u'whatsit_set-0-name'] = u'Whatsit 1'
response = self.client.post(u'/test_admin/admin/admin_views/collector/1/', self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Whatsit.objects.count(), 1)
self.assertEqual(Whatsit.objects.all()[0].name, u'Whatsit 1')
self.post_data[u'whatsit_set-INITIAL_FORMS'] = u'1'
self.post_data[u'whatsit_set-0-index'] = u'42'
self.post_data[u'whatsit_set-0-name'] = u'Whatsit 1 Updated'
response = self.client.post(u'/test_admin/admin/admin_views/collector/1/', self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(Whatsit.objects.count(), 1)
self.assertEqual(Whatsit.objects.all()[0].name, u'Whatsit 1 Updated')
|
'An inherited model can be saved as inlines. Regression for #11042'
| def test_inherited_inline(self):
| self.post_data[u'fancydoodad_set-0-name'] = u'Fancy Doodad 1'
collector_url = (u'/test_admin/admin/admin_views/collector/%d/' % self.collector.pk)
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(FancyDoodad.objects.count(), 1)
self.assertEqual(FancyDoodad.objects.all()[0].name, u'Fancy Doodad 1')
doodad_pk = FancyDoodad.objects.all()[0].pk
response = self.client.get(collector_url)
self.assertContains(response, u'name="fancydoodad_set-0-doodad_ptr"')
self.post_data[u'fancydoodad_set-INITIAL_FORMS'] = u'1'
self.post_data[u'fancydoodad_set-0-doodad_ptr'] = str(doodad_pk)
self.post_data[u'fancydoodad_set-0-name'] = u'Fancy Doodad 1'
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(FancyDoodad.objects.count(), 1)
self.assertEqual(FancyDoodad.objects.all()[0].name, u'Fancy Doodad 1')
self.post_data[u'fancydoodad_set-INITIAL_FORMS'] = u'1'
self.post_data[u'fancydoodad_set-0-doodad_ptr'] = str(doodad_pk)
self.post_data[u'fancydoodad_set-0-name'] = u'Fancy Doodad 1 Updated'
response = self.client.post(collector_url, self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(FancyDoodad.objects.count(), 1)
self.assertEqual(FancyDoodad.objects.all()[0].name, u'Fancy Doodad 1 Updated')
|
'Check that an inline with an editable ordering fields is
updated correctly. Regression for #10922'
| def test_ordered_inline(self):
| Category.objects.create(id=1, order=1, collector=self.collector)
Category.objects.create(id=2, order=2, collector=self.collector)
Category.objects.create(id=3, order=0, collector=self.collector)
Category.objects.create(id=4, order=0, collector=self.collector)
self.post_data.update({u'name': u'Frederick Clegg', u'category_set-TOTAL_FORMS': u'7', u'category_set-INITIAL_FORMS': u'4', u'category_set-MAX_NUM_FORMS': u'0', u'category_set-0-order': u'14', u'category_set-0-id': u'1', u'category_set-0-collector': u'1', u'category_set-1-order': u'13', u'category_set-1-id': u'2', u'category_set-1-collector': u'1', u'category_set-2-order': u'1', u'category_set-2-id': u'3', u'category_set-2-collector': u'1', u'category_set-3-order': u'0', u'category_set-3-id': u'4', u'category_set-3-collector': u'1', u'category_set-4-order': u'', u'category_set-4-id': u'', u'category_set-4-collector': u'1', u'category_set-5-order': u'', u'category_set-5-id': u'', u'category_set-5-collector': u'1', u'category_set-6-order': u'', u'category_set-6-id': u'', u'category_set-6-collector': u'1'})
response = self.client.post(u'/test_admin/admin/admin_views/collector/1/', self.post_data)
self.assertEqual(response.status_code, 302)
self.assertEqual(self.collector.category_set.count(), 4)
self.assertEqual(Category.objects.get(id=1).order, 14)
self.assertEqual(Category.objects.get(id=2).order, 13)
self.assertEqual(Category.objects.get(id=3).order, 1)
self.assertEqual(Category.objects.get(id=4).order, 0)
|
'Check the never-cache status of the main index'
| def testAdminIndex(self):
| response = self.client.get(u'/test_admin/admin/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of an application index'
| def testAppIndex(self):
| response = self.client.get(u'/test_admin/admin/admin_views/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of a model index'
| def testModelIndex(self):
| response = self.client.get(u'/test_admin/admin/admin_views/fabric/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of a model add page'
| def testModelAdd(self):
| response = self.client.get(u'/test_admin/admin/admin_views/fabric/add/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of a model edit page'
| def testModelView(self):
| response = self.client.get(u'/test_admin/admin/admin_views/section/1/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of a model history page'
| def testModelHistory(self):
| response = self.client.get(u'/test_admin/admin/admin_views/section/1/history/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of a model delete page'
| def testModelDelete(self):
| response = self.client.get(u'/test_admin/admin/admin_views/section/1/delete/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of login views'
| def testLogin(self):
| self.client.logout()
response = self.client.get(u'/test_admin/admin/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of logout view'
| def testLogout(self):
| response = self.client.get(u'/test_admin/admin/logout/')
self.assertEqual(get_max_age(response), 0)
|
'Check the never-cache status of the password change view'
| def testPasswordChange(self):
| self.client.logout()
response = self.client.get(u'/test_admin/password_change/')
self.assertEqual(get_max_age(response), None)
|
'Check the never-cache status of the password change done view'
| def testPasswordChangeDone(self):
| response = self.client.get(u'/test_admin/admin/password_change/done/')
self.assertEqual(get_max_age(response), None)
|
'Check the never-cache status of the JavaScript i18n view'
| def testJsi18n(self):
| response = self.client.get(u'/test_admin/admin/jsi18n/')
self.assertEqual(get_max_age(response), None)
|
'Regression test for #15938: if USE_THOUSAND_SEPARATOR is set, make sure
that maxLength (in the JavaScript) is rendered without separators.'
| @override_settings(USE_THOUSAND_SEPARATOR=True, USE_L10N=True)
def test_prepopulated_maxlength_localized(self):
| response = self.client.get(u'/test_admin/admin/admin_views/prepopulatedpostlargeslug/add/')
self.assertContains(response, u'maxLength: 1000')
|
'Ensure that the JavaScript-automated prepopulated fields work with the
main form and with stacked and tabular inlines.
Refs #13068, #9264, #9983, #9784.'
| def test_basic(self):
| from selenium.common.exceptions import TimeoutException
self.admin_login(username=u'super', password=u'secret', login_url=u'/test_admin/admin/')
self.selenium.get((u'%s%s' % (self.live_server_url, u'/test_admin/admin/admin_views/mainprepopulated/add/')))
self.selenium.find_element_by_css_selector(u'#id_pubdate').send_keys(u'2012-02-18')
self.get_select_option(u'#id_status', u'option two').click()
self.selenium.find_element_by_css_selector(u'#id_name').send_keys(u" this is the mAin n\xc0M\xeb and it's aw\u03b5\u0161ome")
slug1 = self.selenium.find_element_by_css_selector(u'#id_slug1').get_attribute(u'value')
slug2 = self.selenium.find_element_by_css_selector(u'#id_slug2').get_attribute(u'value')
self.assertEqual(slug1, u'main-name-and-its-awesome-2012-02-18')
self.assertEqual(slug2, u'option-two-main-name-and-its-awesome')
self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-0-pubdate').send_keys(u'2011-12-17')
self.get_select_option(u'#id_relatedprepopulated_set-0-status', u'option one').click()
self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-0-name').send_keys(u' here is a s\u0164\u0101\xc7ke\xf0 inline ! ')
slug1 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-0-slug1').get_attribute(u'value')
slug2 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-0-slug2').get_attribute(u'value')
self.assertEqual(slug1, u'here-stacked-inline-2011-12-17')
self.assertEqual(slug2, u'option-one-here-stacked-inline')
self.selenium.find_elements_by_link_text(u'Add another Related Prepopulated')[0].click()
self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-1-pubdate').send_keys(u'1999-01-25')
self.get_select_option(u'#id_relatedprepopulated_set-1-status', u'option two').click()
self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-1-name').send_keys(u' now you haVe an\xf6ther s\u0164\u0101\xc7ke\xf0 inline with a very ... loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooog text... ')
slug1 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-1-slug1').get_attribute(u'value')
slug2 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-1-slug2').get_attribute(u'value')
self.assertEqual(slug1, u'now-you-have-another-stacked-inline-very-loooooooo')
self.assertEqual(slug2, u'option-two-now-you-have-another-stacked-inline-very-looooooo')
self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-0-pubdate').send_keys(u'1234-12-07')
self.get_select_option(u'#id_relatedprepopulated_set-2-0-status', u'option two').click()
self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-0-name').send_keys(u'And now, with a t\xc3b\u0171la\u0158 inline !!!')
slug1 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-0-slug1').get_attribute(u'value')
slug2 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-0-slug2').get_attribute(u'value')
self.assertEqual(slug1, u'and-now-tabular-inline-1234-12-07')
self.assertEqual(slug2, u'option-two-and-now-tabular-inline')
self.selenium.find_elements_by_link_text(u'Add another Related Prepopulated')[1].click()
self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-1-pubdate').send_keys(u'1981-08-22')
self.get_select_option(u'#id_relatedprepopulated_set-2-1-status', u'option one').click()
self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-1-name').send_keys(u'a t\xc3b\u0171la\u0158 inline with ignored ;"&*^\\%$#@-/`~ characters')
slug1 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-1-slug1').get_attribute(u'value')
slug2 = self.selenium.find_element_by_css_selector(u'#id_relatedprepopulated_set-2-1-slug2').get_attribute(u'value')
self.assertEqual(slug1, u'tabular-inline-ignored-characters-1981-08-22')
self.assertEqual(slug2, u'option-one-tabular-inline-ignored-characters')
self.selenium.find_element_by_xpath(u'//input[@value="Save"]').click()
self.wait_page_loaded()
self.assertEqual(MainPrepopulated.objects.all().count(), 1)
MainPrepopulated.objects.get(name=u" this is the mAin n\xc0M\xeb and it's aw\u03b5\u0161ome", pubdate=u'2012-02-18', status=u'option two', slug1=u'main-name-and-its-awesome-2012-02-18', slug2=u'option-two-main-name-and-its-awesome')
self.assertEqual(RelatedPrepopulated.objects.all().count(), 4)
RelatedPrepopulated.objects.get(name=u' here is a s\u0164\u0101\xc7ke\xf0 inline ! ', pubdate=u'2011-12-17', status=u'option one', slug1=u'here-stacked-inline-2011-12-17', slug2=u'option-one-here-stacked-inline')
RelatedPrepopulated.objects.get(name=u' now you haVe an\xf6ther s\u0164\u0101\xc7ke\xf0 inline with a very ... loooooooooooooooooo', pubdate=u'1999-01-25', status=u'option two', slug1=u'now-you-have-another-stacked-inline-very-loooooooo', slug2=u'option-two-now-you-have-another-stacked-inline-very-looooooo')
RelatedPrepopulated.objects.get(name=u'And now, with a t\xc3b\u0171la\u0158 inline !!!', pubdate=u'1234-12-07', status=u'option two', slug1=u'and-now-tabular-inline-1234-12-07', slug2=u'option-two-and-now-tabular-inline')
RelatedPrepopulated.objects.get(name=u'a t\xc3b\u0171la\u0158 inline with ignored ;"&*^\\%$#@-/`~ characters', pubdate=u'1981-08-22', status=u'option one', slug1=u'tabular-inline-ignored-characters-1981-08-22', slug2=u'option-one-tabular-inline-ignored-characters')
|
'Regression test for #13004'
| def test_readonly_manytomany(self):
| response = self.client.get(u'/test_admin/admin/admin_views/pizza/add/')
self.assertEqual(response.status_code, 200)
|
'Regression test for #17911.'
| def test_change_form_renders_correct_null_choice_value(self):
| choice = Choice.objects.create(choice=None)
response = self.client.get((u'/test_admin/admin/admin_views/choice/%s/' % choice.pk))
self.assertContains(response, u'<p>No opinion</p>', html=True)
self.assertNotContains(response, u'<p>(None)</p>')
|
'Regression test for 14880'
| def test_limit_choices_to(self):
| actor = Actor.objects.create(name=u'Palin', age=27)
inquisition1 = Inquisition.objects.create(expected=True, leader=actor, country=u'England')
inquisition2 = Inquisition.objects.create(expected=False, leader=actor, country=u'Spain')
response = self.client.get(u'/test_admin/admin/admin_views/sketch/add/')
m = re.search('<a href="([^"]*)"[^>]* id="lookup_id_inquisition"', response.content)
self.assertTrue(m)
popup_url = m.groups()[0].decode().replace(u'&', u'&')
popup_url = urljoin(response.request[u'PATH_INFO'], popup_url)
response2 = self.client.get(popup_url)
self.assertContains(response2, u'Spain')
self.assertNotContains(response2, u'England')
|
'Quick user addition in a FK popup shouldn\'t invoke view for further user customization'
| def test_user_fk_popup(self):
| response = self.client.get(u'/test_admin/admin/admin_views/album/add/')
self.assertEqual(response.status_code, 200)
self.assertContains(response, u'/test_admin/admin/auth/user/add')
self.assertContains(response, u'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"')
response = self.client.get(u'/test_admin/admin/auth/user/add/?_popup=1')
self.assertEqual(response.status_code, 200)
self.assertNotContains(response, u'name="_continue"')
self.assertNotContains(response, u'name="_addanother"')
data = {u'username': u'newuser', u'password1': u'newpassword', u'password2': u'newpassword', u'_popup': u'1', u'_save': u'1'}
response = self.client.post(u'/test_admin/admin/auth/user/add/?_popup=1', data, follow=True)
self.assertEqual(response.status_code, 200)
self.assertContains(response, u'dismissAddAnotherPopup')
|
'Ensure that the year is not localized with
USE_THOUSAND_SEPARATOR. Refs #15234.'
| def assert_non_localized_year(self, response, year):
| self.assertNotContains(response, formats.number_format(year))
|
'Ensure that no date hierarchy links display with empty changelist.'
| def test_empty(self):
| response = self.client.get(reverse(u'admin:admin_views_podcast_changelist'))
self.assertNotContains(response, u'release_date__year=')
self.assertNotContains(response, u'release_date__month=')
self.assertNotContains(response, u'release_date__day=')
|
'Ensure that single day-level date hierarchy appears for single object.'
| def test_single(self):
| DATE = datetime.date(2000, 6, 30)
Podcast.objects.create(release_date=DATE)
url = reverse(u'admin:admin_views_podcast_changelist')
response = self.client.get(url)
self.assert_contains_day_link(response, DATE)
self.assert_non_localized_year(response, 2000)
|
'Ensure that day-level links appear for changelist within single month.'
| def test_within_month(self):
| DATES = (datetime.date(2000, 6, 30), datetime.date(2000, 6, 15), datetime.date(2000, 6, 3))
for date in DATES:
Podcast.objects.create(release_date=date)
url = reverse(u'admin:admin_views_podcast_changelist')
response = self.client.get(url)
for date in DATES:
self.assert_contains_day_link(response, date)
self.assert_non_localized_year(response, 2000)
|
'Ensure that month-level links appear for changelist within single year.'
| def test_within_year(self):
| DATES = (datetime.date(2000, 1, 30), datetime.date(2000, 3, 15), datetime.date(2000, 5, 3))
for date in DATES:
Podcast.objects.create(release_date=date)
url = reverse(u'admin:admin_views_podcast_changelist')
response = self.client.get(url)
self.assertNotContains(response, u'release_date__day=')
for date in DATES:
self.assert_contains_month_link(response, date)
self.assert_non_localized_year(response, 2000)
|
'Ensure that year-level links appear for year-spanning changelist.'
| def test_multiple_years(self):
| DATES = (datetime.date(2001, 1, 30), datetime.date(2003, 3, 15), datetime.date(2005, 5, 3))
for date in DATES:
Podcast.objects.create(release_date=date)
response = self.client.get(reverse(u'admin:admin_views_podcast_changelist'))
self.assertNotContains(response, u'release_date__day=')
self.assertNotContains(response, u'release_date__month=')
for date in DATES:
self.assert_contains_year_link(response, date)
for date in DATES:
url = (u'%s?release_date__year=%d' % (reverse(u'admin:admin_views_podcast_changelist'), date.year))
response = self.client.get(url)
self.assert_contains_month_link(response, date)
self.assert_non_localized_year(response, 2000)
self.assert_non_localized_year(response, 2003)
self.assert_non_localized_year(response, 2005)
url = (u'%s?release_date__year=%d&release_date__month=%d' % (reverse(u'admin:admin_views_podcast_changelist'), date.year, date.month))
response = self.client.get(url)
self.assert_contains_day_link(response, date)
self.assert_non_localized_year(response, 2000)
self.assert_non_localized_year(response, 2003)
self.assert_non_localized_year(response, 2005)
|
'Helper that sends a post to the dummy test methods and asserts that a
message with the level has appeared in the response.'
| def send_message(self, level):
| action_data = {ACTION_CHECKBOX_NAME: [1], u'action': (u'message_%s' % level), u'index': 0}
response = self.client.post(u'/test_admin/admin/admin_views/usermessenger/', action_data, follow=True)
self.assertContains(response, (u'<li class="%s">Test %s</li>' % (level, level)), html=True)
|
'Test that extra_context works'
| def changelist_view(self, request):
| return super(ArticleAdmin, self).changelist_view(request, extra_context={u'extra_var': u'Hello!'})
|
'Only allow changing objects with even id number'
| def has_change_permission(self, request, obj=None):
| return (request.user.is_staff and (obj is not None) and ((obj.id % 2) == 0))
|
'Test that extra_context works'
| def changelist_view(self, request):
| return super(CustomArticleAdmin, self).changelist_view(request, extra_context={u'extra_var': u'Hello!'})
|
'Test that GenericRelations on inherited classes use the correct content
type.'
| def test_inherited_models_content_type(self):
| p = Place.objects.create(name='South Park')
r = Restaurant.objects.create(name="Chubby's")
l1 = Link.objects.create(content_object=p)
l2 = Link.objects.create(content_object=r)
self.assertEqual(list(p.links.all()), [l1])
self.assertEqual(list(r.links.all()), [l2])
|
'Test that the correct column name is used for the primary key on the
originating model of a query. See #12664.'
| def test_reverse_relation_pk(self):
| p = Person.objects.create(account=23, name='Chef')
a = Address.objects.create(street='123 Anywhere Place', city='Conifer', state='CO', zipcode='80433', content_object=p)
qs = Person.objects.filter(addresses__zipcode='80433')
self.assertEqual(1, qs.count())
self.assertEqual('Chef', qs[0].name)
|
'Tests that SQL query parameters for generic relations are properly
grouped when OR is used.
Test for bug http://code.djangoproject.com/ticket/11535
In this bug the first query (below) works while the second, with the
query parameters the same but in reverse order, does not.
The issue is that the generic relation conditions do not get properly
grouped in parentheses.'
| def test_q_object_or(self):
| note_contact = Contact.objects.create()
org_contact = Contact.objects.create()
note = Note.objects.create(note='note', content_object=note_contact)
org = Organization.objects.create(name='org name')
org.contacts.add(org_contact)
qs = Contact.objects.filter((Q(notes__note__icontains='other note') | Q(organizations__name__icontains='org name')))
self.assertTrue((org_contact in qs))
qs = Contact.objects.filter((Q(organizations__name__icontains='org name') | Q(notes__note__icontains='other note')))
self.assertTrue((org_contact in qs))
|
'Helper method that instantiates a Paginator object from the passed
params and then checks that its attributes match the passed output.'
| def check_paginator(self, params, output):
| (count, num_pages, page_range) = output
paginator = Paginator(*params)
self.check_attribute(u'count', paginator, count, params)
self.check_attribute(u'num_pages', paginator, num_pages, params)
self.check_attribute(u'page_range', paginator, page_range, params, coerce=list)
|
'Helper method that checks a single attribute and gives a nice error
message upon test failure.'
| def check_attribute(self, name, paginator, expected, params, coerce=None):
| got = getattr(paginator, name)
if (coerce is not None):
got = coerce(got)
self.assertEqual(expected, got, (u"For '%s', expected %s but got %s. Paginator parameters were: %s" % (name, expected, got, params)))
|
'Tests the paginator attributes using varying inputs.'
| def test_paginator(self):
| nine = [1, 2, 3, 4, 5, 6, 7, 8, 9]
ten = (nine + [10])
eleven = (ten + [11])
tests = (((ten, 4, 0, False), (10, 3, [1, 2, 3])), ((ten, 4, 1, False), (10, 3, [1, 2, 3])), ((ten, 4, 2, False), (10, 2, [1, 2])), ((ten, 4, 5, False), (10, 2, [1, 2])), ((ten, 4, 6, False), (10, 1, [1])), ((ten, 4, 0, True), (10, 3, [1, 2, 3])), ((ten, 4, 1, True), (10, 3, [1, 2, 3])), ((ten, 4, 2, True), (10, 2, [1, 2])), ((ten, 4, 5, True), (10, 2, [1, 2])), ((ten, 4, 6, True), (10, 1, [1])), (([1], 4, 0, False), (1, 1, [1])), (([1], 4, 1, False), (1, 1, [1])), (([1], 4, 2, False), (1, 1, [1])), (([1], 4, 0, True), (1, 1, [1])), (([1], 4, 1, True), (1, 1, [1])), (([1], 4, 2, True), (1, 1, [1])), (([], 4, 0, False), (0, 0, [])), (([], 4, 1, False), (0, 0, [])), (([], 4, 2, False), (0, 0, [])), (([], 4, 0, True), (0, 1, [1])), (([], 4, 1, True), (0, 1, [1])), (([], 4, 2, True), (0, 1, [1])), (([], 1, 0, True), (0, 1, [1])), (([], 1, 0, False), (0, 0, [])), (([1], 2, 0, True), (1, 1, [1])), ((nine, 10, 0, True), (9, 1, [1])), (([1], 1, 0, True), (1, 1, [1])), (([1, 2], 2, 0, True), (2, 1, [1])), ((ten, 10, 0, True), (10, 1, [1])), (([1, 2], 1, 0, True), (2, 2, [1, 2])), (([1, 2, 3], 2, 0, True), (3, 2, [1, 2])), ((eleven, 10, 0, True), (11, 2, [1, 2])), (([1, 2], 1, 1, True), (2, 1, [1])), (([1, 2, 3], 2, 1, True), (3, 1, [1])), ((eleven, 10, 1, True), (11, 1, [1])), ((ten, u'4', 1, False), (10, 3, [1, 2, 3])), ((ten, u'4', 1, False), (10, 3, [1, 2, 3])), ((ten, 4, u'1', False), (10, 3, [1, 2, 3])), ((ten, 4, u'1', False), (10, 3, [1, 2, 3])))
for (params, output) in tests:
self.check_paginator(params, output)
|
'Tests that invalid page numbers result in the correct exception being
raised.'
| def test_invalid_page_number(self):
| paginator = Paginator([1, 2, 3], 2)
self.assertRaises(InvalidPage, paginator.page, 3)
self.assertRaises(PageNotAnInteger, paginator.validate_number, None)
self.assertRaises(PageNotAnInteger, paginator.validate_number, u'x')
paginator = Paginator([], 2)
self.assertEqual(paginator.validate_number(1), 1)
|
'Helper method that instantiates a Paginator object from the passed
params and then checks that the start and end indexes of the passed
page_num match those given as a 2-tuple in indexes.'
| def check_indexes(self, params, page_num, indexes):
| paginator = Paginator(*params)
if (page_num == u'first'):
page_num = 1
elif (page_num == u'last'):
page_num = paginator.num_pages
page = paginator.page(page_num)
(start, end) = indexes
msg = u'For %s of page %s, expected %s but got %s. Paginator parameters were: %s'
self.assertEqual(start, page.start_index(), (msg % (u'start index', page_num, start, page.start_index(), params)))
self.assertEqual(end, page.end_index(), (msg % (u'end index', page_num, end, page.end_index(), params)))
|
'Tests that paginator pages have the correct start and end indexes.'
| def test_page_indexes(self):
| ten = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
tests = (((ten, 1, 0, True), (1, 1), (10, 10)), ((ten, 2, 0, True), (1, 2), (9, 10)), ((ten, 3, 0, True), (1, 3), (10, 10)), ((ten, 5, 0, True), (1, 5), (6, 10)), ((ten, 1, 1, True), (1, 1), (9, 10)), ((ten, 1, 2, True), (1, 1), (8, 10)), ((ten, 3, 1, True), (1, 3), (7, 10)), ((ten, 3, 2, True), (1, 3), (7, 10)), ((ten, 3, 4, True), (1, 3), (4, 10)), ((ten, 5, 1, True), (1, 5), (6, 10)), ((ten, 5, 2, True), (1, 5), (6, 10)), ((ten, 5, 5, True), (1, 10), (1, 10)), (([1], 4, 0, False), (1, 1), (1, 1)), (([1], 4, 1, False), (1, 1), (1, 1)), (([1], 4, 2, False), (1, 1), (1, 1)), (([1], 4, 0, True), (1, 1), (1, 1)), (([1], 4, 1, True), (1, 1), (1, 1)), (([1], 4, 2, True), (1, 1), (1, 1)), (([], 4, 0, True), (0, 0), (0, 0)), (([], 4, 1, True), (0, 0), (0, 0)), (([], 4, 2, True), (0, 0), (0, 0)))
for (params, first, last) in tests:
self.check_indexes(params, u'first', first)
self.check_indexes(params, u'last', last)
self.assertRaises(EmptyPage, self.check_indexes, ([], 4, 0, False), 1, None)
self.assertRaises(EmptyPage, self.check_indexes, ([], 4, 1, False), 1, None)
self.assertRaises(EmptyPage, self.check_indexes, ([], 4, 2, False), 1, None)
|
'Tests that a paginator page acts like a standard sequence.'
| def test_page_sequence(self):
| eleven = u'abcdefghijk'
page2 = Paginator(eleven, per_page=5, orphans=1).page(2)
self.assertEqual(len(page2), 6)
self.assertTrue((u'k' in page2))
self.assertFalse((u'a' in page2))
self.assertEqual(u''.join(page2), u'fghijk')
self.assertEqual(u''.join(reversed(page2)), u'kjihgf')
|
'Tests proper behaviour of a paginator page __getitem__ (queryset
evaluation, slicing, exception raised).'
| def test_page_getitem(self):
| paginator = Paginator(Article.objects.all(), 5)
p = paginator.page(1)
self.assertIsNone(p.object_list._result_cache)
self.assertRaises(TypeError, (lambda : p[u'has_previous']))
self.assertIsNone(p.object_list._result_cache)
self.assertEqual(p[0], Article.objects.get(headline=u'Article 1'))
self.assertQuerysetEqual(p[slice(2)], [u'<Article: Article 1>', u'<Article: Article 2>'])
|
'Test the "in" operator for safe references (cmp)'
| def testIn(self):
| for t in self.ts[:50]:
self.assertTrue((safeRef(t.x) in self.ss))
|
'Test that the references are valid (return instance methods)'
| def testValid(self):
| for s in self.ss:
self.assertTrue(s())
|
'Test that creation short-circuits to reuse existing references'
| def testShortCircuit(self):
| sd = {}
for s in self.ss:
sd[s] = 1
for t in self.ts:
if hasattr(t, 'x'):
self.assertTrue((safeRef(t.x) in sd))
else:
self.assertTrue((safeRef(t) in sd))
|
'Test that the reference object\'s representation works
XXX Doesn\'t currently check the results, just that no error
is raised'
| def testRepresentation(self):
| repr(self.ss[(-1)])
|
'Dumb utility mechanism to increment deletion counter'
| def _closure(self, ref):
| self.closureCount += 1
|
'Assert that everything has been cleaned up automatically'
| def _testIsClean(self, signal):
| self.assertEqual(signal.receivers, [])
signal.receivers = []
|
'Test the sendRobust function'
| def testRobust(self):
| def fails(val, **kwargs):
raise ValueError('this')
a_signal.connect(fails)
result = a_signal.send_robust(sender=self, val='test')
err = result[0][1]
self.assertTrue(isinstance(err, ValueError))
self.assertEqual(err.args, ('this',))
a_signal.disconnect(fails)
self._testIsClean(a_signal)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.