desc
stringlengths 3
26.7k
| decl
stringlengths 11
7.89k
| bodies
stringlengths 8
553k
|
---|---|---|
'fulldefault: manage.py can execute user commands when settings are provided as argument'
| def test_custom_command_with_settings(self):
| args = [u'noargs_command', u'--settings=regressiontests.settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u'EXECUTE:NoArgsCommand')
|
'fulldefault: manage.py can execute user commands when settings are provided in environment'
| def test_custom_command_with_environment(self):
| args = [u'noargs_command']
(out, err) = self.run_manage(args, u'regressiontests.settings')
self.assertNoOutput(err)
self.assertOutput(out, u'EXECUTE:NoArgsCommand')
|
'minimal: manage.py builtin commands fail with an error when no settings provided'
| def test_builtin_command(self):
| args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u'App with label admin_scripts could not be found')
|
'minimal: manage.py builtin commands fail if settings are provided as argument'
| def test_builtin_with_settings(self):
| args = [u'sqlall', u'--settings=regressiontests.settings', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u'App with label admin_scripts could not be found')
|
'minimal: manage.py builtin commands fail if settings are provided in the environment'
| def test_builtin_with_environment(self):
| args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args, u'regressiontests.settings')
self.assertNoOutput(out)
self.assertOutput(err, u'App with label admin_scripts could not be found')
|
'minimal: manage.py builtin commands fail if settings file (from argument) doesn\'t exist'
| def test_builtin_with_bad_settings(self):
| args = [u'sqlall', u'--settings=bad_settings', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"Could not import settings 'bad_settings'")
|
'minimal: manage.py builtin commands fail if settings file (from environment) doesn\'t exist'
| def test_builtin_with_bad_environment(self):
| args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args, u'bad_settings')
self.assertNoOutput(out)
self.assertOutput(err, u"Could not import settings 'bad_settings'")
|
'minimal: manage.py can\'t execute user commands without appropriate settings'
| def test_custom_command(self):
| args = [u'noargs_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"Unknown command: 'noargs_command'")
|
'minimal: manage.py can\'t execute user commands, even if settings are provided as argument'
| def test_custom_command_with_settings(self):
| args = [u'noargs_command', u'--settings=regressiontests.settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"Unknown command: 'noargs_command'")
|
'minimal: manage.py can\'t execute user commands, even if settings are provided in environment'
| def test_custom_command_with_environment(self):
| args = [u'noargs_command']
(out, err) = self.run_manage(args, u'regressiontests.settings')
self.assertNoOutput(out)
self.assertOutput(err, u"Unknown command: 'noargs_command'")
|
'alternate: manage.py builtin commands fail with an error when no default settings provided'
| def test_builtin_command(self):
| args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"Could not import settings 'regressiontests.settings'")
|
'alternate: manage.py builtin commands work with settings provided as argument'
| def test_builtin_with_settings(self):
| args = [u'sqlall', u'--settings=alternate_settings', u'admin_scripts']
(out, err) = self.run_manage(args)
expected = (u'create table %s' % connection.ops.quote_name(u'admin_scripts_article'))
self.assertTrue((expected.lower() in out.lower()))
self.assertNoOutput(err)
|
'alternate: manage.py builtin commands work if settings are provided in the environment'
| def test_builtin_with_environment(self):
| args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args, u'alternate_settings')
expected = (u'create table %s' % connection.ops.quote_name(u'admin_scripts_article'))
self.assertTrue((expected.lower() in out.lower()))
self.assertNoOutput(err)
|
'alternate: manage.py builtin commands fail if settings file (from argument) doesn\'t exist'
| def test_builtin_with_bad_settings(self):
| args = [u'sqlall', u'--settings=bad_settings', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"Could not import settings 'bad_settings'")
|
'alternate: manage.py builtin commands fail if settings file (from environment) doesn\'t exist'
| def test_builtin_with_bad_environment(self):
| args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args, u'bad_settings')
self.assertNoOutput(out)
self.assertOutput(err, u"Could not import settings 'bad_settings'")
|
'alternate: manage.py can\'t execute user commands without settings'
| def test_custom_command(self):
| args = [u'noargs_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"Could not import settings 'regressiontests.settings'")
|
'alternate: manage.py can execute user commands if settings are provided as argument'
| def test_custom_command_with_settings(self):
| args = [u'noargs_command', u'--settings=alternate_settings']
(out, err) = self.run_manage(args)
self.assertOutput(out, u"EXECUTE:NoArgsCommand options=[('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")
self.assertNoOutput(err)
|
'alternate: manage.py can execute user commands if settings are provided in environment'
| def test_custom_command_with_environment(self):
| args = [u'noargs_command']
(out, err) = self.run_manage(args, u'alternate_settings')
self.assertOutput(out, u"EXECUTE:NoArgsCommand options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
self.assertNoOutput(err)
|
'multiple: manage.py builtin commands fail with an error when no settings provided'
| def test_builtin_command(self):
| args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u'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 = [u'sqlall', u'--settings=alternate_settings', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u'CREATE TABLE')
|
'multiple: manage.py can execute builtin commands if settings are provided in the environment'
| def test_builtin_with_environment(self):
| args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args, u'alternate_settings')
self.assertNoOutput(err)
self.assertOutput(out, u'CREATE TABLE')
|
'multiple: manage.py builtin commands fail if settings file (from argument) doesn\'t exist'
| def test_builtin_with_bad_settings(self):
| args = [u'sqlall', u'--settings=bad_settings', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"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 = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args, u'bad_settings')
self.assertNoOutput(out)
self.assertOutput(err, u"Could not import settings 'bad_settings'")
|
'multiple: manage.py can\'t execute user commands using default settings'
| def test_custom_command(self):
| args = [u'noargs_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"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 = [u'noargs_command', u'--settings=alternate_settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u'EXECUTE:NoArgsCommand')
|
'multiple: manage.py can execute user commands if settings are provided in environment'
| def test_custom_command_with_environment(self):
| args = [u'noargs_command']
(out, err) = self.run_manage(args, u'alternate_settings')
self.assertNoOutput(err)
self.assertOutput(out, u'EXECUTE:NoArgsCommand')
|
'import error: manage.py builtin commands shows useful diagnostic info
when settings with import errors is provided'
| def test_builtin_command(self):
| self.write_settings_with_import_error(u'settings.py')
args = [u'sqlall', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u'No module named')
self.assertOutput(err, u'foo42bar')
|
'manage.py builtin commands does not swallow attribute errors from bad settings (#18845)'
| def test_builtin_command_with_attribute_error(self):
| self.write_settings(u'settings.py', sdict={u'BAD_VAR': u'INSTALLED_APPS.crash'})
args = [u'collectstatic', u'admin_scripts']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u"AttributeError: 'list' object has no attribute 'crash'")
|
'manage.py validate reports an error on a non-existent app in INSTALLED_APPS'
| def test_nonexistent_app(self):
| self.write_settings(u'settings.py', apps=[u'admin_scriptz.broken_app'], sdict={u'USE_I18N': False})
args = [u'validate']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u'No module named')
self.assertOutput(err, u'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(u'settings.py', apps=[u'admin_scripts.broken_app'])
args = [u'validate']
(out, err) = self.run_manage(args)
self.assertNoOutput(out)
self.assertOutput(err, u'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(u'settings.py', apps=[u'admin_scripts.complex_app', u'admin_scripts.simple_app'], sdict={u'DEBUG': True})
args = [u'validate']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u'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(u'settings.py', apps=[u'admin_scripts.app_with_import', u'django.contrib.comments', u'django.contrib.auth', u'django.contrib.contenttypes', u'django.contrib.sites'], sdict={u'DEBUG': True})
args = [u'validate']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u'0 errors found')
|
'Ensure that the --liveserver option sets the environment variable
correctly.
Refs #2879.'
| def test_liveserver(self):
| address_predefined = (u'DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ)
old_address = os.environ.get(u'DJANGO_LIVE_TEST_SERVER_ADDRESS')
self.cmd.handle(verbosity=0, testrunner=u'regressiontests.admin_scripts.tests.CustomTestRunner')
self.assertEqual((u'DJANGO_LIVE_TEST_SERVER_ADDRESS' in os.environ), address_predefined)
self.assertEqual(os.environ.get(u'DJANGO_LIVE_TEST_SERVER_ADDRESS'), old_address)
self.cmd.handle(verbosity=0, testrunner=u'regressiontests.admin_scripts.tests.CustomTestRunner', liveserver=u'blah')
self.assertEqual(os.environ[u'DJANGO_LIVE_TEST_SERVER_ADDRESS'], u'blah')
if address_predefined:
os.environ[u'DJANGO_LIVE_TEST_SERVER_ADDRESS'] = old_address
else:
del os.environ[u'DJANGO_LIVE_TEST_SERVER_ADDRESS']
|
'version is handled as a special case'
| def test_version(self):
| args = [u'version']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, get_version())
|
'--version is equivalent to version'
| def test_version_alternative(self):
| (args1, args2) = ([u'version'], [u'--version'])
self.assertEqual(self.run_manage(args1), self.run_manage(args2))
|
'help is handled as a special case'
| def test_help(self):
| args = [u'help']
(out, err) = self.run_manage(args)
self.assertOutput(out, u'Usage: manage.py subcommand [options] [args]')
self.assertOutput(out, u"Type 'manage.py help <subcommand>' for help on a specific subcommand.")
self.assertOutput(out, u'[django]')
self.assertOutput(out, u'startapp')
self.assertOutput(out, u'startproject')
|
'help --commands shows the list of all available commands'
| def test_help_commands(self):
| args = [u'help', u'--commands']
(out, err) = self.run_manage(args)
self.assertNotInOutput(out, u'Usage:')
self.assertNotInOutput(out, u'Options:')
self.assertNotInOutput(out, u'[django]')
self.assertOutput(out, u'startapp')
self.assertOutput(out, u'startproject')
self.assertNotInOutput(out, u'\n\n')
|
'--help is equivalent to help'
| def test_help_alternative(self):
| (args1, args2) = ([u'help'], [u'--help'])
self.assertEqual(self.run_manage(args1), self.run_manage(args2))
|
'-h is handled as a short form of --help'
| def test_help_short_altert(self):
| (args1, args2) = ([u'--help'], [u'-h'])
self.assertEqual(self.run_manage(args1), self.run_manage(args2))
|
'--help can be used on a specific command'
| def test_specific_help(self):
| args = [u'sqlall', u'--help']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u'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 = [u'base_command', u'testlabel']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'User BaseCommands can execute when no labels are provided'
| def test_base_command_no_label(self):
| args = [u'base_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=(), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'User BaseCommands can execute when no labels are provided'
| def test_base_command_multiple_label(self):
| args = [u'base_command', u'testlabel', u'anotherlabel']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel', 'anotherlabel'), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'User BaseCommands can execute with options when a label is provided'
| def test_base_command_with_option(self):
| args = [u'base_command', u'testlabel', u'--option_a=x']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'User BaseCommands can execute with multiple options when a label is provided'
| def test_base_command_with_options(self):
| args = [u'base_command', u'testlabel', u'-a', u'x', u'--option_b=y']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'Test run_from_argv properly terminates even with custom execute() (#19665)
Also test proper traceback display.'
| def test_base_run_from_argv(self):
| command = BaseCommand()
command.execute = (lambda args: args)
old_stderr = sys.stderr
sys.stderr = err = StringIO()
try:
with self.assertRaises(SystemExit):
command.run_from_argv([u'', u''])
err_message = err.getvalue()
self.assertNotIn(u'Traceback', err_message)
self.assertIn(u'TypeError', err_message)
with self.assertRaises(SystemExit):
command.run_from_argv([u'', u'', u'--traceback'])
err_message = err.getvalue()
self.assertIn(u'Traceback (most recent call last)', err_message)
self.assertIn(u'TypeError', err_message)
finally:
sys.stderr = old_stderr
|
'NoArg Commands can be executed'
| def test_noargs(self):
| args = [u'noargs_command']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"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 = [u'noargs_command', u'argument']
(out, err) = self.run_manage(args)
self.assertOutput(err, u"Error: Command doesn't accept any arguments")
|
'User AppCommands can execute when a single app name is provided'
| def test_app_command(self):
| args = [u'app_command', u'auth']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
self.assertOutput(out, os.sep.join([u'django', u'contrib', u'auth', u'models.py']))
self.assertOutput(out, u"'>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'User AppCommands raise an error when no app name is provided'
| def test_app_command_no_apps(self):
| args = [u'app_command']
(out, err) = self.run_manage(args)
self.assertOutput(err, u'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 = [u'app_command', u'auth', u'contenttypes']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
self.assertOutput(out, os.sep.join([u'django', u'contrib', u'auth', u'models.py']))
self.assertOutput(out, u"'>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
self.assertOutput(out, u"EXECUTE:AppCommand app=<module 'django.contrib.contenttypes.models'")
self.assertOutput(out, os.sep.join([u'django', u'contrib', u'contenttypes', u'models.py']))
self.assertOutput(out, u"'>, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'User AppCommands can execute when a single app name is provided'
| def test_app_command_invalid_appname(self):
| args = [u'app_command', u'NOT_AN_APP']
(out, err) = self.run_manage(args)
self.assertOutput(err, u'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 = [u'app_command', u'auth', u'NOT_AN_APP']
(out, err) = self.run_manage(args)
self.assertOutput(err, u'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 = [u'label_command', u'testlabel']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"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 = [u'label_command']
(out, err) = self.run_manage(args)
self.assertOutput(err, u'Enter at least one label')
|
'User LabelCommands are executed multiple times if multiple labels are provided'
| def test_label_command_multiple_label(self):
| args = [u'label_command', u'testlabel', u'anotherlabel']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:LabelCommand label=testlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
self.assertOutput(out, u"EXECUTE:LabelCommand label=anotherlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
|
'Options passed after settings are correctly handled'
| def test_setting_then_option(self):
| args = [u'base_command', u'testlabel', u'--settings=alternate_settings', u'--option_a=x']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")
|
'Short options passed after settings are correctly handled'
| def test_setting_then_short_option(self):
| args = [u'base_command', u'testlabel', u'--settings=alternate_settings', u'--option_a=x']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")
|
'Options passed before settings are correctly handled'
| def test_option_then_setting(self):
| args = [u'base_command', u'testlabel', u'--option_a=x', u'--settings=alternate_settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")
|
'Short options passed before settings are correctly handled'
| def test_short_option_then_setting(self):
| args = [u'base_command', u'testlabel', u'-a', u'x', u'--settings=alternate_settings']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")
|
'Options are correctly handled when they are passed before and after a setting'
| def test_option_then_setting_then_option(self):
| args = [u'base_command', u'testlabel', u'--option_a=x', u'--settings=alternate_settings', u'--option_b=y']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")
|
'Make sure passing the wrong kinds of arguments raises a CommandError'
| def test_wrong_args(self):
| (out, err) = self.run_django_admin([u'startproject'])
self.assertNoOutput(out)
self.assertOutput(err, u'you must provide a project name')
|
'Make sure the startproject management command creates a project'
| def test_simple_project(self):
| args = [u'startproject', u'testproject']
testproject_dir = os.path.join(test_dir, u'testproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
(out, err) = self.run_django_admin(args)
self.assertNoOutput(out)
self.assertOutput(err, u'already exists')
|
'Make sure the startproject management command validates a project name'
| def test_invalid_project_name(self):
| args = [u'startproject', u'7testproject']
testproject_dir = os.path.join(test_dir, u'7testproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertOutput(err, u"Error: '7testproject' is not a valid project name. Please make sure the name begins with a letter or underscore.")
self.assertFalse(os.path.exists(testproject_dir))
|
'Make sure the startproject management command creates a project in a specific directory'
| def test_simple_project_different_directory(self):
| args = [u'startproject', u'testproject', u'othertestproject']
testproject_dir = os.path.join(test_dir, u'othertestproject')
os.mkdir(testproject_dir)
self.addCleanup(shutil.rmtree, testproject_dir)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.exists(os.path.join(testproject_dir, u'manage.py')))
(out, err) = self.run_django_admin(args)
self.assertNoOutput(out)
self.assertOutput(err, u'already exists')
|
'Make sure the startproject management command is able to use a different project template'
| def test_custom_project_template(self):
| template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', u'project_template')
args = [u'startproject', u'--template', template_path, u'customtestproject']
testproject_dir = os.path.join(test_dir, u'customtestproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, u'additional_dir')))
|
'Ticket 17475: Template dir passed has a trailing path separator'
| def test_template_dir_with_trailing_slash(self):
| template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', (u'project_template' + os.sep))
args = [u'startproject', u'--template', template_path, u'customtestproject']
testproject_dir = os.path.join(test_dir, u'customtestproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, u'additional_dir')))
|
'Make sure the startproject management command is able to use a different project template from a tarball'
| def test_custom_project_template_from_tarball_by_path(self):
| template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', u'project_template.tgz')
args = [u'startproject', u'--template', template_path, u'tarballtestproject']
testproject_dir = os.path.join(test_dir, u'tarballtestproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, u'run.py')))
|
'Startproject can use a project template from a tarball and create it in a specified location'
| def test_custom_project_template_from_tarball_to_alternative_location(self):
| template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', u'project_template.tgz')
args = [u'startproject', u'--template', template_path, u'tarballtestproject', u'altlocation']
testproject_dir = os.path.join(test_dir, u'altlocation')
os.mkdir(testproject_dir)
self.addCleanup(shutil.rmtree, testproject_dir)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, u'run.py')))
|
'Make sure the startproject management command is able to use a different project template from a tarball via a url'
| def test_custom_project_template_from_tarball_by_url(self):
| template_url = (u'%s/admin_scripts/custom_templates/project_template.tgz' % self.live_server_url)
args = [u'startproject', u'--template', template_url, u'urltestproject']
testproject_dir = os.path.join(test_dir, u'urltestproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, u'run.py')))
|
'Startproject management command handles project template tar/zip balls from non-canonical urls'
| def test_project_template_tarball_url(self):
| template_url = (u'%s/admin_scripts/custom_templates/project_template.tgz/' % self.live_server_url)
args = [u'startproject', u'--template', template_url, u'urltestproject']
testproject_dir = os.path.join(test_dir, u'urltestproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, u'run.py')))
|
'Make sure the startproject management command is able to render custom files'
| def test_file_without_extension(self):
| template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', u'project_template')
args = [u'startproject', u'--template', template_path, u'customtestproject', u'-e', u'txt', u'-n', u'Procfile']
testproject_dir = os.path.join(test_dir, u'customtestproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
self.assertTrue(os.path.exists(os.path.join(testproject_dir, u'additional_dir')))
base_path = os.path.join(testproject_dir, u'additional_dir')
for f in (u'Procfile', u'additional_file.py', u'requirements.txt'):
self.assertTrue(os.path.exists(os.path.join(base_path, f)))
with open(os.path.join(base_path, f)) as fh:
self.assertEqual(fh.read(), u'# some file for customtestproject test project')
|
'Make sure template context variables are rendered with proper values'
| def test_custom_project_template_context_variables(self):
| template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', u'project_template')
args = [u'startproject', u'--template', template_path, u'another_project', u'project_dir']
testproject_dir = os.path.join(test_dir, u'project_dir')
os.mkdir(testproject_dir)
self.addCleanup(shutil.rmtree, testproject_dir)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
test_manage_py = os.path.join(testproject_dir, u'manage.py')
with open(test_manage_py, u'r') as fp:
content = force_text(fp.read())
self.assertIn(u"project_name = 'another_project'", content)
self.assertIn((u"project_directory = '%s'" % testproject_dir), content)
|
'Make sure template context variables are not html escaped'
| def test_no_escaping_of_project_variables(self):
| self.write_settings(u'alternate_settings.py')
self.addCleanup(self.remove_settings, u'alternate_settings.py')
template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', u'project_template')
args = [u'custom_startproject', u'--template', template_path, u'another_project', u'project_dir', u'--extra', u'<&>', u'--settings=alternate_settings']
testproject_dir = os.path.join(test_dir, u'project_dir')
os.mkdir(testproject_dir)
self.addCleanup(shutil.rmtree, testproject_dir)
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
test_manage_py = os.path.join(testproject_dir, u'additional_dir', u'extra.py')
with open(test_manage_py, u'r') as fp:
content = fp.read()
self.assertIn(u'<&>', content)
|
'Make sure an exception is raised when the provided
destination directory doesn\'t exist'
| def test_custom_project_destination_missing(self):
| template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', u'project_template')
args = [u'startproject', u'--template', template_path, u'yet_another_project', u'project_dir2']
testproject_dir = os.path.join(test_dir, u'project_dir2')
(out, err) = self.run_django_admin(args)
self.assertNoOutput(out)
self.assertOutput(err, (u"Destination directory '%s' does not exist, please create it first." % testproject_dir))
self.assertFalse(os.path.exists(testproject_dir))
|
'Ticket 18091: Make sure the startproject management command is able to render templates with non-ASCII content'
| def test_custom_project_template_with_non_ascii_templates(self):
| template_path = os.path.join(test_dir, u'admin_scripts', u'custom_templates', u'project_template')
args = [u'startproject', u'--template', template_path, u'--extension=txt', u'customtestproject']
testproject_dir = os.path.join(test_dir, u'customtestproject')
self.addCleanup(shutil.rmtree, testproject_dir, True)
(out, err) = self.run_django_admin(args)
self.assertNoOutput(err)
self.assertTrue(os.path.isdir(testproject_dir))
path = os.path.join(testproject_dir, u'ticket-18091-non-ascii-template.txt')
with codecs.open(path, u'r', u'utf-8') as f:
self.assertEqual(f.read(), u'Some non-ASCII text for testing ticket #18091:\n\xfc\xe4\xf6 \u20ac\n')
|
'Runs without error and emits settings diff.'
| def test_basic(self):
| self.write_settings(u'settings_to_diff.py', sdict={u'FOO': u'"bar"'})
self.addCleanup(self.remove_settings, u'settings_to_diff.py')
args = [u'diffsettings', u'--settings=settings_to_diff']
(out, err) = self.run_manage(args)
self.assertNoOutput(err)
self.assertOutput(out, u"FOO = 'bar' ###")
|
'Executing the changepassword management command with a database option
should operate on the specified DB'
| def test_that_changepassword_command_with_database_option_uses_given_db(self):
| self.assertTrue(self.user.check_password('qwerty'))
command = changepassword.Command()
command._get_pass = (lambda *args: 'not qwerty')
command.execute('joe', database='other', stdout=self.stdout)
command_output = self.stdout.getvalue().strip()
self.assertEqual(command_output, "Changing password for user 'joe'\nPassword changed successfully for user 'joe'")
self.assertTrue(models.User.objects.using('other').get(username='joe').check_password('not qwerty'))
|
'createsuperuser command should operate on specified DB'
| def test_createsuperuser_command_with_database_option(self):
| new_io = StringIO()
call_command('createsuperuser', interactive=False, username='joe', email='[email protected]', database='other', stdout=new_io)
command_output = new_io.getvalue().strip()
self.assertEqual(command_output, 'Superuser created successfully.')
u = models.User.objects.using('other').get(username='joe')
self.assertEqual(u.email, '[email protected]')
new_io.close()
|
'Can find a file in a STATICFILES_DIRS directory.'
| def test_staticfiles_dirs(self):
| self.assertFileContains(u'test.txt', u'Can we find')
self.assertFileContains(os.path.join(u'prefix', u'test.txt'), u'Prefix')
|
'Can find a file in a subdirectory of a STATICFILES_DIRS
directory.'
| def test_staticfiles_dirs_subdir(self):
| self.assertFileContains(u'subdir/test.txt', u'Can we find')
|
'File in STATICFILES_DIRS has priority over file in app.'
| def test_staticfiles_dirs_priority(self):
| self.assertFileContains(u'test/file.txt', u'STATICFILES_DIRS')
|
'Can find a file in an app static/ directory.'
| def test_app_files(self):
| self.assertFileContains(u'test/file1.txt', u'file1 in the app dir')
|
'Can find a file with non-ASCII character in an app static/ directory.'
| def test_nonascii_filenames(self):
| self.assertFileContains(u'test/\u2297.txt', u'\u2297 in the app dir')
|
'Can find a file with capital letters.'
| def test_camelcase_filenames(self):
| self.assertFileContains(u'test/camelCase.txt', u'camelCase')
|
'Test that findstatic returns all candidate files if run without --first.'
| def test_all_files(self):
| out = six.StringIO()
call_command(u'findstatic', u'test/file.txt', verbosity=0, stdout=out)
out.seek(0)
lines = [l.strip() for l in out.readlines()]
self.assertEqual(len(lines), 3)
self.assertIn(u'project', force_text(lines[1]))
self.assertIn(u'apps', force_text(lines[2]))
|
'Test that -i patterns are ignored.'
| def test_ignore(self):
| self.assertFileNotFound(u'test/test.ignoreme')
|
'Common ignore patterns (*~, .*, CVS) are ignored.'
| def test_common_ignore_patterns(self):
| self.assertFileNotFound(u'test/.hidden')
self.assertFileNotFound(u'test/backup~')
self.assertFileNotFound(u'test/CVS')
|
'With --no-default-ignore, common ignore patterns (*~, .*, CVS)
are not ignored.'
| def test_no_common_ignore_patterns(self):
| self.assertFileContains(u'test/.hidden', u'should be ignored')
self.assertFileContains(u'test/backup~', u'should be ignored')
self.assertFileContains(u'test/CVS', u'should be ignored')
|
'Make sure no files were create in the destination directory.'
| def test_no_files_created(self):
| self.assertEqual(os.listdir(settings.STATIC_ROOT), [])
|
'Test if collectstatic takes files in proper order'
| def test_ordering_override(self):
| self.assertFileContains(u'file2.txt', u'duplicate of file2.txt')
self.run_collectstatic()
self.assertFileContains(u'file2.txt', u'duplicate of file2.txt')
mtime = os.path.getmtime(self.testfile_path)
atime = os.path.getatime(self.testfile_path)
os.utime(self.orig_path, ((mtime + 1), (atime + 1)))
self.run_collectstatic()
self.assertFileContains(u'file2.txt', u'duplicate of file2.txt')
|
'Test the CachedStaticFilesStorage backend.'
| def test_template_tag_return(self):
| self.assertStaticRaises(ValueError, u'does/not/exist.png', u'/static/does/not/exist.png')
self.assertStaticRenders(u'test/file.txt', u'/static/test/file.dad0999e4f8f.txt')
self.assertStaticRenders(u'test/file.txt', u'/static/test/file.dad0999e4f8f.txt', asvar=True)
self.assertStaticRenders(u'cached/styles.css', u'/static/cached/styles.93b1147e8552.css')
self.assertStaticRenders(u'path/', u'/static/path/')
self.assertStaticRenders(u'path/?query', u'/static/path/?query')
|
'See #18050'
| def test_import_replacement(self):
| relpath = self.cached_file_path(u'cached/import.css')
self.assertEqual(relpath, u'cached/import.2b1d40b0bbd4.css')
with storage.staticfiles_storage.open(relpath) as relfile:
self.assertIn('import url("styles.93b1147e8552.css")', relfile.read())
|
'Test that post_processing behaves correctly.
Files that are alterable should always be post-processed; files that
aren\'t should be skipped.
collectstatic has already been called once in setUp() for this testcase,
therefore we check by verifying behavior on a second run.'
| def test_post_processing(self):
| collectstatic_args = {u'interactive': False, u'verbosity': u'0', u'link': False, u'clear': False, u'dry_run': False, u'post_process': True, u'use_default_ignore_patterns': True, u'ignore_patterns': [u'*.ignoreme']}
collectstatic_cmd = CollectstaticCommand()
collectstatic_cmd.set_options(**collectstatic_args)
stats = collectstatic_cmd.collect()
self.assertIn(os.path.join(u'cached', u'css', u'window.css'), stats[u'post_processed'])
self.assertIn(os.path.join(u'cached', u'css', u'img', u'window.png'), stats[u'unmodified'])
self.assertIn(os.path.join(u'test', u'nonascii.css'), stats[u'post_processed'])
|
'Handle cache key creation correctly, see #17861.'
| def test_cache_key_memcache_validation(self):
| name = ((u'/some crazy/long filename/ with spaces Here and ?#%#$/other/stuff/some crazy/long filename/ with spaces Here and ?#%#$/other/stuff/some crazy/long filename/ with spaces Here and ?#%#$/other/stuff/some crazy/long filename/ with spaces Here and ?#%#$/other/stuff/some crazy/long filename/ with spaces Here and ?#%#$/other/stuff/some crazy/' + u'\x16') + u'\xb4')
cache_key = storage.staticfiles_storage.cache_key(name)
cache_validator = BaseCache({})
cache_validator.validate_key(cache_key)
self.assertEqual(cache_key, u'staticfiles:821ea71ef36f95b3922a77f7364670e7')
|
'Test the CachedStaticFilesStorage backend.'
| def test_template_tag_return(self):
| self.assertStaticRaises(ValueError, u'does/not/exist.png', u'/static/does/not/exist.png')
self.assertStaticRenders(u'test/file.txt', u'/static/test/file.deploy12345.txt')
self.assertStaticRenders(u'cached/styles.css', u'/static/cached/styles.deploy12345.css')
self.assertStaticRenders(u'path/', u'/static/path/')
self.assertStaticRenders(u'path/?query', u'/static/path/?query')
|
'We can\'t determine if STATICFILES_DIRS is set correctly just by
looking at the type, but we can determine if it\'s definitely wrong.'
| @override_settings(STATICFILES_DIRS=u'a string')
def test_non_tuple_raises_exception(self):
| self.assertRaises(ImproperlyConfigured, finders.FileSystemFinder)
|
'Check that if the token is longer than expected, it is ignored and
a new token is created.'
| def test_process_view_token_too_long(self):
| req = self._get_GET_no_csrf_cookie_request()
req.COOKIES[settings.CSRF_COOKIE_NAME] = (u'x' * 10000000)
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.assertEqual(len(csrf_cookie.value), CSRF_KEY_LENGTH)
|
'When get_token is used, check that the cookie is created and headers
patched.'
| def test_process_response_get_token_used(self):
| req = self._get_GET_no_csrf_cookie_request()
with self.settings(CSRF_COOKIE_NAME=u'myname', CSRF_COOKIE_DOMAIN=u'.example.com', CSRF_COOKIE_PATH=u'/test/', CSRF_COOKIE_SECURE=True):
CsrfViewMiddleware().process_view(req, token_view, (), {})
resp = token_view(req)
resp2 = CsrfViewMiddleware().process_response(req, resp)
csrf_cookie = resp2.cookies.get(u'myname', False)
self.assertNotEqual(csrf_cookie, False)
self.assertEqual(csrf_cookie[u'domain'], u'.example.com')
self.assertEqual(csrf_cookie[u'secure'], True)
self.assertEqual(csrf_cookie[u'path'], u'/test/')
self.assertTrue((u'Cookie' in resp2.get(u'Vary', u'')))
|
'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, False)
self.assertEqual(csrf_cookie, False)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.