desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'alternate: manage.py builtin commands fail with an import error when no default settings provided'
| def test_builtin_command(self):
| args = ['sqlall', 'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
'alternate: manage.py builtin commands fail if settings are provided as argument but no defaults'
| def test_builtin_with_settings(self):
| args = ['sqlall', '--settings=alternate_settings', 'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
'alternate: manage.py builtin commands fail if settings are provided in the environment but no defaults'
| def test_builtin_with_environment(self):
| args = ['sqlall', 'admin_scripts']
(out, err) = self.run_manage(args, 'alternate_settings')
self.assertNoOutput(out)
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
'alternate: manage.py builtin commands fail if settings file (from argument) doesn\'t exist'
| def test_builtin_with_bad_settings(self):
| args = ['sqlall', '--settings=bad_settings', 'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
'alternate: manage.py builtin commands fail if settings file (from environment) doesn\'t exist'
| def test_builtin_with_bad_environment(self):
| args = ['sqlall', 'admin_scripts']
(out, err) = self.run_manage(args, 'bad_settings')
self.assertNoOutput(out)
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
'alternate: manage.py can\'t execute user commands'
| def test_custom_command(self):
| args = ['noargs_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
'alternate: manage.py can\'t execute user commands, even if settings are provided as argument'
| def test_custom_command_with_settings(self):
| args = ['noargs_command', '--settings=alternate_settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
'alternate: manage.py can\'t execute user commands, even if settings are provided in environment'
| def test_custom_command_with_environment(self):
| args = ['noargs_command']
(out, err) = self.run_manage(args, 'alternate_settings')
self.assertNoOutput(out)
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
'multiple: manage.py builtin commands fail with an import error when no settings provided'
| def test_builtin_command(self):
| args = ['sqlall', 'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, 'App with label admin_scripts could not be found.')
|
'multiple: manage.py builtin commands succeed if settings are provided as argument'
| def test_builtin_with_settings(self):
| args = ['sqlall', '--settings=alternate_settings', 'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, 'CREATE TABLE')
|
'multiple: manage.py builtin commands fail if settings are provided in the environment'
| def test_builtin_with_environment(self):
| args = ['sqlall', 'admin_scripts']
(out, err) = self.run_manage(args, 'alternate_settings')
self.assertNoOutput(out)
self.assertOutput(err, 'App with label admin_scripts could not be found.')
|
'multiple: manage.py builtin commands fail if settings file (from argument) doesn\'t exist'
| def test_builtin_with_bad_settings(self):
| args = ['sqlall', '--settings=bad_settings', 'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, "Could not import settings 'bad_settings'")
|
'multiple: manage.py builtin commands fail if settings file (from environment) doesn\'t exist'
| def test_builtin_with_bad_environment(self):
| args = ['sqlall', 'admin_scripts']
(out, err) = self.run_manage(args, 'bad_settings')
self.assertNoOutput(out)
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
'multiple: manage.py can\'t execute user commands using default settings'
| def test_custom_command(self):
| args = ['noargs_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
'multiple: manage.py can execute user commands if settings are provided as argument'
| def test_custom_command_with_settings(self):
| args = ['noargs_command', '--settings=alternate_settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, 'EXECUTE:NoArgsCommand')
|
'multiple: manage.py can execute user commands if settings are provided in environment'
| def test_custom_command_with_environment(self):
| args = ['noargs_command']
(out, err) = self.run_manage(args, 'alternate_settings')
self.assertNoOutput(out)
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
'manage.py validate reports an error on a non-existent app in INSTALLED_APPS'
| def test_nonexistent_app(self):
| self.write_settings('settings.py', apps=['admin_scriptz.broken_app'], sdict={'USE_I18N': False})
args = ['validate']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, 'No module named admin_scriptz')
|
'manage.py validate reports an ImportError if an app\'s models.py raises one on import'
| def test_broken_app(self):
| self.write_settings('settings.py', apps=['admin_scripts.broken_app'])
args = ['validate']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, 'ImportError')
|
'manage.py validate does not raise an ImportError validating a complex app with nested calls to load_app'
| def test_complex_app(self):
| self.write_settings('settings.py', apps=['admin_scripts.complex_app', 'admin_scripts.simple_app'], sdict={'DEBUG': True})
args = ['validate']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, '0 errors found')
|
'manage.py validate does not raise errors when an app imports a base class that itself has an abstract base'
| def test_app_with_import(self):
| self.write_settings('settings.py', apps=['admin_scripts.app_with_import', 'django.contrib.comments'], sdict={'DEBUG': True})
args = ['validate']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, '0 errors found')
|
'--version is handled as a special case'
| def test_version(self):
| args = ['--version']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, get_version().split('-')[0])
|
'--help is handled as a special case'
| def test_help(self):
| args = ['--help']
(out, err) = self.run_manage(args)
if (sys.version_info < (2, 5)):
self.assertOutput(out, 'usage: manage.py subcommand [options] [args]')
else:
self.assertOutput(out, 'Usage: manage.py subcommand [options] [args]')
self.assertOutput(err, "Typ... |
'--help can be used on a specific command'
| def test_specific_help(self):
| args = ['sqlall', '--help']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, 'Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).')
|
'User BaseCommands can execute when a label is provided'
| def test_base_command(self):
| args = ['base_command', 'testlabel']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None),... |
'User BaseCommands can execute when no labels are provided'
| def test_base_command_no_label(self):
| args = ['base_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=(), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None... |
'User BaseCommands can execute when no labels are provided'
| def test_base_command_multiple_label(self):
| args = ['base_command', 'testlabel', 'anotherlabel']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel', 'anotherlabel'), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', ... |
'User BaseCommands can execute with options when a label is provided'
| def test_base_command_with_option(self):
| args = ['base_command', 'testlabel', '--option_a=x']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('sett... |
'User BaseCommands can execute with multiple options when a label is provided'
| def test_base_command_with_options(self):
| args = ['base_command', 'testlabel', '-a', 'x', '--option_b=y']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None)... |
'NoArg Commands can be executed'
| def test_noargs(self):
| args = ['noargs_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:NoArgsCommand options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'NoArg Commands raise an error if an argument is provided'
| def test_noargs_with_args(self):
| args = ['noargs_command', 'argument']
(out, err) = self.run_manage(args)
self.assertOutput(err, "Error: Command doesn't accept any arguments")
|
'User AppCommands can execute when a single app name is provided'
| def test_app_command(self):
| args = ['app_command', 'auth']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
self.assertOutput(out, os.sep.join(['django', 'contrib', 'auth', 'models.py']))
self.assertOutput(out, "'>, op... |
'User AppCommands raise an error when no app name is provided'
| def test_app_command_no_apps(self):
| args = ['app_command']
(out, err) = self.run_manage(args)
self.assertOutput(err, 'Error: Enter at least one appname.')
|
'User AppCommands raise an error when multiple app names are provided'
| def test_app_command_multiple_apps(self):
| args = ['app_command', 'auth', 'contenttypes']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
self.assertOutput(out, os.sep.join(['django', 'contrib', 'auth', 'models.py']))
self.assertOutput... |
'User AppCommands can execute when a single app name is provided'
| def test_app_command_invalid_appname(self):
| args = ['app_command', 'NOT_AN_APP']
(out, err) = self.run_manage(args)
self.assertOutput(err, 'App with label NOT_AN_APP could not be found')
|
'User AppCommands can execute when some of the provided app names are invalid'
| def test_app_command_some_invalid_appnames(self):
| args = ['app_command', 'auth', 'NOT_AN_APP']
(out, err) = self.run_manage(args)
self.assertOutput(err, 'App with label NOT_AN_APP could not be found')
|
'User LabelCommands can execute when a label is provided'
| def test_label_command(self):
| args = ['label_command', 'testlabel']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:LabelCommand label=testlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'User LabelCommands raise an error if no label is provided'
| def test_label_command_no_label(self):
| args = ['label_command']
(out, err) = self.run_manage(args)
self.assertOutput(err, 'Enter at least one label')
|
'User LabelCommands are executed multiple times if multiple labels are provided'
| def test_label_command_multiple_label(self):
| args = ['label_command', 'testlabel', 'anotherlabel']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:LabelCommand label=testlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
sel... |
'Options passed after settings are correctly handled'
| def test_setting_then_option(self):
| args = ['base_command', 'testlabel', '--settings=alternate_settings', '--option_a=x']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), (... |
'Short options passed after settings are correctly handled'
| def test_setting_then_short_option(self):
| args = ['base_command', 'testlabel', '--settings=alternate_settings', '--option_a=x']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), (... |
'Options passed before settings are correctly handled'
| def test_option_then_setting(self):
| args = ['base_command', 'testlabel', '--option_a=x', '--settings=alternate_settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), (... |
'Short options passed before settings are correctly handled'
| def test_short_option_then_setting(self):
| args = ['base_command', 'testlabel', '-a', 'x', '--settings=alternate_settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pyth... |
'Options are correctly handled when they are passed before and after a setting'
| def test_option_then_setting_then_option(self):
| args = ['base_command', 'testlabel', '--option_a=x', '--settings=alternate_settings', '--option_b=y']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c... |
'When no prior CSRF cookie exists, check that the cookie is created and a
token is inserted.'
| def test_process_response_no_csrf_cookie(self):
| req = self._get_GET_no_csrf_cookie_request()
CsrfMiddleware().process_view(req, post_form_view, (), {})
resp = post_form_response()
resp_content = resp.content
resp2 = CsrfMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, False)
self.assertNo... |
'Check that a view decorated with \'csrf_view_exempt\' is still
post-processed to add the CSRF token.'
| def test_process_response_for_exempt_view(self):
| req = self._get_GET_no_csrf_cookie_request()
CsrfMiddleware().process_view(req, csrf_view_exempt(post_form_view), (), {})
resp = post_form_response()
resp_content = resp.content
resp2 = CsrfMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, False)... |
'When no prior CSRF cookie exists, check that the cookie is created, even
if only CsrfViewMiddleware is used.'
| def test_process_response_no_csrf_cookie_view_only_get_token_used(self):
| req = self._get_GET_no_csrf_cookie_request()
CsrfViewMiddleware().process_view(req, token_view, (), {})
resp = token_view(req)
resp2 = CsrfViewMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, False)
self.assertNotEqual(csrf_cookie, False)
|
'Check that if get_token() is not called, the view middleware does not
add a cookie.'
| def test_process_response_get_token_not_used(self):
| req = self._get_GET_no_csrf_cookie_request()
CsrfViewMiddleware().process_view(req, non_token_view_using_request_processor, (), {})
resp = non_token_view_using_request_processor(req)
resp2 = CsrfViewMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(settings.CSRF_COOKIE_NAME, F... |
'Check that the token is inserted when a prior CSRF cookie exists'
| def test_process_response_existing_csrf_cookie(self):
| req = self._get_GET_csrf_cookie_request()
CsrfMiddleware().process_view(req, post_form_view, (), {})
resp = post_form_response()
resp_content = resp.content
resp2 = CsrfMiddleware().process_response(req, resp)
self.assertNotEqual(resp_content, resp2.content)
self._check_token_present(resp2)
|
'Check the the post-processor does nothing for content-types not in _HTML_TYPES.'
| def test_process_response_non_html(self):
| req = self._get_GET_no_csrf_cookie_request()
CsrfMiddleware().process_view(req, post_form_view, (), {})
resp = post_form_response_non_html()
resp_content = resp.content
resp2 = CsrfMiddleware().process_response(req, resp)
self.assertEquals(resp_content, resp2.content)
|
'Check that no post processing is done for an exempt view'
| def test_process_response_exempt_view(self):
| req = self._get_GET_csrf_cookie_request()
view = csrf_exempt(post_form_view)
CsrfMiddleware().process_view(req, view, (), {})
resp = view(req)
resp_content = resp.content
resp2 = CsrfMiddleware().process_response(req, resp)
self.assertEquals(resp_content, resp2.content)
|
'Check that if neither a CSRF cookie nor a session cookie are present,
the middleware rejects the incoming request. This will stop login CSRF.'
| def test_process_request_no_session_no_csrf_cookie(self):
| req = self._get_POST_no_csrf_cookie_request()
req2 = CsrfMiddleware().process_view(req, post_form_view, (), {})
self.assertEquals(403, req2.status_code)
|
'Check that if a CSRF cookie is present but no token, the middleware
rejects the incoming request.'
| def test_process_request_csrf_cookie_no_token(self):
| req = self._get_POST_csrf_cookie_request()
req2 = CsrfMiddleware().process_view(req, post_form_view, (), {})
self.assertEquals(403, req2.status_code)
|
'Check that if both a cookie and a token is present, the middleware lets it through.'
| def test_process_request_csrf_cookie_and_token(self):
| req = self._get_POST_request_with_token()
req2 = CsrfMiddleware().process_view(req, post_form_view, (), {})
self.assertEquals(None, req2)
|
'When no CSRF cookie exists, but the user has a session, check that a token
using the session cookie as a legacy CSRF cookie is accepted.'
| def test_process_request_session_cookie_no_csrf_cookie_token(self):
| orig_secret_key = settings.SECRET_KEY
settings.SECRET_KEY = self._secret_key_for_session_test
try:
req = self._get_POST_session_request_with_token()
req2 = CsrfMiddleware().process_view(req, post_form_view, (), {})
self.assertEquals(None, req2)
finally:
settings.SECRET_KE... |
'Check that if a session cookie is present but no token and no CSRF cookie,
the request is rejected.'
| def test_process_request_session_cookie_no_csrf_cookie_no_token(self):
| req = self._get_POST_session_request_no_token()
req2 = CsrfMiddleware().process_view(req, post_form_view, (), {})
self.assertEquals(403, req2.status_code)
|
'Check that if a CSRF cookie is present and no token, but the csrf_exempt
decorator has been applied to the view, the middleware lets it through'
| def test_process_request_csrf_cookie_no_token_exempt_view(self):
| req = self._get_POST_csrf_cookie_request()
req2 = CsrfMiddleware().process_view(req, csrf_exempt(post_form_view), (), {})
self.assertEquals(None, req2)
|
'Check that we can pass in the token in a header instead of in the form'
| def test_csrf_token_in_header(self):
| req = self._get_POST_csrf_cookie_request()
req.META['HTTP_X_CSRFTOKEN'] = self._csrf_id
req2 = CsrfMiddleware().process_view(req, post_form_view, (), {})
self.assertEquals(None, req2)
|
'Check that CsrfTokenNode works when no CSRF cookie is set'
| def test_token_node_no_csrf_cookie(self):
| req = self._get_GET_no_csrf_cookie_request()
resp = token_view(req)
self.assertEquals(u'', resp.content)
|
'Check that we get a new token if the csrf_cookie is the empty string'
| def test_token_node_empty_csrf_cookie(self):
| req = self._get_GET_no_csrf_cookie_request()
req.COOKIES[settings.CSRF_COOKIE_NAME] = ''
CsrfViewMiddleware().process_view(req, token_view, (), {})
resp = token_view(req)
self.assertNotEqual(u'', resp.content)
|
'Check that CsrfTokenNode works when a CSRF cookie is set'
| def test_token_node_with_csrf_cookie(self):
| req = self._get_GET_csrf_cookie_request()
CsrfViewMiddleware().process_view(req, token_view, (), {})
resp = token_view(req)
self._check_token_present(resp)
|
'Check that get_token still works for a view decorated with \'csrf_view_exempt\'.'
| def test_get_token_for_exempt_view(self):
| req = self._get_GET_csrf_cookie_request()
CsrfViewMiddleware().process_view(req, csrf_view_exempt(token_view), (), {})
resp = token_view(req)
self._check_token_present(resp)
|
'Check that get_token works for a view decorated solely with requires_csrf_token'
| def test_get_token_for_requires_csrf_token_view(self):
| req = self._get_GET_csrf_cookie_request()
resp = requires_csrf_token(token_view)(req)
self._check_token_present(resp)
|
'Check that CsrfTokenNode works when a CSRF cookie is created by
the middleware (when one was not already present)'
| def test_token_node_with_new_csrf_cookie(self):
| req = self._get_GET_no_csrf_cookie_request()
CsrfViewMiddleware().process_view(req, token_view, (), {})
resp = token_view(req)
resp2 = CsrfViewMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies[settings.CSRF_COOKIE_NAME]
self._check_token_present(resp, csrf_id=csrf_cookie.value... |
'Check that CsrfResponseMiddleware finishes without error if the view middleware
has not been called, as is the case if a request middleware returns a response.'
| def test_response_middleware_without_view_middleware(self):
| req = self._get_GET_no_csrf_cookie_request()
resp = post_form_view(req)
CsrfMiddleware().process_response(req, resp)
|
'Test that a POST HTTPS request with a bad referer is rejected'
| def test_https_bad_referer(self):
| req = self._get_POST_request_with_token()
req._is_secure = True
req.META['HTTP_HOST'] = 'www.example.com'
req.META['HTTP_REFERER'] = 'https://www.evil.org/somepage'
req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {})
self.assertNotEqual(None, req2)
self.assertEquals(403, re... |
'Test that a POST HTTPS request with a good referer is accepted'
| def test_https_good_referer(self):
| req = self._get_POST_request_with_token()
req._is_secure = True
req.META['HTTP_HOST'] = 'www.example.com'
req.META['HTTP_REFERER'] = 'https://www.example.com/somepage'
req2 = CsrfViewMiddleware().process_view(req, post_form_view, (), {})
self.assertEquals(None, req2)
|
'Year boundary tests (ticket #3689)'
| def test_year_boundaries(self):
| d = Donut.objects.create(name='Date Test 2007', baked_date=datetime.datetime(year=2007, month=12, day=31), consumed_at=datetime.datetime(year=2007, month=12, day=31, hour=23, minute=59, second=59))
d1 = Donut.objects.create(name='Date Test 2006', baked_date=datetime.datetime(year=2006, month=1, day=... |
'Regression test for #10238: TextField values returned from the
database should be unicode.'
| def test_textfields_unicode(self):
| d = Donut.objects.create(name=u'Jelly Donut', review=u'Outstanding')
newd = Donut.objects.get(id=d.id)
self.assert_(isinstance(newd.review, unicode))
|
'Regression test for #8354: the MySQL backend should raise an error
if given a timezone-aware datetime object.'
| def test_tz_awareness_mysql(self):
| if (settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] == 'django.db.backends.mysql'):
dt = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(0))
d = Donut(name='Bear claw', consumed_at=dt)
self.assertRaises(ValueError, d.save)
|
'Regression test for #10970, auto_now_add for DateField should store
a Python datetime.date, not a datetime.datetime'
| def test_datefield_auto_now_add(self):
| b = RumBaba.objects.create()
self.assert_(isinstance(b.baked_timestamp, datetime.datetime))
self.assert_((isinstance(b.baked_date, datetime.date) and (not isinstance(b.baked_date, datetime.datetime))))
|
'Regression test for #1661 and #1662
Check that string form referencing of
models works, both as pre and post reference, on all RelatedField types.'
| def test_string_form_referencing(self):
| f1 = Foo(name='Foo1')
f1.save()
f2 = Foo(name='Foo2')
f2.save()
w1 = Whiz(name='Whiz1')
w1.save()
b1 = Bar(name='Bar1', normal=f1, fwd=w1, back=f2)
b1.save()
self.assertEquals(b1.normal, f1)
self.assertEquals(b1.fwd, w1)
self.assertEquals(b1.back, f2)
base1 = Base(name='B... |
'Regression tests for #3937
make sure we can use unicode characters in queries.
If these tests fail on MySQL, it\'s a problem with the test setup.
A properly configured UTF-8 database can handle this.'
| def test_unicode_chars_in_queries(self):
| fx = Foo(name='Bjorn', friend=u'Fran\xe7ois')
fx.save()
self.assertEquals(Foo.objects.get(friend__contains=u'\xe7'), fx)
self.assertEquals(Foo.objects.get(friend__contains='\xc3\xa7'), fx)
|
'Regression tests for #5087
make sure we can perform queries on TextFields.'
| def test_queries_on_textfields(self):
| a = Article(name='Test', text='The quick brown fox jumps over the lazy dog.')
a.save()
self.assertEquals(Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.'), a)
self.assertEquals(Article.objects.get(text__contains='quick brow... |
'Regression test for #708
"like" queries on IP address fields require casting to text (on PostgreSQL).'
| def test_ipaddress_on_postgresql(self):
| a = Article(name='IP test', text='The body', submitted_from='192.0.2.100')
a.save()
self.assertEquals(repr(Article.objects.filter(submitted_from__contains='192.0.2')), repr([a]))
|
'Regression test for #12822: DatabaseError: aggregates not allowed in
WHERE clause
Tests that the subselect works and returns results equivalent to a
query with the IDs listed.
Before the corresponding fix for this bug, this test passed in 1.1 and
failed in 1.2-beta (trunk).'
| def test_aggregates_in_where_clause(self):
| qs = Book.objects.values('contact').annotate(Max('id'))
qs = qs.order_by('contact').values_list('id__max', flat=True)
books = Book.objects.order_by('id')
qs1 = books.filter(id__in=qs)
qs2 = books.filter(id__in=list(qs))
self.assertEqual(list(qs1), list(qs2))
|
'Regression test for #12822: DatabaseError: aggregates not allowed in
WHERE clause
Same as the above test, but evaluates the queryset for the subquery
before it\'s used as a subquery.
Before the corresponding fix for this bug, this test failed in both
1.1 and 1.2-beta (trunk).'
| def test_aggregates_in_where_clause_pre_eval(self):
| qs = Book.objects.values('contact').annotate(Max('id'))
qs = qs.order_by('contact').values_list('id__max', flat=True)
list(qs)
books = Book.objects.order_by('id')
qs1 = books.filter(id__in=qs)
qs2 = books.filter(id__in=list(qs))
self.assertEqual(list(qs1), list(qs2))
|
'Model saves should throw some signals.'
| def test_model_signals(self):
| a1 = Author(name='Neal Stephenson')
self.assertEquals(self.get_signal_output(a1.save), ['pre_save signal, Neal Stephenson', 'post_save signal, Neal Stephenson', 'Is created'])
b1 = Book(name='Snow Crash')
self.assertEquals(self.get_signal_output(b1.save), ['pre_save signal,... |
'Assigning and removing to/from m2m shouldn\'t generate an m2m signal'
| def test_m2m_signals(self):
| b1 = Book(name='Snow Crash')
self.get_signal_output(b1.save)
a1 = Author(name='Neal Stephenson')
self.get_signal_output(a1.save)
self.assertEquals(self.get_signal_output(setattr, b1, 'authors', [a1]), [])
self.assertEquals(self.get_signal_output(setattr, b1, 'authors', []), [])
|
'Even though the default manager filters out some records,
we must still be able to save (particularly, save by updating
existing records) those filtered instances. This is a
regression test for #8990, #9527'
| def test_filtered_default_manager(self):
| related = RelatedModel.objects.create(name='xyzzy')
obj = RestrictedModel.objects.create(name='hidden', related=related)
obj.name = 'still hidden'
obj.save()
self.assertEqual(RestrictedModel.plain_manager.count(), 1)
|
'Deleting related objects should also not be distracted by a
restricted manager on the related object. This is a regression
test for #2698.'
| def test_delete_related_on_filtered_manager(self):
| related = RelatedModel.objects.create(name='xyzzy')
for (name, public) in (('one', True), ('two', False), ('three', False)):
RestrictedModel.objects.create(name=name, is_public=public, related=related)
obj = RelatedModel.objects.get(name='xyzzy')
obj.delete()
self.assertEqual(len(RestrictedM... |
'A save method that modifies the data in the object'
| def save(self):
| self.data = 666
super(ModifyingSaveData, self).save(raw)
|
'Test that the get_*_display() methods are added to the model instances.'
| def test_get_display_methods(self):
| place = self.form.save()
self.assertEqual(place.get_state_display(), 'Georgia')
self.assertEqual(place.get_state_req_display(), 'North Carolina')
|
'Test that required USStateFields throw appropriate errors.'
| def test_required(self):
| form = USPlaceForm({'state': 'GA', 'name': 'Place in GA'})
self.assertFalse(form.is_valid())
self.assertEqual(form.errors['state_req'], [u'This field is required.'])
|
'Test that the empty option is there.'
| def test_field_blank_option(self):
| state_select_html = '<select name="state" id="id_state">\n<option value="">---------</option>\n<option value="AL">Alabama</option>\n<option value="AK">Alaska</option>\n<option value="AS">American Samoa</option>\n<option value="AZ">Arizona</option>\n<option value="AR">Arkansas</option>\n<o... |
'Tests that the correct template is identified as not existing
when {% extends %} specifies a template that does exist, but
that template has an {% include %} of something that does not
exist. See #12787.'
| def test_extends_include_missing_baseloader(self):
| (old_td, settings.TEMPLATE_DEBUG) = (settings.TEMPLATE_DEBUG, True)
old_loaders = loader.template_source_loaders
try:
loader.template_source_loaders = (app_directories.Loader(),)
load_name = 'test_extends_error.html'
tmpl = loader.get_template(load_name)
r = None
try:... |
'Same as test_extends_include_missing_baseloader, only tests
behavior of the cached loader instead of BaseLoader.'
| def test_extends_include_missing_cachedloader(self):
| (old_td, settings.TEMPLATE_DEBUG) = (settings.TEMPLATE_DEBUG, True)
old_loaders = loader.template_source_loaders
try:
cache_loader = cached.Loader(('',))
cache_loader._cached_loaders = (app_directories.Loader(),)
loader.template_source_loaders = (cache_loader,)
load_name = 't... |
'A template can be loaded from an egg'
| def test_existing(self):
| settings.INSTALLED_APPS = ['egg_1']
(contents, template_name) = lts_egg('y.html')
self.assertEqual(contents, 'y')
self.assertEqual(template_name, 'egg:egg_1:templates/y.html')
|
'Loading any template on an empty egg should fail'
| def test_empty(self):
| settings.INSTALLED_APPS = ['egg_empty']
egg_loader = EggLoader()
self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, 'not-existing.html')
|
'Template loading fails if the template is not in the egg'
| def test_non_existing(self):
| settings.INSTALLED_APPS = ['egg_1']
egg_loader = EggLoader()
self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, 'not-existing.html')
|
'A template can be loaded from an egg'
| def test_existing(self):
| settings.INSTALLED_APPS = ['egg_1']
egg_loader = EggLoader()
(contents, template_name) = egg_loader.load_template_source('y.html')
self.assertEqual(contents, 'y')
self.assertEqual(template_name, 'egg:egg_1:templates/y.html')
|
'Loading an existent template from an egg not included in INSTALLED_APPS should fail'
| def test_not_installed(self):
| settings.INSTALLED_APPS = []
egg_loader = EggLoader()
self.assertRaises(TemplateDoesNotExist, egg_loader.load_template_source, 'y.html')
|
'Check that the template directories form part of the template cache key. Refs #13573'
| def test_templatedir_caching(self):
| (t1, name) = loader.find_template('test.html', (os.path.join(os.path.dirname(__file__), 'templates', 'first'),))
(t2, name) = loader.find_template('test.html', (os.path.join(os.path.dirname(__file__), 'templates', 'second'),))
self.assertNotEqual(t1.render(Context({})), t2.render(Context({})))
|
'can_delete should be passed to inlineformset factory.'
| def test_can_delete(self):
| response = self.client.get(self.change_url)
inner_formset = response.context[(-1)]['inline_admin_formsets'][0].formset
expected = InnerInline.can_delete
actual = inner_formset.can_delete
self.assertEqual(expected, actual, 'can_delete must be equal')
|
'Bug #13174.'
| def test_readonly_stacked_inline_label(self):
| holder = Holder.objects.create(dummy=42)
inner = Inner.objects.create(holder=holder, dummy=42, readonly='')
response = self.client.get(('/test_admin/admin/admin_inlines/holder/%i/' % holder.id))
self.assertContains(response, '<label>Inner readonly label:</label>')
|
'Autogenerated many-to-many inlines are displayed correctly (#13407)'
| def test_many_to_many_inlines(self):
| response = self.client.get('/test_admin/admin/admin_inlines/author/add/')
self.assertContains(response, '<h2>Author-book relationships</h2>')
self.assertContains(response, 'Add another Author-Book Relationship')
self.assertContains(response, 'id="id_Author_books-TOTAL_FORMS"')
|
'Regression for #9362
The problem depends only on InlineAdminForm and its "original"
argument, so we can safely set the other arguments to None/{}. We just
need to check that the content_type argument of Child isn\'t altered by
the internals of the inline form.'
| def test_immutable_content_type(self):
| sally = Teacher.objects.create(name='Sally')
john = Parent.objects.create(name='John')
joe = Child.objects.create(name='Joe', teacher=sally, parent=john)
iaf = InlineAdminForm(None, None, {}, {}, joe)
parent_ct = ContentType.objects.get_for_model(Parent)
self.assertEqual(iaf.original.content_typ... |
'Regression tests for #7314 and #7372'
| def test_regression_7314_7372(self):
| rm = RevisionableModel.objects.create(title='First Revision', when=datetime.datetime(2008, 9, 28, 10, 30, 0))
self.assertEqual(rm.pk, rm.base.pk)
rm2 = rm.new_revision()
rm2.title = 'Second Revision'
rm.when = datetime.datetime(2008, 9, 28, 14, 25, 0)
rm2.save()
self.assertEqual(rm2.ti... |
'Regression test for #7957: Combining extra() calls should leave the
corresponding parameters associated with the right extra() bit. I.e.
internal dictionary must remain sorted.'
| def test_regression_7957(self):
| self.assertEqual(User.objects.extra(select={'alpha': '%s'}, select_params=(1,)).extra(select={'beta': '%s'}, select_params=(2,))[0].alpha, 1)
self.assertEqual(User.objects.extra(select={'beta': '%s'}, select_params=(1,)).extra(select={'alpha': '%s'}, select_params=(2,))[0].alpha, 2)
|
'Regression test for #7961: When not using a portion of an
extra(...) in a query, remove any corresponding parameters from the
query as well.'
| def test_regression_7961(self):
| self.assertEqual(list(User.objects.extra(select={'alpha': '%s'}, select_params=((-6),)).filter(id=self.u.id).values_list('id', flat=True)), [self.u.id])
|
'Regression test for #8063: limiting a query shouldn\'t discard any
extra() bits.'
| def test_regression_8063(self):
| qs = User.objects.all().extra(where=['id=%s'], params=[self.u.id])
self.assertQuerysetEqual(qs, ['<User: fred>'])
self.assertQuerysetEqual(qs[:1], ['<User: fred>'])
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.