desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Tests for bug #15672 (\'request\' referenced before assignment)'
| def test_bad_path_info(self):
| environ = RequestFactory().get('/').environ
environ['PATH_INFO'] = '\xed'
handler = WSGIHandler()
response = handler(environ, (lambda *a, **k: None))
self.assertEqual(response.status_code, 400)
|
'Test the structure and content of feeds generated by Rss201rev2Feed.'
| def test_rss2_feed(self):
| response = self.client.get('/syndication/rss2/')
doc = minidom.parseString(response.content)
feed_elem = doc.getElementsByTagName('rss')
self.assertEqual(len(feed_elem), 1)
feed = feed_elem[0]
self.assertEqual(feed.getAttribute('version'), '2.0')
chan_elem = feed.getElementsByTagName('channe... |
'Test the structure and content of feeds generated by RssUserland091Feed.'
| def test_rss091_feed(self):
| response = self.client.get('/syndication/rss091/')
doc = minidom.parseString(response.content)
feed_elem = doc.getElementsByTagName('rss')
self.assertEqual(len(feed_elem), 1)
feed = feed_elem[0]
self.assertEqual(feed.getAttribute('version'), '0.91')
chan_elem = feed.getElementsByTagName('cha... |
'Test the structure and content of feeds generated by Atom1Feed.'
| def test_atom_feed(self):
| response = self.client.get('/syndication/atom/')
feed = minidom.parseString(response.content).firstChild
self.assertEqual(feed.nodeName, 'feed')
self.assertEqual(feed.getAttribute('xmlns'), 'http://www.w3.org/2005/Atom')
self.assertChildNodes(feed, ['title', 'subtitle', 'link', 'id', 'updated', 'ent... |
'Tests that titles are escaped correctly in RSS feeds.'
| def test_title_escaping(self):
| response = self.client.get('/syndication/rss2/')
doc = minidom.parseString(response.content)
for item in doc.getElementsByTagName('item'):
link = item.getElementsByTagName('link')[0]
if (link.firstChild.wholeText == 'http://example.com/blog/4/'):
title = item.getElementsByTagName... |
'Test that datetimes are correctly converted to the local time zone.'
| def test_naive_datetime_conversion(self):
| response = self.client.get('/syndication/naive-dates/')
doc = minidom.parseString(response.content)
updated = doc.getElementsByTagName('updated')[0].firstChild.wholeText
d = Entry.objects.latest('date').date
ltz = tzinfo.LocalTimezone(d)
latest = rfc3339_date(d.replace(tzinfo=ltz))
self.asse... |
'Test that datetimes with timezones don\'t get trodden on.'
| def test_aware_datetime_conversion(self):
| response = self.client.get('/syndication/aware-dates/')
doc = minidom.parseString(response.content)
updated = doc.getElementsByTagName('updated')[0].firstChild.wholeText
self.assertEqual(updated[(-6):], '+00:42')
|
'Test that the feed_url can be overridden.'
| def test_feed_url(self):
| response = self.client.get('/syndication/feedurl/')
doc = minidom.parseString(response.content)
for link in doc.getElementsByTagName('link'):
if (link.getAttribute('rel') == 'self'):
self.assertEqual(link.getAttribute('href'), 'http://example.com/customfeedurl/')
|
'Test URLs are prefixed with https:// when feed is requested over HTTPS.'
| def test_secure_urls(self):
| response = self.client.get('/syndication/rss2/', **{'wsgi.url_scheme': 'https'})
doc = minidom.parseString(response.content)
chan = doc.getElementsByTagName('channel')[0]
self.assertEqual(chan.getElementsByTagName('link')[0].firstChild.wholeText[0:5], 'https')
atom_link = chan.getElementsByTagName('... |
'Test that a ImproperlyConfigured is raised if no link could be found
for the item(s).'
| def test_item_link_error(self):
| self.assertRaises(ImproperlyConfigured, self.client.get, '/syndication/articles/')
|
'Test that the item title and description can be overridden with
templates.'
| def test_template_feed(self):
| response = self.client.get('/syndication/template/')
doc = minidom.parseString(response.content)
feed = doc.getElementsByTagName('rss')[0]
chan = feed.getElementsByTagName('channel')[0]
items = chan.getElementsByTagName('item')
self.assertChildNodeContent(items[0], {'title': 'Title in your... |
'Test add_domain() prefixes domains onto the correct URLs.'
| def test_add_domain(self):
| self.assertEqual(views.add_domain('example.com', '/foo/?arg=value'), 'http://example.com/foo/?arg=value')
self.assertEqual(views.add_domain('example.com', '/foo/?arg=value', True), 'https://example.com/foo/?arg=value')
self.assertEqual(views.add_domain('example.com', 'http://djangoproject.com/doc/'), 'http:... |
'Test that an empty feed_dict raises a 404.'
| def test_empty_feed_dict(self):
| response = self.client.get('/syndication/depr-feeds-empty/aware-dates/')
self.assertEqual(response.status_code, 404)
|
'Test that a non-existent slug raises a 404.'
| def test_nonexistent_slug(self):
| response = self.client.get('/syndication/depr-feeds/foobar/')
self.assertEqual(response.status_code, 404)
|
'A simple test for Rss201rev2Feed feeds generated by the deprecated
system.'
| def test_rss_feed(self):
| response = self.client.get('/syndication/depr-feeds/rss/')
doc = minidom.parseString(response.content)
feed = doc.getElementsByTagName('rss')[0]
self.assertEqual(feed.getAttribute('version'), '2.0')
chan = feed.getElementsByTagName('channel')[0]
self.assertChildNodes(chan, ['title', 'link', 'des... |
'Tests that the base url for a complex feed doesn\'t raise a 500
exception.'
| def test_complex_base_url(self):
| response = self.client.get('/syndication/depr-feeds/complex/')
self.assertEqual(response.status_code, 404)
|
'Regression test for #7722'
| def test_cc(self):
| email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'], cc=['cc@example.com'])
message = email.message()
self.assertEqual(message['Cc'], 'cc@example.com')
self.assertEqual(email.recipients(), ['to@example.com', 'cc@example.com'])
email = EmailMessage('Subject', 'Content', ... |
'Test for space continuation character in long (ascii) subject headers (#7747)'
| def test_space_continuation(self):
| email = EmailMessage('Long subject lines that get wrapped should use a space continuation character to get expected behaviour in Outlook and Thunderbird', 'Content', 'from@example.com', ['to@example.com'])
message = email.message()
self.assertEqual(me... |
'Specifying dates or message-ids in the extra headers overrides the
default values (#9233)'
| def test_message_header_overrides(self):
| headers = {'date': 'Fri, 09 Nov 2001 01:08:47 -0000', 'Message-ID': 'foo'}
email = EmailMessage('subject', 'content', 'from@example.com', ['to@example.com'], headers=headers)
self.assertEqual(email.message().as_string(), 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\n... |
'Make sure we can manually set the From header (#9214)'
| def test_from_header(self):
| email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
message = email.message()
self.assertEqual(message['From'], 'from@example.com')
|
'Regression for #13259 - Make sure that headers are not changed when
calling EmailMessage.message()'
| def test_multiple_message_call(self):
| email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
message = email.message()
self.assertEqual(message['From'], 'from@example.com')
message = email.message()
self.assertEqual(message['From'], 'from@example.com')
|
'Regression for #11144 - When a to/from/cc header contains unicode,
make sure the email addresses are parsed correctly (especially with
regards to commas)'
| def test_unicode_address_header(self):
| email = EmailMessage('Subject', 'Content', 'from@example.com', ['"Firstname S\xc3\xbcrname" <to@example.com>', 'other@example.com'])
self.assertEqual(email.message()['To'], '=?utf-8?q?Firstname_S=C3=BCrname?= <to@example.com>, other@example.com')
email = EmailMessage('Subject', 'Content', 'from@... |
'Make sure headers can be set with a different encoding than utf-8 in
SafeMIMEMultipart as well'
| def test_safe_mime_multipart(self):
| headers = {'Date': 'Fri, 09 Nov 2001 01:08:47 -0000', 'Message-ID': 'foo'}
(subject, from_email, to) = ('hello', 'from@example.com', '"S\xc3\xbcrname, Firstname" <to@example.com>')
text_content = 'This is an important message.'
html_content = '<p>This is an <str... |
'Regression for #12791 - Encode body correctly with other encodings
than utf-8'
| def test_encoding(self):
| email = EmailMessage('Subject', 'Firstname S\xc3\xbcrname is a great guy.', 'from@example.com', ['other@example.com'])
email.encoding = 'iso-8859-1'
message = email.message()
self.assertTrue(message.as_string().startswith('Content-Type: text/plain; charset="iso-8859-1"\nMIME-Version... |
'Regression test for #9367'
| def test_attachments(self):
| headers = {'Date': 'Fri, 09 Nov 2001 01:08:47 -0000', 'Message-ID': 'foo'}
(subject, from_email, to) = ('hello', 'from@example.com', 'to@example.com')
text_content = 'This is an important message.'
html_content = '<p>This is an <strong>important</strong> message.</... |
'Make sure that dummy backends returns correct number of sent messages'
| def test_dummy_backend(self):
| connection = dummy.EmailBackend()
email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
self.assertEqual(connection.send_messages([email, email, email]), 3)
|
'Make sure that get_connection() accepts arbitrary keyword that might be
used with custom backends.'
| def test_arbitrary_keyword(self):
| c = mail.get_connection(fail_silently=True, foo='bar')
self.assertTrue(c.fail_silently)
|
'Test custom backend defined in this suite.'
| def test_custom_backend(self):
| conn = mail.get_connection('regressiontests.mail.custombackend.EmailBackend')
self.assertTrue(hasattr(conn, 'test_outbox'))
email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
conn.send_messages([email])
self.assertEqual(len(conn... |
'Test backend argument of mail.get_connection()'
| def test_backend_arg(self):
| self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.smtp.EmailBackend'), smtp.EmailBackend))
self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.locmem.EmailBackend'), locmem.EmailBackend))
self.assertTrue(isinstance(mail.get_connection('django.core.mail.backends.... |
'Test connection argument to send_mail(), et. al.'
| @with_django_settings(EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend', ADMINS=[('nobody', 'nobody@example.com')], MANAGERS=[('nobody', 'nobody@example.com')])
def test_connection_arg(self):
| mail.outbox = []
connection = mail.get_connection('regressiontests.mail.custombackend.EmailBackend')
send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
self.assertEqual(mail.outbox, [])
self.assertEqual(len(connection.test_outbox), 1)
self.assertEqual(... |
'Test html_message argument to mail_managers'
| @with_django_settings(MANAGERS=[('nobody', 'nobody@example.com')])
def test_html_mail_managers(self):
| mail_managers('Subject', 'Content', html_message='HTML Content')
message = self.get_the_message()
self.assertEqual(message.get('subject'), '[Django] Subject')
self.assertEqual(message.get_all('to'), ['nobody@example.com'])
self.assertTrue(message.is_multipart())
self.assertEqual(len(messag... |
'Test html_message argument to mail_admins'
| @with_django_settings(ADMINS=[('nobody', 'nobody@example.com')])
def test_html_mail_admins(self):
| mail_admins('Subject', 'Content', html_message='HTML Content')
message = self.get_the_message()
self.assertEqual(message.get('subject'), '[Django] Subject')
self.assertEqual(message.get_all('to'), ['nobody@example.com'])
self.assertTrue(message.is_multipart())
self.assertEqual(len(message.... |
'String prefix + lazy translated subject = bad output
Regression for #13494'
| @with_django_settings(ADMINS=[('nobody', 'nobody+admin@example.com')], MANAGERS=[('nobody', 'nobody+manager@example.com')])
def test_manager_and_admin_mail_prefix(self):
| mail_managers(ugettext_lazy('Subject'), 'Content')
message = self.get_the_message()
self.assertEqual(message.get('subject'), '[Django] Subject')
self.flush_mailbox()
mail_admins(ugettext_lazy('Subject'), 'Content')
message = self.get_the_message()
self.assertEqual(message.get('subject'), ... |
'Test that mail_admins/mail_managers doesn\'t connect to the mail server
if there are no recipients (#9383)'
| @with_django_settings(ADMINS=(), MANAGERS=())
def test_empty_admins(self):
| mail_admins('hi', 'there')
self.assertEqual(self.get_mailbox_content(), [])
mail_managers('hi', 'there')
self.assertEqual(self.get_mailbox_content(), [])
|
'Regression test for #7722'
| def test_message_cc_header(self):
| email = EmailMessage('Subject', 'Content', 'from@example.com', ['to@example.com'], cc=['cc@example.com'])
mail.get_connection().send_messages([email])
message = self.get_the_message()
self.assertStartsWith(message.as_string(), 'Content-Type: text/plain; charset="utf-8"\nMIME-Version: 1.0\nConte... |
'Regression test for #14301'
| def test_idn_send(self):
| self.assertTrue(send_mail('Subject', 'Content', 'from@\xc3\xb6\xc3\xa4\xc3\xbc.com', [u'to@\xf6\xe4\xfc.com']))
message = self.get_the_message()
self.assertEqual(message.get('subject'), 'Subject')
self.assertEqual(message.get('from'), 'from@xn--4ca9at.com')
self.assertEqual(message.get('to'), 'to@xn... |
'Regression test for #15042'
| def test_recipient_without_domain(self):
| self.assertTrue(send_mail('Subject', 'Content', 'tester', ['django']))
message = self.get_the_message()
self.assertEqual(message.get('subject'), 'Subject')
self.assertEqual(message.get('from'), 'tester')
self.assertEqual(message.get('to'), 'django')
|
'Make sure that the locmen backend populates the outbox.'
| def test_locmem_shared_messages(self):
| connection = locmem.EmailBackend()
connection2 = locmem.EmailBackend()
email = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
connection.send_messages([email])
connection2.send_messages([email])
self.assertEqual(len(mail.outbox)... |
'Make sure opening a connection creates a new file'
| def test_file_sessions(self):
| msg = EmailMessage('Subject', 'Content', 'bounce@example.com', ['to@example.com'], headers={'From': 'from@example.com'})
connection = mail.get_connection()
connection.send_messages([msg])
self.assertEqual(len(os.listdir(self.tmp_dir)), 1)
message = email.message_from_file(open(os.path.join(self.tmp_... |
'Test that the console backend can be pointed at an arbitrary stream.'
| def test_console_stream_kwarg(self):
| s = StringIO()
connection = mail.get_connection('django.core.mail.backends.console.EmailBackend', stream=s)
send_mail('Subject', 'Content', 'from@example.com', ['to@example.com'], connection=connection)
self.assertTrue(s.getvalue().startswith('Content-Type: text/plain; charset="utf-8"\nMIME-Versio... |
'Test that a view can\'t be accidentally instantiated before deployment'
| def test_no_init_kwargs(self):
| try:
view = SimpleView(key='value').as_view()
self.fail('Should not be able to instantiate a view')
except AttributeError:
pass
|
'Test that a view can\'t be accidentally instantiated before deployment'
| def test_no_init_args(self):
| try:
view = SimpleView.as_view('value')
self.fail('Should not be able to use non-keyword arguments instantiating a view')
except TypeError:
pass
|
'The edge case of a http request that spoofs an existing method name is caught.'
| def test_pathological_http_method(self):
| self.assertEqual(SimpleView.as_view()(self.rf.get('/', REQUEST_METHOD='DISPATCH')).status_code, 405)
|
'Test a view which only allows GET doesn\'t allow other methods.'
| def test_get_only(self):
| self._assert_simple(SimpleView.as_view()(self.rf.get('/')))
self.assertEqual(SimpleView.as_view()(self.rf.post('/')).status_code, 405)
self.assertEqual(SimpleView.as_view()(self.rf.get('/', REQUEST_METHOD='FAKE')).status_code, 405)
|
'Test a view which only allows both GET and POST.'
| def test_get_and_post(self):
| self._assert_simple(SimplePostView.as_view()(self.rf.get('/')))
self._assert_simple(SimplePostView.as_view()(self.rf.post('/')))
self.assertEqual(SimplePostView.as_view()(self.rf.get('/', REQUEST_METHOD='FAKE')).status_code, 405)
|
'Test that view arguments must be predefined on the class and can\'t
be named like a HTTP method.'
| def test_invalid_keyword_argument(self):
| for method in SimpleView.http_method_names:
kwargs = dict(((method, 'value'),))
self.assertRaises(TypeError, SimpleView.as_view, **kwargs)
CustomizableView.as_view(parameter='value')
self.assertRaises(TypeError, CustomizableView.as_view, foobar='value')
|
'Test a view can only be called once.'
| def test_calling_more_than_once(self):
| request = self.rf.get('/')
view = InstanceView.as_view()
self.assertNotEqual(view(request), view(request))
|
'Test that the callable returned from as_view() has proper
docstring, name and module.'
| def test_class_attributes(self):
| self.assertEqual(SimpleView.__doc__, SimpleView.as_view().__doc__)
self.assertEqual(SimpleView.__name__, SimpleView.as_view().__name__)
self.assertEqual(SimpleView.__module__, SimpleView.as_view().__module__)
|
'Test that attributes set by decorators on the dispatch method
are also present on the closure.'
| def test_dispatch_decoration(self):
| self.assertTrue(DecoratedDispatchView.as_view().is_decorated)
|
'Test a view that simply renders a template on GET'
| def test_get(self):
| self._assert_about(AboutTemplateView.as_view()(self.rf.get('/about/')))
|
'Test a view that renders a template on GET with the template name as
an attribute on the class.'
| def test_get_template_attribute(self):
| self._assert_about(AboutTemplateAttributeView.as_view()(self.rf.get('/about/')))
|
'Test a completely generic view that renders a template on GET
with the template name as an argument at instantiation.'
| def test_get_generic_template(self):
| self._assert_about(TemplateView.as_view(template_name='generic_views/about.html')(self.rf.get('/about/')))
|
'A template view must provide a template name'
| def test_template_name_required(self):
| self.assertRaises(ImproperlyConfigured, self.client.get, '/template/no_template/')
|
'A generic template view passes kwargs as context.'
| def test_template_params(self):
| response = self.client.get('/template/simple/bar/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['params'], {'foo': 'bar'})
|
'A template view can be customized to return extra context.'
| def test_extra_template_params(self):
| response = self.client.get('/template/custom/bar/')
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['params'], {'foo': 'bar'})
self.assertEqual(response.context['key'], 'value')
|
'A template view can be cached'
| def test_cached_views(self):
| response = self.client.get('/template/cached/bar/')
self.assertEqual(response.status_code, 200)
time.sleep(1.0)
response2 = self.client.get('/template/cached/bar/')
self.assertEqual(response2.status_code, 200)
self.assertEqual(response.content, response2.content)
time.sleep(2.0)
response... |
'Without any configuration, returns HTTP 410 GONE'
| def test_no_url(self):
| response = RedirectView.as_view()(self.rf.get('/foo/'))
self.assertEqual(response.status_code, 410)
|
'Default is a permanent redirect'
| def test_permanaent_redirect(self):
| response = RedirectView.as_view(url='/bar/')(self.rf.get('/foo/'))
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/')
|
'Permanent redirects are an option'
| def test_temporary_redirect(self):
| response = RedirectView.as_view(url='/bar/', permanent=False)(self.rf.get('/foo/'))
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'], '/bar/')
|
'GET arguments can be included in the redirected URL'
| def test_include_args(self):
| response = RedirectView.as_view(url='/bar/')(self.rf.get('/foo/'))
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/')
response = RedirectView.as_view(url='/bar/', query_string=True)(self.rf.get('/foo/?pork=spam'))
self.assertEqual(response.status_code, 301)
... |
'Redirection URLs can be parameterized'
| def test_parameter_substitution(self):
| response = RedirectView.as_view(url='/bar/%(object_id)d/')(self.rf.get('/foo/42/'), object_id=42)
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/42/')
|
'Default is a permanent redirect'
| def test_redirect_POST(self):
| response = RedirectView.as_view(url='/bar/')(self.rf.post('/foo/'))
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/')
|
'Default is a permanent redirect'
| def test_redirect_HEAD(self):
| response = RedirectView.as_view(url='/bar/')(self.rf.head('/foo/'))
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/')
|
'Default is a permanent redirect'
| def test_redirect_OPTIONS(self):
| response = RedirectView.as_view(url='/bar/')(self.rf.options('/foo/'))
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/')
|
'Default is a permanent redirect'
| def test_redirect_PUT(self):
| response = RedirectView.as_view(url='/bar/')(self.rf.put('/foo/'))
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/')
|
'Default is a permanent redirect'
| def test_redirect_DELETE(self):
| response = RedirectView.as_view(url='/bar/')(self.rf.delete('/foo/'))
self.assertEqual(response.status_code, 301)
self.assertEqual(response['Location'], '/bar/')
|
'Content can exist on any day of the previous month. Refs #14711'
| def test_previous_month_without_content(self):
| self.pubdate_list = [datetime.date(2010, month, day) for (month, day) in ((9, 1), (10, 2), (11, 3))]
for pubdate in self.pubdate_list:
name = str(pubdate)
Book.objects.create(name=name, slug=name, pages=100, pubdate=pubdate)
res = self.client.get('/dates/books/2010/nov/allow_empty/')
sel... |
'Uploaded file names should be sanitized before ever reaching the view.'
| def test_dangerous_file_names(self):
| scary_file_names = ['/tmp/hax0rd.txt', 'C:\\Windows\\hax0rd.txt', 'C:/Windows/hax0rd.txt', '\\tmp\\hax0rd.txt', '/tmp\\hax0rd.txt', 'subdir/hax0rd.txt', 'subdir\\hax0rd.txt', 'sub/dir\\hax0rd.txt', '../../hax0rd.txt', '..\\..\\hax0rd.txt', '../..\\hax0rd.txt']
payload = []
for (i, name) in enumerate(scary_f... |
'File names over 256 characters (dangerous on some platforms) get fixed up.'
| def test_filename_overflow(self):
| name = ('%s.txt' % ('f' * 500))
payload = '\r\n'.join([('--' + client.BOUNDARY), ('Content-Disposition: form-data; name="file"; filename="%s"' % name), 'Content-Type: application/octet-stream', '', (('Oops.--' + client.BOUNDARY) + '--'), ''])
r = {'CONTENT_LENGTH': len(payload), 'CONTENT_TYPE': ... |
'The server should not block when there are upload errors (bug #8622).
This can happen if something -- i.e. an exception handler -- tries to
access POST while handling an error in parsing POST. This shouldn\'t
cause an infinite loop!'
| def test_file_error_blocking(self):
| class POSTAccessingHandler(client.ClientHandler, ):
"A handler that'll access POST during an exception."
def handle_uncaught_exception(self, request, resolver, exc_info):
ret = super(POSTAccessingHandler, self).handle_uncaught_exception(request, resolver, exc_info)
... |
'Permission errors are not swallowed'
| def test_readonly_root(self):
| os.chmod(temp_storage.location, 320)
try:
self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x'))
except OSError as err:
self.assertEqual(err.errno, errno.EACCES)
except Exception as err:
self.fail(('OSError [Errno %s] not raised.' % errno.EACCES))
|
'The correct IOError is raised when the upload directory name exists but isn\'t a directory'
| def test_not_a_directory(self):
| fd = open(UPLOAD_TO, 'w')
fd.close()
try:
self.obj.testfile.save('foo.txt', SimpleUploadedFile('foo.txt', 'x'))
except IOError as err:
self.assertEqual(err.args[0], ('%s exists and is not a directory.' % UPLOAD_TO))
except:
self.fail('IOError not raise... |
'Returns the URL for this guitarist.'
| @models.permalink
def url(self):
| return ('guitarist_detail', [self.slug])
|
'Methods using the @permalink decorator retain their docstring.'
| def test_wrapped_docstring(self):
| g = Guitarist(name='Adrien Moignard', slug='adrienmoignard')
self.assertEqual(g.url.__doc__, 'Returns the URL for this guitarist.')
|
'Deletes on concurrent transactions don\'t collide and lock the database. Regression for #9479'
| @skipUnlessDBFeature('test_db_allows_multiple_connections')
def test_concurrent_delete(self):
| b1 = Book(id=1, pagecount=100)
b2 = Book(id=2, pagecount=200)
b3 = Book(id=3, pagecount=300)
b1.save()
b2.save()
b3.save()
transaction.commit()
self.assertEqual(3, Book.objects.count())
cursor2 = self.conn2.cursor()
cursor2.execute('DELETE from delete_regress_book WHERE ... |
'Django cascades deletes through generic-related objects to their
reverse relations.'
| def test_generic_relation_cascade(self):
| person = Person.objects.create(name='Nelson Mandela')
award = Award.objects.create(name='Nobel', content_object=person)
note = AwardNote.objects.create(note='a peace prize', award=award)
self.assertEqual(AwardNote.objects.count(), 1)
person.delete()
self.assertEqual(Award.objects.count(... |
'If an M2M relationship has an explicitly-specified through model, and
some other model has an FK to that through model, deletion is cascaded
from one of the participants in the M2M, to the through model, to its
related model.'
| def test_fk_to_m2m_through(self):
| juan = Child.objects.create(name='Juan')
paints = Toy.objects.create(name='Paints')
played = PlayedWith.objects.create(child=juan, toy=paints, date=datetime.date.today())
note = PlayedWithNote.objects.create(played=played, note='the next Jackson Pollock')
self.assertEqual(PlayedWithNote.obj... |
'Auto-created many-to-many through tables referencing a parent model are
correctly found by the delete cascade when a child of that parent is
deleted.
Refs #14896.'
| def test_inheritance(self):
| r = Researcher.objects.create()
email = Email.objects.create(label='office-email', email_address='carl@science.edu')
r.contacts.add(email)
email.delete()
|
'Cascade deletion works with ForeignKey.to_field set to non-PK.'
| def test_to_field(self):
| apple = Food.objects.create(name='apple')
eaten = Eaten.objects.create(food=apple, meal='lunch')
apple.delete()
|
'Regression for #13309 -- if the number of objects > chunk size, deletion still occurs'
| def test_large_deletes(self):
| for x in range(300):
track = Book.objects.create(pagecount=(x + 100))
Book.objects.all().delete()
self.assertEqual(Book.objects.count(), 0)
|
'Models module can be loaded from an app in an egg'
| def test_egg1(self):
| egg_name = ('%s/modelapp.egg' % self.egg_dir)
sys.path.append(egg_name)
models = load_app('app_with_models')
self.assertFalse((models is None))
|
'Loading an app from an egg that has no models returns no models (and no error)'
| def test_egg2(self):
| egg_name = ('%s/nomodelapp.egg' % self.egg_dir)
sys.path.append(egg_name)
models = load_app('app_no_models')
self.assertTrue((models is None))
|
'Models module can be loaded from an app located under an egg\'s top-level package'
| def test_egg3(self):
| egg_name = ('%s/omelet.egg' % self.egg_dir)
sys.path.append(egg_name)
models = load_app('omelet.app_with_models')
self.assertFalse((models is None))
|
'Loading an app with no models from under the top-level egg package generates no error'
| def test_egg4(self):
| egg_name = ('%s/omelet.egg' % self.egg_dir)
sys.path.append(egg_name)
models = load_app('omelet.app_no_models')
self.assertTrue((models is None))
|
'Loading an app from an egg that has an import error in its models module raises that error'
| def test_egg5(self):
| egg_name = ('%s/brokenapp.egg' % self.egg_dir)
sys.path.append(egg_name)
self.assertRaises(ImportError, load_app, 'broken_app')
try:
load_app('broken_app')
except ImportError as e:
self.assertTrue(('modelz' in e.args[0]))
|
'The default ordering should be by name, as specified in the inner Meta
class.'
| def test_default_ordering(self):
| ma = ModelAdmin(Band, None)
names = [b.name for b in ma.queryset(None)]
self.assertEqual([u'Aerosmith', u'Radiohead', u'Van Halen'], names)
|
'Let\'s use a custom ModelAdmin that changes the ordering, and make sure
it actually changes.'
| def test_specified_ordering(self):
| class BandAdmin(ModelAdmin, ):
ordering = ('rank',)
ma = BandAdmin(Band, None)
names = [b.name for b in ma.queryset(None)]
self.assertEqual([u'Radiohead', u'Van Halen', u'Aerosmith'], names)
|
'The default ordering should be by name, as specified in the inner Meta
class.'
| def test_default_ordering(self):
| inline = SongInlineDefaultOrdering(self.b, None)
names = [s.name for s in inline.queryset(None)]
self.assertEqual([u'Dude (Looks Like a Lady)', u'Jaded', u'Pink'], names)
|
'Let\'s check with ordering set to something different than the default.'
| def test_specified_ordering(self):
| inline = SongInlineNewOrdering(self.b, None)
names = [s.name for s in inline.queryset(None)]
self.assertEqual([u'Jaded', u'Pink', u'Dude (Looks Like a Lady)'], names)
|
'Regression test for #6755'
| def test_issue_6755(self):
| r = Restaurant(serves_pizza=False)
r.save()
self.assertEqual(r.id, r.place_ptr_id)
orig_id = r.id
r = Restaurant(place_ptr_id=orig_id, serves_pizza=True)
r.save()
self.assertEqual(r.id, orig_id)
self.assertEqual(r.id, r.place_ptr_id)
|
'Regression test for #11764'
| def test_issue_11764(self):
| wholesalers = list(Wholesaler.objects.all().select_related())
self.assertEqual(wholesalers, [])
|
'Regression test for #7853
If the parent class has a self-referential link, make sure that any
updates to that link via the child update the right table.'
| def test_issue_7853(self):
| obj = SelfRefChild.objects.create(child_data=37, parent_data=42)
obj.delete()
|
'Regression tests for #8076
get_(next/previous)_by_date should work'
| def test_get_next_previous_by_date(self):
| c1 = ArticleWithAuthor(headline='ArticleWithAuthor 1', author='Person 1', pub_date=datetime.datetime(2005, 8, 1, 3, 0))
c1.save()
c2 = ArticleWithAuthor(headline='ArticleWithAuthor 2', author='Person 2', pub_date=datetime.datetime(2005, 8, 1, 10, 0))
c2.save()
c3 = ArticleWithAuthor(head... |
'Regression test for #8825 and #9390
Make sure all inherited fields (esp. m2m fields, in this case) appear
on the child class.'
| def test_inherited_fields(self):
| m2mchildren = list(M2MChild.objects.filter(articles__isnull=False))
self.assertEqual(m2mchildren, [])
qs = ArticleWithAuthor.objects.order_by('pub_date', 'pk')
sql = qs.query.get_compiler(qs.db).as_sql()[0]
fragment = sql[sql.find('ORDER BY'):]
pos = fragment.find('pub_date')
self.assertE... |
'Regression test for #10362
It is possible to call update() and only change a field in
an ancestor model.'
| def test_queryset_update_on_parent_model(self):
| article = ArticleWithAuthor.objects.create(author='fred', headline='Hey there!', pub_date=datetime.datetime(2009, 3, 1, 8, 0, 0))
update = ArticleWithAuthor.objects.filter(author='fred').update(headline='Oh, no!')
self.assertEqual(update, 1)
update = ArticleWithAuthor.objects.filter(pk=article.pk)... |
'Regression tests for #10406
If there\'s a one-to-one link between a child model and the parent and
no explicit pk declared, we can use the one-to-one link as the pk on
the child.'
| def test_use_explicit_o2o_to_parent_as_pk(self):
| self.assertEqual(ParkingLot2._meta.pk.name, 'parent')
self.assertEqual(ParkingLot3._meta.pk.name, 'primary_key')
self.assertEqual(ParkingLot3._meta.get_ancestor_link(Place).name, 'parent')
|
'Regression tests for #7588'
| def test_all_fields_from_abstract_base_class(self):
| QualityControl.objects.create(headline='Problems in Django', pub_date=datetime.datetime.now(), quality=10, assignee='adrian')
|
'verbose_name_plural correctly inherited from ABC if inheritance chain
includes an abstract model.'
| def test_abstract_verbose_name_plural_inheritance(self):
| self.assertEqual(InternalCertificationAudit._meta.verbose_name_plural, u'Audits')
|
'Primary key set correctly with concrete->abstract->concrete inheritance.'
| def test_concrete_abstract_concrete_pk(self):
| self.assertEqual(len([field for field in BusStation._meta.local_fields if field.primary_key]), 1)
self.assertEqual(len([field for field in TrainStation._meta.local_fields if field.primary_key]), 1)
self.assertIs(BusStation._meta.pk.model, BusStation)
self.assertIs(TrainStation._meta.pk.model, TrainStati... |
'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>'])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.