desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'verbose_name_plural correctly inherited from ABC if inheritance chain
includes an abstract model.'
| def test_11369(self):
| self.assertEquals(InternalCertificationAudit._meta.verbose_name_plural, u'Audits')
|
'We can fill a value in all objects with an other value of the
same object.'
| def test_fill_with_value_from_same_object(self):
| self.assertQuerysetEqual(Number.objects.all(), ['<Number: -1, -1.000>', '<Number: 42, 42.000>', '<Number: 1337, 1337.000>'])
|
'We can increment a value of all objects in a query set.'
| def test_increment_value(self):
| self.assertEqual(Number.objects.filter(integer__gt=0).update(integer=(F('integer') + 1)), 2)
self.assertQuerysetEqual(Number.objects.all(), ['<Number: -1, -1.000>', '<Number: 43, 42.000>', '<Number: 1338, 1337.000>'])
|
'We can filter for objects, where a value is not equals the value
of an other field.'
| def test_filter_not_equals_other_field(self):
| self.assertEqual(Number.objects.filter(integer__gt=0).update(integer=(F('integer') + 1)), 2)
self.assertQuerysetEqual(Number.objects.exclude(float=F('integer')), ['<Number: 43, 42.000>', '<Number: 1338, 1337.000>'])
|
'Complex expressions of different connection types are possible.'
| def test_complex_expressions(self):
| n = Number.objects.create(integer=10, float=123.45)
self.assertEqual(Number.objects.filter(pk=n.pk).update(float=(F('integer') + (F('float') * 2))), 1)
self.assertEqual(Number.objects.get(pk=n.pk).integer, 10)
self.assertEqual(Number.objects.get(pk=n.pk).float, Approximate(256.9, places=3))
|
'Can view a shortcut for an Author object that has a get_absolute_url method'
| def test_shortcut_with_absolute_url(self):
| for obj in Author.objects.all():
short_url = ('/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Author).id, obj.pk))
response = self.client.get(short_url)
self.assertRedirects(response, ('http://testserver%s' % obj.get_absolute_url()), status_code=302, target_status_code=404)
|
'Shortcuts for an object that has no get_absolute_url method raises 404'
| def test_shortcut_no_absolute_url(self):
| for obj in Article.objects.all():
short_url = ('/views/shortcut/%s/%s/' % (ContentType.objects.get_for_model(Article).id, obj.pk))
response = self.client.get(short_url)
self.assertEquals(response.status_code, 404)
|
'A 404 status is returned by the page_not_found view'
| def test_page_not_found(self):
| for url in self.non_existing_urls:
response = self.client.get(url)
self.assertEquals(response.status_code, 404)
|
'The 404 page should have the csrf_token available in the context'
| def test_csrf_token_in_404(self):
| old_DEBUG = settings.DEBUG
try:
settings.DEBUG = False
for url in self.non_existing_urls:
response = self.client.get(url)
csrf_token = response.context['csrf_token']
self.assertNotEqual(str(csrf_token), 'NOTPROVIDED')
self.assertNotEqual(str(csrf_t... |
'The server_error view raises a 500 status'
| def test_server_error(self):
| response = self.client.get('/views/server_error/')
self.assertEquals(response.status_code, 500)
|
'A model can set attributes on the get_absolute_url method'
| def test_get_absolute_url_attributes(self):
| self.assertTrue(getattr(UrlArticle.get_absolute_url, 'purge', False), 'The attributes of the original get_absolute_url must be added.')
article = UrlArticle.objects.get(pk=1)
self.assertTrue(getattr(article.get_absolute_url, 'purge', False), 'The attributes of the origina... |
'The set_language view can be used to change the session language'
| def test_setlang(self):
| for (lang_code, lang_name) in settings.LANGUAGES:
post_data = dict(language=lang_code, next='/views/')
response = self.client.post('/views/i18n/setlang/', data=post_data)
self.assertRedirects(response, 'http://testserver/views/')
self.assertEquals(self.client.session['django_language... |
'The javascript_catalog can be deployed with language settings'
| def test_jsi18n(self):
| for lang_code in ['es', 'fr', 'ru']:
activate(lang_code)
catalog = gettext.translation('djangojs', locale_dir, [lang_code])
trans_txt = catalog.ugettext('this is to be translated')
response = self.client.get('/views/jsi18n/')
self.assertContains(response, javascri... |
'The javascript_catalog shouldn\'t load the fallback language in the
case that the current selected language is actually the one translated
from, and hence missing translation files completely.
This happens easily when you\'re translating from English to other
languages and you\'ve set settings.LANGUAGE_CODE to some ot... | def test_jsi18n_with_missing_en_files(self):
| settings.LANGUAGE_CODE = 'es'
activate('en-us')
response = self.client.get('/views/jsi18n/')
self.assertNotContains(response, 'esto tiene que ser traducido')
|
'Let\'s make sure that the fallback language is still working properly
in cases where the selected language cannot be found.'
| def test_jsi18n_fallback_language(self):
| settings.LANGUAGE_CODE = 'fr'
activate('fi')
response = self.client.get('/views/jsi18n/')
self.assertContains(response, 'il faut le traduire')
|
'Check if the Javascript i18n view returns an empty language catalog
if the default language is non-English, the selected language
is English and there is not \'en\' translation available. See #13388,
#3594 and #13726 for more details.'
| def testI18NLanguageNonEnglishDefault(self):
| settings.LANGUAGE_CODE = 'fr'
activate('en-us')
response = self.client.get('/views/jsi18n/')
self.assertNotContains(response, 'Choisir une heure')
|
'Same as above with the difference that there IS an \'en\' translation
available. The Javascript i18n view must return a NON empty language catalog
with the proper English translations. See #13726 for more details.'
| def test_nonenglish_default_english_userpref(self):
| settings.LANGUAGE_CODE = 'fr'
settings.INSTALLED_APPS = (list(settings.INSTALLED_APPS) + ['regressiontests.views.app0'])
activate('en-us')
response = self.client.get('/views/jsi18n_english_translation/')
self.assertContains(response, javascript_quote('this app0 string is to be tran... |
'Makes sure that the fallback language is still working properly
in cases where the selected language cannot be found.'
| def testI18NLanguageNonEnglishFallback(self):
| settings.LANGUAGE_CODE = 'fr'
activate('none')
response = self.client.get('/views/jsi18n/')
self.assertContains(response, 'Choisir une heure')
|
'Check if the JavaScript i18n view returns a complete language catalog
if the default language is en-us, the selected language has a
translation available and a catalog composed by djangojs domain
translations of multiple Python packages is requested. See #13388,
#3594 and #13514 for more details.'
| def testI18NLanguageEnglishDefault(self):
| settings.LANGUAGE_CODE = 'en-us'
settings.INSTALLED_APPS = (list(settings.INSTALLED_APPS) + ['regressiontests.views.app1', 'regressiontests.views.app2'])
activate('fr')
response = self.client.get('/views/jsi18n_multi_packages1/')
self.assertContains(response, javascript_quote('il faut traduire... |
'Similar to above but with neither default or requested language being
English.'
| def testI18NDifferentNonEnLangs(self):
| settings.LANGUAGE_CODE = 'fr'
settings.INSTALLED_APPS = (list(settings.INSTALLED_APPS) + ['regressiontests.views.app3', 'regressiontests.views.app4'])
activate('es-ar')
response = self.client.get('/views/jsi18n_multi_packages2/')
self.assertContains(response, javascript_quote('este texto de ... |
'The static view can serve static media'
| def test_serve(self):
| media_files = ['file.txt', 'file.txt.gz']
for filename in media_files:
response = self.client.get(('/views/site_media/%s' % filename))
file_path = path.join(media_dir, filename)
self.assertEquals(open(file_path).read(), response.content)
self.assertEquals(len(response.content), i... |
'Handle bogus If-Modified-Since values gracefully
Assume that a file is modified since an invalid timestamp as per RFC
2616, section 14.25.'
| def test_invalid_if_modified_since(self):
| file_name = 'file.txt'
invalid_date = 'Mon, 28 May 999999999999 28:25:26 GMT'
response = self.client.get(('/views/site_media/%s' % file_name), HTTP_IF_MODIFIED_SINCE=invalid_date)
file = open(path.join(media_dir, file_name))
self.assertEquals(file.read(), response.content)
self.as... |
'Handle even more bogus If-Modified-Since values gracefully
Assume that a file is modified since an invalid timestamp as per RFC
2616, section 14.25.'
| def test_invalid_if_modified_since2(self):
| file_name = 'file.txt'
invalid_date = ': 1291108438, Wed, 20 Oct 2010 14:05:00 GMT'
response = self.client.get(('/views/site_media/%s' % file_name), HTTP_IF_MODIFIED_SINCE=invalid_date)
file = open(path.join(media_dir, file_name))
self.assertEquals(file.read(), response.content)... |
'Verifies that an unauthenticated user attempting to access a
login_required view gets redirected to the login page and that
an authenticated user is let through.'
| def test_login_required_view(self):
| view_url = '/views/create_update/member/create/article/'
response = self.client.get(view_url)
self.assertRedirects(response, ('/accounts/login/?next=%s' % view_url))
login = self.client.login(username='testclient', password='password')
self.assertTrue(login, 'Could not log in')
response... |
'Ensures the generic view returned the page and contains a form.'
| def test_create_article_display_page(self):
| view_url = '/views/create_update/create/article/'
response = self.client.get(view_url)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'views/article_form.html')
if (not response.context.get('form')):
self.fail('No form found in the response.')
|
'POSTs a form that contains validation errors.'
| def test_create_article_with_errors(self):
| view_url = '/views/create_update/create/article/'
num_articles = Article.objects.count()
response = self.client.post(view_url, {'title': 'My First Article'})
self.assertFormError(response, 'form', 'slug', [u'This field is required.'])
self.assertTemplateUsed(response, 'views/article_f... |
'Creates a new article using a custom form class with a save method
that alters the slug entered.'
| def test_create_custom_save_article(self):
| view_url = '/views/create_update/create_custom/article/'
response = self.client.post(view_url, {'title': 'Test Article', 'slug': 'this-should-get-replaced', 'author': 1, 'date_created': datetime.datetime(2007, 6, 25)})
self.assertRedirects(response, '/views/create_update/view/article/some-other-slug/', t... |
'Verifies that the form was created properly and with initial values.'
| def test_update_object_form_display(self):
| response = self.client.get('/views/create_update/update/article/old_article/')
self.assertTemplateUsed(response, 'views/article_form.html')
self.assertEquals(unicode(response.context['form']['title']), u'<input id="id_title" type="text" name="title" value="Old Article" maxlength="100" /... |
'Verifies the updating of an Article.'
| def test_update_object(self):
| response = self.client.post('/views/create_update/update/article/old_article/', {'title': 'Another Article', 'slug': 'another-article-slug', 'author': 1, 'date_created': datetime.datetime(2007, 6, 25)})
article = Article.objects.get(pk=1)
self.assertEquals(article.title, 'Another Article')
|
'Verifies the confirm deletion page is displayed using a GET.'
| def test_delete_object_confirm(self):
| response = self.client.get('/views/create_update/delete/article/old_article/')
self.assertTemplateUsed(response, 'views/article_confirm_delete.html')
|
'Verifies the object actually gets deleted on a POST.'
| def test_delete_object(self):
| view_url = '/views/create_update/delete/article/old_article/'
response = self.client.post(view_url)
try:
Article.objects.get(slug='old_article')
except Article.DoesNotExist:
pass
else:
self.fail('Object was not deleted.')
|
'The delete_object view requires a post_delete_redirect, so skip testing
here.'
| def test_delete_article(self):
| pass
|
'The delete_object view requires a post_delete_redirect, so skip testing
here.'
| def test_delete_article(self):
| pass
|
'date_based.object_detail can view a page in the past'
| def test_finds_past(self):
| response = self.client.get('/views/date_based/object_detail/2001/01/01/old_article/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['object'].title, 'Old Article')
|
'date_based.object_detail can view a page from today'
| def test_object_detail_finds_today(self):
| today_url = datetime.now().strftime('%Y/%m/%d')
response = self.client.get(('/views/date_based/object_detail/%s/current_article/' % today_url))
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['object'].title, 'Current Article')
|
'date_based.object_detail can view a page from the future, but only if allowed.'
| def test_object_detail_ignores_future(self):
| response = self.client.get('/views/date_based/object_detail/3000/01/01/future_article/')
self.assertEqual(response.status_code, 404)
|
'date_based.object_detail can view a page from the future if explicitly allowed.'
| def test_object_detail_allowed_future_if_enabled(self):
| response = self.client.get('/views/date_based/object_detail/3000/01/01/future_article/allow_future/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['object'].title, 'Future Article')
|
'Regression for #3031: Archives around Feburary include only one month'
| def test_archive_month_includes_only_month(self):
| author = Author(name='John Smith')
author.save()
first_second_of_feb = datetime(2004, 2, 1, 0, 0, 1)
first_second_of_mar = datetime(2004, 3, 1, 0, 0, 1)
two_seconds = timedelta(0, 2, 0)
article = Article(title='example', author=author)
article.date_created = first_second_of_feb
articl... |
'Make sure day views don\'t get confused with numeric month formats (#7944)'
| def test_year_month_day_format(self):
| author = Author.objects.create(name='John Smith')
article = Article.objects.create(title='example', author=author, date_created=datetime(2004, 1, 21, 0, 0, 1))
response = self.client.get('/views/date_based/archive_day/2004/1/21/')
self.assertEqual(response.status_code, 200)
self.assertEqual(respo... |
'Tests that redirecting to an IRI, requiring encoding before we use it
in an HTTP response, is handled correctly. In this case the arg to
HttpRedirect is ASCII but the current request path contains non-ASCII
characters so this test ensures the creation of the full path with a
base non-ASCII part is handled correctly.'
| def test_combining_redirect(self):
| response = self.client.get(u'/views/\u4e2d\u6587/')
self.assertRedirects(response, self.redirect_target)
|
'Tests that a non-ASCII argument to HttpRedirect is handled properly.'
| def test_nonascii_redirect(self):
| response = self.client.get('/views/nonascii_redirect/')
self.assertRedirects(response, self.redirect_target)
|
'Tests that a non-ASCII argument to HttpPermanentRedirect is handled
properly.'
| def test_permanent_nonascii_redirect(self):
| response = self.client.get('/views/permanent_nonascii_redirect/')
self.assertRedirects(response, self.redirect_target, status_code=301)
|
'm2m-through models aren\'t serialized as m2m fields. Refs #8134'
| def test_serialization(self):
| p = Person.objects.create(name='Bob')
g = Group.objects.create(name='Roll')
m = Membership.objects.create(person=p, group=g)
pks = {'p_pk': p.pk, 'g_pk': g.pk, 'm_pk': m.pk}
out = StringIO()
management.call_command('dumpdata', 'm2m_through_regress', format='json', stdout=out)
self.assertEqua... |
'Check that we don\'t involve too many copies of the intermediate table when doing a join. Refs #8046, #8254'
| def test_join_trimming(self):
| bob = Person.objects.create(name='Bob')
jim = Person.objects.create(name='Jim')
rock = Group.objects.create(name='Rock')
roll = Group.objects.create(name='Roll')
Membership.objects.create(person=bob, group=rock)
Membership.objects.create(person=jim, group=rock, price=50)
Membership.objects.c... |
'Check that sequences on an m2m_through are created for the through model, not a phantom auto-generated m2m table. Refs #11107'
| def test_sequence_creation(self):
| out = StringIO()
management.call_command('dumpdata', 'm2m_through_regress', format='json', stdout=out)
self.assertEqual(out.getvalue().strip(), '[{"pk": 1, "model": "m2m_through_regress.usermembership", "fields": {"price": 100, "group": 1, "user": 1}}, {"pk": 1, "model... |
'Comments that aren\'t public are considered in moderation'
| def testInModeration(self):
| (c1, c2, c3, c4) = self.createSomeComments()
c1.is_public = False
c2.is_public = False
c1.save()
c2.save()
moderated_comments = list(Comment.objects.in_moderation().order_by('id'))
self.assertEqual(moderated_comments, [c1, c2])
|
'Removed comments are not considered in moderation'
| def testRemovedCommentsNotInModeration(self):
| (c1, c2, c3, c4) = self.createSomeComments()
c1.is_public = False
c2.is_public = False
c2.is_removed = True
c1.save()
c2.save()
moderated_comments = list(Comment.objects.in_moderation())
self.assertEqual(moderated_comments, [c1])
|
'Test COMMENTS_ALLOW_PROFANITIES and PROFANITIES_LIST settings'
| def testProfanities(self):
| a = Article.objects.get(pk=1)
d = self.getValidData(a)
saved = (settings.PROFANITIES_LIST, settings.COMMENTS_ALLOW_PROFANITIES)
settings.PROFANITIES_LIST = ['rooster']
settings.COMMENTS_ALLOW_PROFANITIES = False
f = CommentForm(a, data=dict(d, comment='What a rooster!'))
self.assertFal... |
'The debug error template should be shown only if DEBUG is True'
| def testDebugCommentErrors(self):
| olddebug = settings.DEBUG
settings.DEBUG = True
a = Article.objects.get(pk=1)
data = self.getValidData(a)
data['security_hash'] = 'Nobody expects the Spanish Inquisition!'
response = self.client.post('/post/', data)
self.assertEqual(response.status_code, 400)
self.assertTempl... |
'Check that the user\'s name in the comment is populated for
authenticated users without first_name and last_name.'
| def testPostAsAuthenticatedUserWithoutFullname(self):
| user = User.objects.create_user(username='jane_other', email='jane@example.com', password='jane_other')
a = Article.objects.get(pk=1)
data = self.getValidData(a)
data['name'] = data['email'] = ''
self.client.login(username='jane_other', password='jane_other')
self.response = self.client.post('/p... |
'Prevent posting the exact same comment twice'
| def testPreventDuplicateComments(self):
| a = Article.objects.get(pk=1)
data = self.getValidData(a)
self.client.post('/post/', data)
self.client.post('/post/', data)
self.assertEqual(Comment.objects.count(), 1)
self.client.post('/post/', dict(data, comment='My second comment.'))
self.assertEqual(Comment.objects.count(), 2)
|
'Test signals emitted by the comment posting view'
| def testCommentSignals(self):
| def receive(sender, **kwargs):
self.assertEqual(kwargs['comment'].comment, 'This is my comment')
self.assert_(('request' in kwargs))
received_signals.append(kwargs.get('signal'))
received_signals = []
expected_signals = [signals.comment_will_be_posted, signals.comment_was_po... |
'Test that the comment_will_be_posted signal can prevent the comment from
actually getting saved'
| def testWillBePostedSignal(self):
| def receive(sender, **kwargs):
return False
signals.comment_will_be_posted.connect(receive, dispatch_uid='comment-test')
a = Article.objects.get(pk=1)
data = self.getValidData(a)
response = self.client.post('/post/', data)
self.assertEqual(response.status_code, 400)
self.assertEqual(... |
'Test that the comment_will_be_posted signal can modify a comment before
it gets posted'
| def testWillBePostedSignalModifyComment(self):
| def receive(sender, **kwargs):
kwargs['comment'].is_public = False
signals.comment_will_be_posted.connect(receive)
self.testCreateValidComment()
c = Comment.objects.all()[0]
self.assertFalse(c.is_public)
|
'Test the different "next" actions the comment view can take'
| def testCommentNext(self):
| a = Article.objects.get(pk=1)
data = self.getValidData(a)
response = self.client.post('/post/', data)
location = response['Location']
match = post_redirect_re.match(location)
self.assertTrue((match != None), ('Unexpected redirect location: %s' % location))
data['next'] = '/somewhere... |
'The `next` key needs to handle already having a query string (#10585)'
| def testCommentNextWithQueryString(self):
| a = Article.objects.get(pk=1)
data = self.getValidData(a)
data['next'] = '/somewhere/else/?foo=bar'
data['comment'] = 'This is another comment'
response = self.client.post('/post/', data)
location = response['Location']
match = re.search('^http://testserver/somewhere/else/\\?foo=bar... |
'Tests that attempting to retrieve the location specified in the
post redirect, after adding some invalid data to the expected
querystring it ends with, doesn\'t cause a server error.'
| def testCommentPostRedirectWithInvalidIntegerPK(self):
| a = Article.objects.get(pk=1)
data = self.getValidData(a)
data['comment'] = 'This is another comment'
response = self.client.post('/post/', data)
location = response['Location']
broken_location = (location + u'\ufffd')
response = self.client.get(broken_location)
self.assertEqual... |
'GET the flag view: render a confirmation page.'
| def testFlagGet(self):
| comments = self.createSomeComments()
pk = comments[0].pk
self.client.login(username='normaluser', password='normaluser')
response = self.client.get(('/flag/%d/' % pk))
self.assertTemplateUsed(response, 'comments/flag.html')
|
'POST the flag view: actually flag the view (nice for XHR)'
| def testFlagPost(self):
| comments = self.createSomeComments()
pk = comments[0].pk
self.client.login(username='normaluser', password='normaluser')
response = self.client.post(('/flag/%d/' % pk))
self.assertEqual(response['Location'], ('http://testserver/flagged/?c=%d' % pk))
c = Comment.objects.get(pk=pk)
self.assert... |
'Users don\'t get to flag comments more than once.'
| def testFlagPostTwice(self):
| c = self.testFlagPost()
self.client.post(('/flag/%d/' % c.pk))
self.client.post(('/flag/%d/' % c.pk))
self.assertEqual(c.flags.filter(flag=CommentFlag.SUGGEST_REMOVAL).count(), 1)
|
'GET/POST the flag view while not logged in: redirect to log in.'
| def testFlagAnon(self):
| comments = self.createSomeComments()
pk = comments[0].pk
response = self.client.get(('/flag/%d/' % pk))
self.assertEqual(response['Location'], ('http://testserver/accounts/login/?next=/flag/%d/' % pk))
response = self.client.post(('/flag/%d/' % pk))
self.assertEqual(response['Location'], ('http:... |
'Test signals emitted by the comment flag view'
| def testFlagSignals(self):
| def receive(sender, **kwargs):
self.assertEqual(kwargs['flag'].flag, CommentFlag.SUGGEST_REMOVAL)
self.assertEqual(kwargs['request'].user.username, 'normaluser')
received_signals.append(kwargs.get('signal'))
received_signals = []
signals.comment_was_flagged.connect(receive)
self.... |
'The delete view should only be accessible to \'moderators\''
| def testDeletePermissions(self):
| comments = self.createSomeComments()
pk = comments[0].pk
self.client.login(username='normaluser', password='normaluser')
response = self.client.get(('/delete/%d/' % pk))
self.assertEqual(response['Location'], ('http://testserver/accounts/login/?next=/delete/%d/' % pk))
makeModerator('normaluser'... |
'POSTing the delete view should mark the comment as removed'
| def testDeletePost(self):
| comments = self.createSomeComments()
pk = comments[0].pk
makeModerator('normaluser')
self.client.login(username='normaluser', password='normaluser')
response = self.client.post(('/delete/%d/' % pk))
self.assertEqual(response['Location'], ('http://testserver/deleted/?c=%d' % pk))
c = Comment.... |
'The delete view should only be accessible to \'moderators\''
| def testApprovePermissions(self):
| comments = self.createSomeComments()
pk = comments[0].pk
self.client.login(username='normaluser', password='normaluser')
response = self.client.get(('/approve/%d/' % pk))
self.assertEqual(response['Location'], ('http://testserver/accounts/login/?next=/approve/%d/' % pk))
makeModerator('normaluse... |
'POSTing the delete view should mark the comment as removed'
| def testApprovePost(self):
| (c1, c2, c3, c4) = self.createSomeComments()
c1.is_public = False
c1.save()
makeModerator('normaluser')
self.client.login(username='normaluser', password='normaluser')
response = self.client.post(('/approve/%d/' % c1.pk))
self.assertEqual(response['Location'], ('http://testserver/approved/?c... |
'Tests a CommentAdmin where \'delete_selected\' has been disabled.'
| def testActionsDisabledDelete(self):
| comments = self.createSomeComments()
self.client.login(username='normaluser', password='normaluser')
response = self.client.get('/admin2/comments/comment/')
self.assertEqual(response.status_code, 200)
self.assert_(('<option value="delete_selected">' not in response.content), 'Found an unexp... |
'A formset over a ForeignKey with a to_field can be saved. Regression for #10243'
| def test_formset_over_to_field(self):
| Form = modelform_factory(User)
FormSet = inlineformset_factory(User, UserSite)
form = Form()
form_set = FormSet(instance=User())
data = {'serial': u'1', 'username': u'apollo13', 'usersite_set-TOTAL_FORMS': u'1', 'usersite_set-INITIAL_FORMS': u'0', 'usersite_set-MAX_NUM_FORMS': u'0', 'usersite_set-0-... |
'A formset over a ForeignKey with a to_field can be saved. Regression for #11120'
| def test_formset_over_inherited_model(self):
| Form = modelform_factory(Restaurant)
FormSet = inlineformset_factory(Restaurant, Manager)
form = Form()
form_set = FormSet(instance=Restaurant())
data = {'name': u"Guido's House of Pasta", 'manager_set-TOTAL_FORMS': u'1', 'manager_set-INITIAL_FORMS': u'0', 'manager_set-MAX_NUM_FORMS': u'0',... |
'A formset with instance=None can be created. Regression for #11872'
| def test_formset_with_none_instance(self):
| Form = modelform_factory(User)
FormSet = inlineformset_factory(User, UserSite)
form = Form(instance=None)
formset = FormSet(instance=None)
|
'Existing and new inlines are saved with save_as_new.
Regression for #14938.'
| def test_save_as_new_with_new_inlines(self):
| efnet = Network.objects.create(name='EFNet')
host1 = Host.objects.create(hostname='irc.he.net', network=efnet)
HostFormSet = inlineformset_factory(Network, Host)
data = {'host_set-TOTAL_FORMS': u'2', 'host_set-INITIAL_FORMS': u'1', 'host_set-MAX_NUM_FORMS': u'0', 'host_set-0-id': unicode(host1.id), 'hos... |
'Test the type of Formset and Form error attributes'
| def test_error_class(self):
| Formset = modelformset_factory(User)
data = {'form-TOTAL_FORMS': u'2', 'form-INITIAL_FORMS': u'0', 'form-MAX_NUM_FORMS': u'0', 'form-0-id': '', 'form-0-username': u'apollo13', 'form-0-serial': u'1', 'form-1-id': '', 'form-1-username': u'apollo13', 'form-1-serial': u'2'}
formset = Formset(data)
self.asse... |
'Regression test for bug #7110.
When using select_related(), we must query the
Device and Building tables using two different aliases (each) in order to
differentiate the start and end Connection fields. The net result is that
both the "connections = ..." queries here should give the same results
without pulling in mor... | def test_regression_7110(self):
| b = Building.objects.create(name='101')
dev1 = Device.objects.create(name='router', building=b)
dev2 = Device.objects.create(name='switch', building=b)
dev3 = Device.objects.create(name='server', building=b)
port1 = Port.objects.create(port_number='4', device=dev1)
port2 = Port.objects.create(po... |
'Regression test for bug #8106.
Same sort of problem as the previous test, but this time there are
more extra tables to pull in as part of the select_related() and some
of them could potentially clash (so need to be kept separate).'
| def test_regression_8106(self):
| us = TUser.objects.create(name='std')
usp = Person.objects.create(user=us)
uo = TUser.objects.create(name='org')
uop = Person.objects.create(user=uo)
s = Student.objects.create(person=usp)
o = Organizer.objects.create(person=uop)
c = Class.objects.create(org=o)
e = Enrollment.objects.cre... |
'Regression test for bug #8036
the first related model in the tests below
("state") is empty and we try to select the more remotely related
state__country. The regression here was not skipping the empty column results
for country before getting status.'
| def test_regression_8036(self):
| australia = Country.objects.create(name='Australia')
active = ClientStatus.objects.create(name='active')
client = Client.objects.create(name='client', status=active)
self.assertEquals(client.status, active)
self.assertEquals(Client.objects.select_related()[0].status, active)
self.assertEquals(Cl... |
'Exercising select_related() with multi-table model inheritance.'
| def test_multi_table_inheritance(self):
| c1 = Child.objects.create(name='child1', value=42)
i1 = Item.objects.create(name='item1', child=c1)
i2 = Item.objects.create(name='item2')
self.assertQuerysetEqual(Item.objects.select_related('child').order_by('name'), ['<Item: item1>', '<Item: item2>'])
|
'Regression for #12851
Deferred fields are used correctly if you select_related a subset
of fields.'
| def test_regression_12851(self):
| australia = Country.objects.create(name='Australia')
active = ClientStatus.objects.create(name='active')
wa = State.objects.create(name='Western Australia', country=australia)
c1 = Client.objects.create(name='Brian Burke', state=wa, status=active)
burke = Client.objects.select_related('state')... |
'If a model\'s ForeignKey has blank=False and a default, no empty option is created (Refs #10792).'
| def test_no_empty_option(self):
| option = ChoiceOptionModel.objects.create(name='default')
choices = list(ChoiceFieldForm().fields['choice'].choices)
self.assertEquals(len(choices), 1)
self.assertEquals(choices[0], (option.pk, unicode(option)))
|
'The initial value for a callable default returning a queryset is the pk (refs #13769)'
| def test_callable_initial_value(self):
| obj1 = ChoiceOptionModel.objects.create(id=1, name='default')
obj2 = ChoiceOptionModel.objects.create(id=2, name='option 2')
obj3 = ChoiceOptionModel.objects.create(id=3, name='option 3')
self.assertEquals(ChoiceFieldForm().as_p(), '<p><label for="id_choice">Choice:</label> <select name="... |
'Initial instances for model fields may also be instances (refs #7287)'
| def test_initial_instance_value(self):
| obj1 = ChoiceOptionModel.objects.create(id=1, name='default')
obj2 = ChoiceOptionModel.objects.create(id=2, name='option 2')
obj3 = ChoiceOptionModel.objects.create(id=3, name='option 3')
self.assertEquals(ChoiceFieldForm(initial={'choice': obj2, 'choice_int': obj2, 'multi_choice': [obj2, obj3], '... |
'When choices are set for this widget, we want to pass those along to the Select widget'
| def _set_choices(self, choices):
| self.widgets[0].choices = choices
|
'The choices for this widget are the Select widget\'s choices'
| def _get_choices(self):
| return self.widgets[0].choices
|
'Re-cleaning an instance that was added via a ModelForm should not raise
a pk uniqueness error.'
| def test_regression_14234(self):
| class CheeseForm(ModelForm, ):
class Meta:
model = Cheese
form = CheeseForm({'name': 'Brie'})
self.assertTrue(form.is_valid())
obj = form.save()
obj.name = 'Camembert'
obj.full_clean()
|
'TimeFields can parse dates in the default format'
| def test_timeField(self):
| f = forms.TimeField()
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
result = f.clean('13:30:05')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
self.assertEqual(text, '13:30:05')
result = f.clean('13:30')
self.assertEqual(result, time... |
'Localized TimeFields act as unlocalized widgets'
| def test_localized_timeField(self):
| f = forms.TimeField(localize=True)
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
result = f.clean('13:30:05')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
self.assertEqual(text, '13:30:05')
result = f.clean('13:30')
self.assertEqual... |
'TimeFields with manually specified input formats can accept those formats'
| def test_timeField_with_inputformat(self):
| f = forms.TimeField(input_formats=['%H.%M.%S', '%H.%M'])
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
self.assertRaises(forms.ValidationError, f.clean, '13:30:05')
result = f.clean('13.30.05')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
... |
'Localized TimeFields with manually specified input formats can accept those formats'
| def test_localized_timeField_with_inputformat(self):
| f = forms.TimeField(input_formats=['%H.%M.%S', '%H.%M'], localize=True)
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
self.assertRaises(forms.ValidationError, f.clean, '13:30:05')
result = f.clean('13.30.05')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_... |
'TimeFields can parse dates in the default format'
| def test_timeField(self):
| f = forms.TimeField()
self.assertRaises(forms.ValidationError, f.clean, '13:30:05')
result = f.clean('1:30:05 PM')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
self.assertEqual(text, '01:30:05 PM')
result = f.clean('1:30 PM')
self.assertEqual(r... |
'Localized TimeFields act as unlocalized widgets'
| def test_localized_timeField(self):
| f = forms.TimeField(localize=True)
self.assertRaises(forms.ValidationError, f.clean, '13:30:05')
result = f.clean('1:30:05 PM')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
self.assertEqual(text, '01:30:05 PM')
result = f.clean('01:30 PM')
self... |
'TimeFields with manually specified input formats can accept those formats'
| def test_timeField_with_inputformat(self):
| f = forms.TimeField(input_formats=['%H.%M.%S', '%H.%M'])
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
self.assertRaises(forms.ValidationError, f.clean, '13:30:05')
result = f.clean('13.30.05')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
... |
'Localized TimeFields with manually specified input formats can accept those formats'
| def test_localized_timeField_with_inputformat(self):
| f = forms.TimeField(input_formats=['%H.%M.%S', '%H.%M'], localize=True)
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
self.assertRaises(forms.ValidationError, f.clean, '13:30:05')
result = f.clean('13.30.05')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_... |
'TimeFields can parse dates in the default format'
| def test_timeField(self):
| f = forms.TimeField()
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
result = f.clean('13:30:05')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
self.assertEqual(text, '13:30:05')
result = f.clean('13:30')
self.assertEqual(result, time... |
'Localized TimeFields in a non-localized environment act as unlocalized widgets'
| def test_localized_timeField(self):
| f = forms.TimeField()
self.assertRaises(forms.ValidationError, f.clean, '1:30:05 PM')
result = f.clean('13:30:05')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
self.assertEqual(text, '13:30:05')
result = f.clean('13:30')
self.assertEqual(result, time... |
'TimeFields with manually specified input formats can accept those formats'
| def test_timeField_with_inputformat(self):
| f = forms.TimeField(input_formats=['%I:%M:%S %p', '%I:%M %p'])
self.assertRaises(forms.ValidationError, f.clean, '13:30:05')
result = f.clean('1:30:05 PM')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
self.assertEqual(text, '13:30:05')
result = f.c... |
'Localized TimeFields with manually specified input formats can accept those formats'
| def test_localized_timeField_with_inputformat(self):
| f = forms.TimeField(input_formats=['%I:%M:%S %p', '%I:%M %p'], localize=True)
self.assertRaises(forms.ValidationError, f.clean, '13:30:05')
result = f.clean('1:30:05 PM')
self.assertEqual(result, time(13, 30, 5))
text = f.widget._format_value(result)
self.assertEqual(text, '13:30:05')
... |
'DateFields can parse dates in the default format'
| def test_dateField(self):
| f = forms.DateField()
self.assertRaises(forms.ValidationError, f.clean, '21/12/2010')
result = f.clean('21.12.2010')
self.assertEqual(result, date(2010, 12, 21))
text = f.widget._format_value(result)
self.assertEqual(text, '21.12.2010')
result = f.clean('21.12.10')
self.assertEqual(resul... |
'Localized DateFields act as unlocalized widgets'
| def test_localized_dateField(self):
| f = forms.DateField(localize=True)
self.assertRaises(forms.ValidationError, f.clean, '21/12/2010')
result = f.clean('21.12.2010')
self.assertEqual(result, date(2010, 12, 21))
text = f.widget._format_value(result)
self.assertEqual(text, '21.12.2010')
result = f.clean('21.12.10')
self.asse... |
'DateFields with manually specified input formats can accept those formats'
| def test_dateField_with_inputformat(self):
| f = forms.DateField(input_formats=['%m.%d.%Y', '%m-%d-%Y'])
self.assertRaises(forms.ValidationError, f.clean, '2010-12-21')
self.assertRaises(forms.ValidationError, f.clean, '21/12/2010')
self.assertRaises(forms.ValidationError, f.clean, '21.12.2010')
result = f.clean('12.21.2010')
self.assertEq... |
'Localized DateFields with manually specified input formats can accept those formats'
| def test_localized_dateField_with_inputformat(self):
| f = forms.DateField(input_formats=['%m.%d.%Y', '%m-%d-%Y'], localize=True)
self.assertRaises(forms.ValidationError, f.clean, '2010-12-21')
self.assertRaises(forms.ValidationError, f.clean, '21/12/2010')
self.assertRaises(forms.ValidationError, f.clean, '21.12.2010')
result = f.clean('12.21.2010')
... |
'DateFields can parse dates in the default format'
| def test_dateField(self):
| f = forms.DateField()
self.assertRaises(forms.ValidationError, f.clean, '2010-12-21')
result = f.clean('21.12.2010')
self.assertEqual(result, date(2010, 12, 21))
text = f.widget._format_value(result)
self.assertEqual(text, '21.12.2010')
result = f.clean('21-12-2010')
self.assertEqual(res... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.