desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'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/')
... |
'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('/test_admin/admin/admin_views/album/add/')
self.assertEqual(response.status_code, 200)
self.assertContains(response, '/test_admin/admin/auth/user/add')
self.assertContains(response, 'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"')
... |
'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_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('admin:admin_views_podcast_changelist')
response = self.client.get(url)
for date in DATES:
self.assert_contains_day_l... |
'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.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(sd.has_key(safeRef(t.x)))
self.assertTrue((safeRef(t.x) in sd))
else:
self.assertTrue(sd.has_key(safeRef(t)))
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_s... |
'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.assertIn('No templates used to render the response', s... |
'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.assertIn("Template 'Empty GET Template' was used unexpectedly in rendering the response", str(e))
... |
'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.assertIn("Response didn't redirect as expected: Response code was 301 (expected 302)", str(e))
... |
'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.assertIn("Response redirected to 'http://testserver/test_client/get_view/?var=value', expected 'http://tes... |
'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.assertIn("Response didn't redirect as expected: Response code was 301 (expected 302)", str(e))
|
'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.assertIn("Couldn't retrieve redirection page '/test_client/permanent_redirect_view/': ... |
'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.assertEqual(len(response.redirect_chain), 1)
self.assertEqual(response.redirect_chain[0], ('h... |
'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.assertEqual(len(response.redirect_chain), 3)
self.assertEqual(response.redirect_chain[0], ('http://testser... |
'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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertEqual(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.assertIn("Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
tr... |
'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.assertIn("Response didn't redirect as expected: Response code was 200 (expected 302)", str(e))
try:
se... |
'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
|
'Errors found when rendering 404 error templates are re-raised'
| def test_bad_404_template(self):
| settings.TEMPLATE_DIRS = (os.path.join(os.path.dirname(__file__), 'bad_templates'),)
try:
response = self.client.get('/no_such_view/')
self.fail('Should get error about syntax error in template')
except TemplateSyntaxError:
pass
|
'TestCase can enforce a custom URLconf on a per-test basis'
| def test_urlconf_was_changed(self):
| url = reverse('arg_view', args=['somename'])
self.assertEqual(url, '/arg_view/somename/')
|
'URLconf is reverted to original value after modification in a TestCase'
| def test_urlconf_was_reverted(self):
| url = reverse('arg_view', args=['somename'])
self.assertEqual(url, '/test_client_regress/arg_view/somename/')
|
'Context variables can be retrieved from a single context'
| def test_single_context(self):
| response = self.client.get('/test_client_regress/request_data/', data={'foo': 'whiz'})
self.assertEqual(response.context.__class__, Context)
self.assertTrue(('get-foo' in response.context))
self.assertEqual(response.context['get-foo'], 'whiz')
self.assertEqual(response.context['request-foo'], 'whiz'... |
'Context variables can be retrieved from a list of contexts'
| def test_inherited_context(self):
| response = self.client.get('/test_client_regress/request_data_extended/', data={'foo': 'whiz'})
self.assertEqual(response.context.__class__, ContextList)
self.assertEqual(len(response.context), 2)
self.assertTrue(('get-foo' in response.context))
self.assertEqual(response.context['get-foo'], 'whiz')
... |
'The session isn\'t lost if a user logs in'
| def test_session(self):
| response = self.client.get('/test_client_regress/check_session/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'NO')
response = self.client.get('/test_client_regress/set_session/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 's... |
'Logout should work whether the user is logged in or not (#9978).'
| def test_logout(self):
| self.client.logout()
login = self.client.login(username='testclient', password='password')
self.assertTrue(login, 'Could not log in')
self.client.logout()
self.client.logout()
|
'Request a view via request method GET'
| def test_get(self):
| response = self.client.get('/test_client_regress/request_methods/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'request method: GET')
|
'Request a view via request method POST'
| def test_post(self):
| response = self.client.post('/test_client_regress/request_methods/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'request method: POST')
|
'Request a view via request method HEAD'
| def test_head(self):
| response = self.client.head('/test_client_regress/request_methods/')
self.assertEqual(response.status_code, 200)
self.assertNotEqual(response.content, 'request method: HEAD')
self.assertEqual(response.content, '')
|
'Request a view via request method OPTIONS'
| def test_options(self):
| response = self.client.options('/test_client_regress/request_methods/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'request method: OPTIONS')
|
'Request a view via request method PUT'
| def test_put(self):
| response = self.client.put('/test_client_regress/request_methods/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'request method: PUT')
|
'Request a view via request method DELETE'
| def test_delete(self):
| response = self.client.delete('/test_client_regress/request_methods/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'request method: DELETE')
|
'Request a view with string data via request method POST'
| def test_post(self):
| data = u'{"test": "json"}'
response = self.client.post('/test_client_regress/request_methods/', data=data, content_type='application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'request method: POST')
|
'Request a view with string data via request method PUT'
| def test_put(self):
| data = u'{"test": "json"}'
response = self.client.put('/test_client_regress/request_methods/', data=data, content_type='application/json')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.content, 'request method: PUT')
|
'A simple ASCII-only unicode JSON document can be POSTed'
| def test_simple_unicode_payload(self):
| json = u'{"english": "mountain pass"}'
response = self.client.post('/test_client_regress/parse_unicode_json/', json, content_type='application/json')
self.assertEqual(response.content, json)
response = self.client.put('/test_client_regress/parse_unicode_json/', json, content_type='application/json... |
'A non-ASCII unicode data encoded as UTF-8 can be POSTed'
| def test_unicode_payload_utf8(self):
| json = u'{"dog": "\u0441\u043e\u0431\u0430\u043a\u0430"}'
response = self.client.post('/test_client_regress/parse_unicode_json/', json, content_type='application/json; charset=utf-8')
self.assertEqual(response.content, json.encode('utf-8'))
response = self.client.put('/test_client_regress/parse_un... |
'A non-ASCII unicode data encoded as UTF-16 can be POSTed'
| def test_unicode_payload_utf16(self):
| json = u'{"dog": "\u0441\u043e\u0431\u0430\u043a\u0430"}'
response = self.client.post('/test_client_regress/parse_unicode_json/', json, content_type='application/json; charset=utf-16')
self.assertEqual(response.content, json.encode('utf-16'))
response = self.client.put('/test_client_regress/parse_... |
'A non-ASCII unicode data as a non-UTF based encoding can be POSTed'
| def test_unicode_payload_non_utf(self):
| json = u'{"dog": "\u0441\u043e\u0431\u0430\u043a\u0430"}'
response = self.client.post('/test_client_regress/parse_unicode_json/', json, content_type='application/json; charset=koi8-r')
self.assertEqual(response.content, json.encode('koi8-r'))
response = self.client.put('/test_client_regress/parse_... |
'A test client can receive custom headers'
| def test_client_headers(self):
| response = self.client.get('/test_client_regress/check_headers/', HTTP_X_ARG_CHECK='Testing 123')
self.assertEqual(response.content, 'HTTP_X_ARG_CHECK: Testing 123')
self.assertEqual(response.status_code, 200)
|
'Test client headers are preserved through redirects'
| def test_client_headers_redirect(self):
| response = self.client.get('/test_client_regress/check_headers_redirect/', follow=True, HTTP_X_ARG_CHECK='Testing 123')
self.assertEqual(response.content, 'HTTP_X_ARG_CHECK: Testing 123')
self.assertRedirects(response, '/test_client_regress/check_headers/', status_code=301, target_status_code=200)
|
'Tests that URLs with slashes go unmolested.'
| def test_append_slash_have_slash(self):
| settings.APPEND_SLASH = True
request = self._get_request('slash/')
self.assertEqual(CommonMiddleware().process_request(request), None)
|
'Tests that matches to explicit slashless URLs go unmolested.'
| def test_append_slash_slashless_resource(self):
| settings.APPEND_SLASH = True
request = self._get_request('noslash')
self.assertEqual(CommonMiddleware().process_request(request), None)
|
'Tests that APPEND_SLASH doesn\'t redirect to unknown resources.'
| def test_append_slash_slashless_unknown(self):
| settings.APPEND_SLASH = True
request = self._get_request('unknown')
self.assertEqual(CommonMiddleware().process_request(request), None)
|
'Tests that APPEND_SLASH redirects slashless URLs to a valid pattern.'
| def test_append_slash_redirect(self):
| settings.APPEND_SLASH = True
request = self._get_request('slash')
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
self.assertEqual(r['Location'], 'http://testserver/middleware/slash/')
|
'Tests that while in debug mode, an exception is raised with a warning
when a failed attempt is made to POST to an URL which would normally be
redirected to a slashed version.'
| def test_append_slash_no_redirect_on_POST_in_DEBUG(self):
| settings.APPEND_SLASH = True
settings.DEBUG = True
request = self._get_request('slash')
request.method = 'POST'
self.assertRaises(RuntimeError, CommonMiddleware().process_request, request)
try:
CommonMiddleware().process_request(request)
except RuntimeError as e:
self.assertT... |
'Tests disabling append slash functionality.'
| def test_append_slash_disabled(self):
| settings.APPEND_SLASH = False
request = self._get_request('slash')
self.assertEqual(CommonMiddleware().process_request(request), None)
|
'Tests that URLs which require quoting are redirected to their slash
version ok.'
| def test_append_slash_quoted(self):
| settings.APPEND_SLASH = True
request = self._get_request('needsquoting#')
r = CommonMiddleware().process_request(request)
self.assertEqual(r.status_code, 301)
self.assertEqual(r['Location'], 'http://testserver/middleware/needsquoting%23/')
|
'Tests that URLs with slashes go unmolested.'
| def test_append_slash_have_slash_custom_urlconf(self):
| settings.APPEND_SLASH = True
request = self._get_request('customurlconf/slash/')
request.urlconf = 'regressiontests.middleware.extra_urls'
self.assertEqual(CommonMiddleware().process_request(request), None)
|
'Tests that matches to explicit slashless URLs go unmolested.'
| def test_append_slash_slashless_resource_custom_urlconf(self):
| settings.APPEND_SLASH = True
request = self._get_request('customurlconf/noslash')
request.urlconf = 'regressiontests.middleware.extra_urls'
self.assertEqual(CommonMiddleware().process_request(request), None)
|
'Tests that APPEND_SLASH doesn\'t redirect to unknown resources.'
| def test_append_slash_slashless_unknown_custom_urlconf(self):
| settings.APPEND_SLASH = True
request = self._get_request('customurlconf/unknown')
request.urlconf = 'regressiontests.middleware.extra_urls'
self.assertEqual(CommonMiddleware().process_request(request), None)
|
'Tests that APPEND_SLASH redirects slashless URLs to a valid pattern.'
| def test_append_slash_redirect_custom_urlconf(self):
| settings.APPEND_SLASH = True
request = self._get_request('customurlconf/slash')
request.urlconf = 'regressiontests.middleware.extra_urls'
r = CommonMiddleware().process_request(request)
self.assertFalse((r is None), 'CommonMiddlware failed to return APPEND_SLASH redirect using r... |
'Tests that while in debug mode, an exception is raised with a warning
when a failed attempt is made to POST to an URL which would normally be
redirected to a slashed version.'
| def test_append_slash_no_redirect_on_POST_in_DEBUG_custom_urlconf(self):
| settings.APPEND_SLASH = True
settings.DEBUG = True
request = self._get_request('customurlconf/slash')
request.urlconf = 'regressiontests.middleware.extra_urls'
request.method = 'POST'
self.assertRaises(RuntimeError, CommonMiddleware().process_request, request)
try:
CommonMiddleware()... |
'Tests disabling append slash functionality.'
| def test_append_slash_disabled_custom_urlconf(self):
| settings.APPEND_SLASH = False
request = self._get_request('customurlconf/slash')
request.urlconf = 'regressiontests.middleware.extra_urls'
self.assertEqual(CommonMiddleware().process_request(request), None)
|
'Tests that URLs which require quoting are redirected to their slash
version ok.'
| def test_append_slash_quoted_custom_urlconf(self):
| settings.APPEND_SLASH = True
request = self._get_request('customurlconf/needsquoting#')
request.urlconf = 'regressiontests.middleware.extra_urls'
r = CommonMiddleware().process_request(request)
self.assertFalse((r is None), 'CommonMiddlware failed to return APPEND_SLASH redirect us... |
'# Regression test for #8027: custom ModelForms with fields/fieldsets'
| def test_custom_modelforms_with_fields_fieldsets(self):
| validate(ValidFields, Song)
self.assertRaisesMessage(ImproperlyConfigured, "'InvalidFields.fields' refers to field 'spam' that is missing from the form.", validate, InvalidFields, Song)
|
'Tests for basic validation of \'exclude\' option values (#12689)'
| def test_exclude_values(self):
| class ExcludedFields1(admin.ModelAdmin, ):
exclude = 'foo'
self.assertRaisesMessage(ImproperlyConfigured, "'ExcludedFields1.exclude' must be a list or tuple.", validate, ExcludedFields1, Book)
|
'# Regression test for #9932 - exclude in InlineModelAdmin
# should not contain the ForeignKey field used in ModelAdmin.model'
| def test_exclude_inline_model_admin(self):
| class SongInline(admin.StackedInline, ):
model = Song
exclude = ['album']
class AlbumAdmin(admin.ModelAdmin, ):
model = Album
inlines = [SongInline]
self.assertRaisesMessage(ImproperlyConfigured, "SongInline cannot exclude the field 'album' - this is ... |
'Regression test for #11709 - when testing for fk excluding (when exclude is
given) make sure fk_name is honored or things blow up when there is more
than one fk to the parent model.'
| def test_fk_exclusion(self):
| class TwoAlbumFKAndAnEInline(admin.TabularInline, ):
model = TwoAlbumFKAndAnE
exclude = ('e',)
fk_name = 'album1'
validate_inline(TwoAlbumFKAndAnEInline, None, Album)
|
'Regression test for #12203/#12237 - Fail more gracefully when a M2M field that
specifies the \'through\' option is included in the \'fields\' or the \'fieldsets\'
ModelAdmin options.'
| def test_graceful_m2m_fail(self):
| class BookAdmin(admin.ModelAdmin, ):
fields = ['authors']
self.assertRaisesMessage(ImproperlyConfigured, "'BookAdmin.fields' can't include the ManyToManyField field 'authors' because 'authors' manually specifies a 'through' model.", validate, BookAdmin, Book)
|
'Regression test for #12209 -- If the explicitly provided through model
is specified as a string, the admin should still be able use
Model.m2m_field.through'
| def test_explicit_through_override(self):
| class AuthorsInline(admin.TabularInline, ):
model = Book.authors.through
class BookAdmin(admin.ModelAdmin, ):
inlines = [AuthorsInline]
validate(BookAdmin, Book)
|
'Regression for ensuring ModelAdmin.fields can contain non-model fields
that broke with r11737'
| def test_non_model_fields(self):
| class SongForm(forms.ModelForm, ):
extra_data = forms.CharField()
class Meta:
model = Song
class FieldsOnFormOnlyAdmin(admin.ModelAdmin, ):
form = SongForm
fields = ['title', 'extra_data']
validate(FieldsOnFormOnlyAdmin, Song)
|
'Tests for bug #11193 (errors inside middleware shouldn\'t leave
the initLock locked).'
| def test_lock_safety(self):
| old_middleware_classes = settings.MIDDLEWARE_CLASSES
settings.MIDDLEWARE_CLASSES = 42
handler = WSGIHandler()
self.assertEqual(handler.initLock.locked(), False)
try:
handler(None, None)
except:
pass
self.assertEqual(handler.initLock.locked(), False)
settings.MIDDLEWARE_CL... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.