desc
stringlengths
3
26.7k
decl
stringlengths
11
7.89k
bodies
stringlengths
8
553k
'The link from the changelist referring to the changeform of the object should be quoted'
def test_changelist_to_changeform_link(self):
response = self.client.get('/test_admin/admin/admin_views/modelwithstringprimarykey/') should_contain = ('<th><a href="%s/">%s</a></th></tr>' % (quote(self.pk), 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('/test_admin/admin/') should_contain = ('<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>' % (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('/test_admin/admin/') should_contain = ('<a href="admin_views/modelwithstringprimarykey/%s/">%s</a>' % (quote(self.pk), escape(self.pk))) self.assertContains(response, should_contain) should_contain = 'Model with string primary key' self.assertContains(respo...
'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(('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/delete/' % quote(self.pk))) should_contain = ('/%s/">%s</a>' % (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(id='i have something to add') add_model.save() response = self.client.get(('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(add_model.pk))) should_contain = '<h1>Change model with string primary key</h1>' self.asse...
'A model with a primary key that ends with delete should be visible'
def test_url_conflicts_with_delete(self):
delete_model = ModelWithStringPrimaryKey(id='delete') delete_model.save() response = self.client.get(('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(delete_model.pk))) should_contain = '<h1>Change model with string primary key</h1>' self.assertContains(response,...
'A model with a primary key that ends with history should be visible'
def test_url_conflicts_with_history(self):
history_model = ModelWithStringPrimaryKey(id='history') history_model.save() response = self.client.get(('/test_admin/admin/admin_views/modelwithstringprimarykey/%s/' % quote(history_model.pk))) should_contain = '<h1>Change model with string primary key</h1>' self.assertContains(respo...
'Ensure that we see the login form'
def test_secure_view_shows_login_if_not_logged_in(self):
response = self.client.get('/test_admin/admin/secure-view/') self.assertTemplateUsed(response, '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):
request = self.client.get('/test_admin/admin/secure-view/') self.assertEqual(request.status_code, 200) login = self.client.post('/test_admin/admin/secure-view/', self.super_login) self.assertRedirects(login, '/test_admin/admin/secure-view/') self.assertFalse(login.context) self.client.get('/test...
'A test to ensure that POST on edit_view handles non-ascii characters.'
def testUnicodeEdit(self):
post_data = {'name': u'Test l\xe6rdommer', 'chapter_set-TOTAL_FORMS': u'6', 'chapter_set-INITIAL_FORMS': u'3', 'chapter_set-MAX_NUM_FORMS': u'0', 'chapter_set-0-id': u'1', 'chapter_set-0-title': u'Norske bostaver \xe6\xf8\xe5 skaper problemer', 'chapter_set-0-content': u'&lt;p&gt;Sv\xe6rt frustrer...
'Ensure that the delete_view handles non-ascii characters'
def testUnicodeDelete(self):
delete_dict = {'post': 'yes'} response = self.client.get('/test_admin/admin/admin_views/book/1/delete/') self.assertEqual(response.status_code, 200) response = self.client.post('/test_admin/admin/admin_views/book/1/delete/', delete_dict) self.assertRedirects(response, '/test_admin/admin/admin_views/...
'Check that a search that mentions sibling models'
def test_search_on_sibling_models(self):
response = self.client.get('/test_admin/admin/admin_views/recommendation/?q=bar') self.assertContains(response, '\n1 recommendation\n')
'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('/test_admin/admin/admin_views/persona/add/') names = name_re.findall(response.content) self.assertEqual(len(names), len(set(names))) post_data = {'name': u'Test Nam...
'Tests a custom action defined in a ModelAdmin method'
def test_model_admin_custom_action(self):
action_data = {ACTION_CHECKBOX_NAME: [1], 'action': 'mail_admin', 'index': 0} response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].subject, '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], 'action': 'delete_selected', 'index': 0} delete_confirmation_data = {ACTION_CHECKBOX_NAME: [1, 2], 'action': 'delete_selected', 'post': 'yes'} confirmation = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) self.assertContains(confir...
'Tests a custom action defined in a function'
def test_custom_function_mail_action(self):
action_data = {ACTION_CHECKBOX_NAME: [1], 'action': 'external_mail', 'index': 0} response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data) self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].subject, '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], 'action': 'redirect_to', 'index': 0} response = self.client.post('/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], 'action': 'external_mail', 'index': 0} url = '/test_admin/admin/admin_views/externalsubscriber/?ot=asc&o=1' response = self.client.post(url, action_data) self.assertRedirects(response, url)
'Tests a ModelAdmin without any action'
def test_model_without_action(self):
response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/') self.assertEquals(response.context['action_form'], None) self.assert_(('<input type="checkbox" class="action-select"' not in response.content), 'Found an unexpected action toggle checkboxbox in response') ...
'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('/test_admin/admin/admin_views/oldsubscriber/') self.assertEquals(response.context['action_form'], None) self.assert_(('jquery.min.js' in response.content), '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('/test_admin/admin/admin_views/subscriber/') self.assertNotEqual(response.context['action_form'], None) self.assert_(('action-checkbox-column' in response.content), 'Expected an action-checkbox-column in response')
'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], 'action': ['external_mail', 'delete_selected'], 'index': 0} response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data) self.assertEquals(len(mail.outbox), 1) self.assertEquals(mail.outbox[0].subject, 'Greetings from a ...
'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: [], 'action': 'delete_selected', 'index': 0} response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) msg = 'Items must be selected in order to perform actions on them. No items have been changed.'...
'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], 'action': '', 'index': 0} response = self.client.post('/test_admin/admin/admin_views/subscriber/', action_data) msg = '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('/test_admin/admin/admin_views/subscriber/') self.assertContains(response, '0 of 2 selected')
'Validate that a custom ChangeList class can be used (#9749)'
def test_custom_changelist(self):
post_data = {'name': u'First Gadget'} response = self.client.post(('/test_admin/%s/admin_views/gadget/add/' % self.urlbit), post_data) self.assertEqual(response.status_code, 302) response = self.client.get(('/test_admin/%s/admin_views/gadget/' % self.urlbit)) response = self.client.get(('/test_ad...
'InlineModelAdmin broken?'
def test(self):
response = self.client.get('/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 = {'name': u'Test Gallery', 'pictures-TOTAL_FORMS': u'2', 'pictures-INITIAL_FORMS': u'1', 'pictures-MAX_NUM_FORMS': u'0', 'pictures-0-id': u'1', 'pictures-0-gallery': u'1', 'pictures-0-name': 'Test Picture', 'pictures-0-image': '', 'pictures-1-id': '', 'pictures-1-gallery': '1', 'pictures-1-name': '...
'A simple model can be saved as inlines'
def test_simple_inline(self):
self.post_data['widget_set-0-name'] = 'Widget 1' response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) self.assertEqual(response.status_code, 302) self.assertEqual(Widget.objects.count(), 1) self.assertEqual(Widget.objects.all()[0].name, 'Widget 1') resp...
'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['grommet_set-0-name'] = 'Grommet 1' response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) self.assertEqual(response.status_code, 302) self.assertEqual(Grommet.objects.count(), 1) self.assertEqual(Grommet.objects.all()[0].name, 'Grommet 1') ...
'A model with a character PK can be saved as inlines. Regression for #10992'
def test_char_pk_inline(self):
self.post_data['doohickey_set-0-code'] = 'DH1' self.post_data['doohickey_set-0-name'] = 'Doohickey 1' response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) self.assertEqual(response.status_code, 302) self.assertEqual(DooHickey.objects.count(), 1) self.asser...
'A model with an integer PK can be saved as inlines. Regression for #10992'
def test_integer_pk_inline(self):
self.post_data['whatsit_set-0-index'] = '42' self.post_data['whatsit_set-0-name'] = 'Whatsit 1' response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) self.assertEqual(response.status_code, 302) self.assertEqual(Whatsit.objects.count(), 1) self.assertEqual(W...
'An inherited model can be saved as inlines. Regression for #11042'
def test_inherited_inline(self):
self.post_data['fancydoodad_set-0-name'] = 'Fancy Doodad 1' response = self.client.post('/test_admin/admin/admin_views/collector/1/', self.post_data) self.assertEqual(response.status_code, 302) self.assertEqual(FancyDoodad.objects.count(), 1) self.assertEqual(FancyDoodad.objects.all()[0].name,...
'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({'name': 'Frederic...
'Check the never-cache status of the main index'
def testAdminIndex(self):
response = self.client.get('/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('/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('/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('/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('/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('/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('/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('/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('/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('/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('/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('/test_admin/admin/jsi18n/') self.assertEqual(get_max_age(response), None)
'Regression test for #13004'
def test_readonly_manytomany(self):
response = self.client.get('/test_admin/admin/admin_views/pizza/add/') self.assertEqual(response.status_code, 200)
'Regression test for 14880'
def test_limit_choices_to(self):
actor = Actor.objects.create(name='Palin', age=27) inquisition1 = Inquisition.objects.create(expected=True, leader=actor, country='England') inquisition2 = Inquisition.objects.create(expected=False, leader=actor, country='Spain') response = self.client.get('/test_admin/admin/admin_views/sketch/add/') ...
'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('admin:admin_views_podcast_changelist')) self.assertNotContains(response, 'release_date__year=') self.assertNotContains(response, 'release_date__month=') self.assertNotContains(response, '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('admin:admin_views_podcast_changelist') response = self.client.get(url) 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('admin:admin_views_podcast_changelist') response = self.client.get(url) 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('admin:admin_views_podcast_changelist') response = self.client.get(url) self.assertNotContains(response, 'release_date__day='...
'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('admin:admin_views_podcast_changelist')) self.assertNotContains(response, 'release_date__day=') self.ass...
'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 condi...
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 ...
'Test the "in" operator for safe references (cmp)'
def testIn(self):
for t in self.ts[:50]: self.assert_((safeRef(t.x) in self.ss))
'Test that the references are valid (return instance methods)'
def testValid(self):
for s in self.ss: self.assert_(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.assert_(sd.has_key(safeRef(t.x))) self.assert_((safeRef(t.x) in sd)) else: self.assert_(sd.has_key(safeRef(t))) self.assert_((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.assert_(isinstance(err, ValueError)) self.assertEqual(err.args, ('this',)) a_signal.disconnect(fails) self._testIsClean(a_sign...
'Regression test for #7512 ordering across nullable Foreign Keys shouldn\'t exclude results'
def test_ordering_across_null_fk(self):
author_1 = Author.objects.create(name='Tom Jones') author_2 = Author.objects.create(name='Bob Smith') article_1 = Article.objects.create(title='No author on this article') article_2 = Article.objects.create(author=author_1, title='This article written by Tom Jones') ...
'Responses can be inspected for content, including counting repeated substrings'
def test_contains(self):
response = self.client.get('/test_client_regress/no_template_view/') self.assertNotContains(response, 'never') self.assertContains(response, 'never', 0) self.assertContains(response, 'once') self.assertContains(response, 'once', 1) self.assertContains(response, 'twice') self.assertContains(r...
'Unicode characters can be found in template context'
def test_unicode_contains(self):
r = self.client.get('/test_client_regress/check_unicode/') self.assertContains(r, u'\u3055\u304b\u304d') self.assertContains(r, '\xe5\xb3\xa0'.decode('utf-8'))
'Unicode characters can be searched for, and not found in template context'
def test_unicode_not_contains(self):
r = self.client.get('/test_client_regress/check_unicode/') self.assertNotContains(r, u'\u306f\u305f\u3051') self.assertNotContains(r, '\xe3\x81\xaf\xe3\x81\x9f\xe3\x81\x91'.decode('utf-8'))
'Template usage assertions work then templates aren\'t in use'
def test_no_context(self):
response = self.client.get('/test_client_regress/no_template_view/') self.assertTemplateNotUsed(response, 'GET Template') try: self.assertTemplateUsed(response, 'GET Template') except AssertionError as e: self.assertEquals(str(e), 'No templates used to render the ...
'Template assertions work when there is a single context'
def test_single_context(self):
response = self.client.get('/test_client/post_view/', {}) try: self.assertTemplateNotUsed(response, 'Empty GET Template') except AssertionError as e: self.assertEquals(str(e), "Template 'Empty GET Template' was used unexpectedly in rendering the response")...
'Template assertions work when there are multiple contexts'
def test_multiple_context(self):
post_data = {'text': 'Hello World', 'email': 'foo@example.com', 'value': 37, 'single': 'b', 'multi': ('b', 'c', 'e')} response = self.client.post('/test_client/form_view_with_template/', post_data) self.assertContains(response, 'POST data OK') try: self.assertTemplateNotUsed(response, '...
'An assertion is raised if the original page couldn\'t be retrieved as expected'
def test_redirect_page(self):
response = self.client.get('/test_client/permanent_redirect_view/') try: self.assertRedirects(response, '/test_client/get_view/') except AssertionError as e: self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 301 (expected 302)") ...
'An assertion is raised if the redirect location doesn\'t preserve GET parameters'
def test_lost_query(self):
response = self.client.get('/test_client/redirect_view/', {'var': 'value'}) try: self.assertRedirects(response, '/test_client/get_view/') except AssertionError as e: self.assertEquals(str(e), "Response redirected to 'http://testserver/test_client/get_view/?var=value', expected ...
'An assertion is raised if the response redirects to another target'
def test_incorrect_target(self):
response = self.client.get('/test_client/permanent_redirect_view/') try: self.assertRedirects(response, '/test_client/some_view/') except AssertionError as e: self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 301 (expected 302)")...
'An assertion is raised if the response redirect target cannot be retrieved as expected'
def test_target_page(self):
response = self.client.get('/test_client/double_redirect_view/') try: self.assertRedirects(response, 'http://testserver/test_client/permanent_redirect_view/') except AssertionError as e: self.assertEquals(str(e), "Couldn't retrieve redirection page '/test_client/permanent_redirec...
'You can follow a redirect chain of multiple redirects'
def test_redirect_chain(self):
response = self.client.get('/test_client_regress/redirects/further/more/', {}, follow=True) self.assertRedirects(response, '/test_client_regress/no_template_view/', status_code=301, target_status_code=200) self.assertEquals(len(response.redirect_chain), 1) self.assertEquals(response.redirect_chain[0], (...
'You can follow a redirect chain of multiple redirects'
def test_multiple_redirect_chain(self):
response = self.client.get('/test_client_regress/redirects/', {}, follow=True) self.assertRedirects(response, '/test_client_regress/no_template_view/', status_code=301, target_status_code=200) self.assertEquals(len(response.redirect_chain), 3) self.assertEquals(response.redirect_chain[0], ('http://tests...
'You can follow a chain to a non-existent view'
def test_redirect_chain_to_non_existent(self):
response = self.client.get('/test_client_regress/redirect_to_non_existent_view2/', {}, follow=True) self.assertRedirects(response, '/test_client_regress/non_existent_view/', status_code=301, target_status_code=404)
'Redirections to self are caught and escaped'
def test_redirect_chain_to_self(self):
response = self.client.get('/test_client_regress/redirect_to_self/', {}, follow=True) self.assertRedirects(response, '/test_client_regress/redirect_to_self/', status_code=301, target_status_code=301) self.assertEquals(len(response.redirect_chain), 2)
'Circular redirect chains are caught and escaped'
def test_circular_redirect(self):
response = self.client.get('/test_client_regress/circular_redirect_1/', {}, follow=True) self.assertRedirects(response, '/test_client_regress/circular_redirect_2/', status_code=301, target_status_code=301) self.assertEquals(len(response.redirect_chain), 4)
'A redirect chain will be followed from an initial POST post'
def test_redirect_chain_post(self):
response = self.client.post('/test_client_regress/redirects/', {'nothing': 'to_send'}, follow=True) self.assertRedirects(response, '/test_client_regress/no_template_view/', 301, 200) self.assertEquals(len(response.redirect_chain), 3)
'A redirect chain will be followed from an initial HEAD request'
def test_redirect_chain_head(self):
response = self.client.head('/test_client_regress/redirects/', {'nothing': 'to_send'}, follow=True) self.assertRedirects(response, '/test_client_regress/no_template_view/', 301, 200) self.assertEquals(len(response.redirect_chain), 3)
'A redirect chain will be followed from an initial OPTIONS request'
def test_redirect_chain_options(self):
response = self.client.options('/test_client_regress/redirects/', {'nothing': 'to_send'}, follow=True) self.assertRedirects(response, '/test_client_regress/no_template_view/', 301, 200) self.assertEquals(len(response.redirect_chain), 3)
'A redirect chain will be followed from an initial PUT request'
def test_redirect_chain_put(self):
response = self.client.put('/test_client_regress/redirects/', {'nothing': 'to_send'}, follow=True) self.assertRedirects(response, '/test_client_regress/no_template_view/', 301, 200) self.assertEquals(len(response.redirect_chain), 3)
'A redirect chain will be followed from an initial DELETE request'
def test_redirect_chain_delete(self):
response = self.client.delete('/test_client_regress/redirects/', {'nothing': 'to_send'}, follow=True) self.assertRedirects(response, '/test_client_regress/no_template_view/', 301, 200) self.assertEquals(len(response.redirect_chain), 3)
'An assertion is raised if the original page couldn\'t be retrieved as expected'
def test_redirect_chain_on_non_redirect_page(self):
response = self.client.get('/test_client/get_view/', follow=True) try: self.assertRedirects(response, '/test_client/get_view/') except AssertionError as e: self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 200 (expected 302)") ...
'An assertion is raised if the original page couldn\'t be retrieved as expected'
def test_redirect_on_non_redirect_page(self):
response = self.client.get('/test_client/get_view/') try: self.assertRedirects(response, '/test_client/get_view/') except AssertionError as e: self.assertEquals(str(e), "Response didn't redirect as expected: Response code was 200 (expected 302)") try: ...
'An assertion is raised if the form name is unknown'
def test_unknown_form(self):
post_data = {'text': 'Hello World', 'email': 'not an email address', 'value': 37, 'single': 'b', 'multi': ('b', 'c', 'e')} response = self.client.post('/test_client/form_view/', post_data) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'Invalid POST Templ...
'An assertion is raised if the field name is unknown'
def test_unknown_field(self):
post_data = {'text': 'Hello World', 'email': 'not an email address', 'value': 37, 'single': 'b', 'multi': ('b', 'c', 'e')} response = self.client.post('/test_client/form_view/', post_data) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'Invalid POST Templ...
'An assertion is raised if the field doesn\'t have any errors'
def test_noerror_field(self):
post_data = {'text': 'Hello World', 'email': 'not an email address', 'value': 37, 'single': 'b', 'multi': ('b', 'c', 'e')} response = self.client.post('/test_client/form_view/', post_data) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'Invalid POST Templ...
'An assertion is raised if the field doesn\'t contain the provided error'
def test_unknown_error(self):
post_data = {'text': 'Hello World', 'email': 'not an email address', 'value': 37, 'single': 'b', 'multi': ('b', 'c', 'e')} response = self.client.post('/test_client/form_view/', post_data) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'Invalid POST Templ...
'Checks that an assertion is raised if the form\'s non field errors doesn\'t contain the provided error.'
def test_unknown_nonfield_error(self):
post_data = {'text': 'Hello World', 'email': 'not an email address', 'value': 37, 'single': 'b', 'multi': ('b', 'c', 'e')} response = self.client.post('/test_client/form_view/', post_data) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'Invalid POST Templ...
'Check that using a different test client doesn\'t violate authentication'
def test_login_different_client(self):
c = Client() login = c.login(username='testclient', password='password') self.assertTrue(login, 'Could not log in') response = c.get('/test_client_regress/login_protected_redirect_view/') self.assertRedirects(response, 'http://testserver/test_client_regress/get_view/')
'A session engine that modifies the session key can be used to log in'
def test_login(self):
login = self.client.login(username='testclient', password='password') self.assertTrue(login, 'Could not log in') response = self.client.get('/test_client/login_protected_view/') self.assertEqual(response.status_code, 200) self.assertEqual(response.context['user'].username, 'testclient')
'Get a view that has a simple string argument'
def test_simple_argument_get(self):
response = self.client.get(reverse('arg_view', args=['Slartibartfast'])) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, 'Howdy, Slartibartfast')
'Get a view that has a string argument that requires escaping'
def test_argument_with_space_get(self):
response = self.client.get(reverse('arg_view', args=['Arthur Dent'])) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, 'Hi, Arthur')
'Post for a view that has a simple string argument'
def test_simple_argument_post(self):
response = self.client.post(reverse('arg_view', args=['Slartibartfast'])) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, 'Howdy, Slartibartfast')
'Post for a view that has a string argument that requires escaping'
def test_argument_with_space_post(self):
response = self.client.post(reverse('arg_view', args=['Arthur Dent'])) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, 'Hi, Arthur')
'#5836 - A stale user exception isn\'t re-raised by the test client.'
def test_exception_cleared(self):
login = self.client.login(username='testclient', password='password') self.assertTrue(login, 'Could not log in') try: response = self.client.get('/test_client_regress/staff_only/') self.fail('General users should not be able to visit this page') except...
'Missing templates are correctly reported by test client'
def test_no_404_template(self):
try: response = self.client.get('/no_such_view/') self.fail('Should get error about missing template') except TemplateDoesNotExist: pass