Fixed the admin_scripts tests to check for the right output with Python 2.4.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@8108 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
4fee39c63c
commit
ce15b389c1
|
@ -1,5 +1,5 @@
|
||||||
"""
|
"""
|
||||||
A series of tests to establish that the command-line managment tools work as
|
A series of tests to establish that the command-line managment tools work as
|
||||||
advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE
|
advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE
|
||||||
and default settings.py files.
|
and default settings.py files.
|
||||||
"""
|
"""
|
||||||
|
@ -13,7 +13,7 @@ from django.conf import settings
|
||||||
|
|
||||||
class AdminScriptTestCase(unittest.TestCase):
|
class AdminScriptTestCase(unittest.TestCase):
|
||||||
def write_settings(self, filename, apps=None):
|
def write_settings(self, filename, apps=None):
|
||||||
test_dir = os.path.dirname(os.path.dirname(__file__))
|
test_dir = os.path.dirname(os.path.dirname(__file__))
|
||||||
settings_file = open(os.path.join(test_dir,filename), 'w')
|
settings_file = open(os.path.join(test_dir,filename), 'w')
|
||||||
settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
|
settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
|
||||||
exports = [
|
exports = [
|
||||||
|
@ -28,17 +28,17 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
for s in exports:
|
for s in exports:
|
||||||
if hasattr(settings,s):
|
if hasattr(settings,s):
|
||||||
settings_file.write("%s = '%s'\n" % (s, str(getattr(settings,s))))
|
settings_file.write("%s = '%s'\n" % (s, str(getattr(settings,s))))
|
||||||
|
|
||||||
if apps is None:
|
if apps is None:
|
||||||
apps = ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts']
|
apps = ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts']
|
||||||
|
|
||||||
if apps:
|
if apps:
|
||||||
settings_file.write("INSTALLED_APPS = %s\n" % apps)
|
settings_file.write("INSTALLED_APPS = %s\n" % apps)
|
||||||
|
|
||||||
settings_file.close()
|
settings_file.close()
|
||||||
|
|
||||||
def remove_settings(self, filename):
|
def remove_settings(self, filename):
|
||||||
test_dir = os.path.dirname(os.path.dirname(__file__))
|
test_dir = os.path.dirname(os.path.dirname(__file__))
|
||||||
os.remove(os.path.join(test_dir, filename))
|
os.remove(os.path.join(test_dir, filename))
|
||||||
# Also try to remove the pyc file; if it exists, it could
|
# Also try to remove the pyc file; if it exists, it could
|
||||||
# mess up later tests that depend upon the .py file not existing
|
# mess up later tests that depend upon the .py file not existing
|
||||||
|
@ -46,34 +46,34 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
os.remove(os.path.join(test_dir, filename + 'c'))
|
os.remove(os.path.join(test_dir, filename + 'c'))
|
||||||
except OSError:
|
except OSError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def run_test(self, script, args, settings_file=None, apps=None):
|
def run_test(self, script, args, settings_file=None, apps=None):
|
||||||
test_dir = os.path.dirname(os.path.dirname(__file__))
|
test_dir = os.path.dirname(os.path.dirname(__file__))
|
||||||
project_dir = os.path.dirname(test_dir)
|
project_dir = os.path.dirname(test_dir)
|
||||||
base_dir = os.path.dirname(project_dir)
|
base_dir = os.path.dirname(project_dir)
|
||||||
|
|
||||||
# Build the command line
|
# Build the command line
|
||||||
cmd = '%s "%s"' % (sys.executable, script)
|
cmd = '%s "%s"' % (sys.executable, script)
|
||||||
cmd += ''.join([' %s' % arg for arg in args])
|
cmd += ''.join([' %s' % arg for arg in args])
|
||||||
|
|
||||||
# Remember the old environment
|
# Remember the old environment
|
||||||
old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
|
old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
|
||||||
old_python_path = os.environ.get('PYTHONPATH', None)
|
old_python_path = os.environ.get('PYTHONPATH', None)
|
||||||
old_cwd = os.getcwd()
|
old_cwd = os.getcwd()
|
||||||
|
|
||||||
# Set the test environment
|
# Set the test environment
|
||||||
if settings_file:
|
if settings_file:
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
|
os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
|
||||||
elif 'DJANGO_SETTINGS_MODULE' in os.environ:
|
elif 'DJANGO_SETTINGS_MODULE' in os.environ:
|
||||||
del os.environ['DJANGO_SETTINGS_MODULE']
|
del os.environ['DJANGO_SETTINGS_MODULE']
|
||||||
|
|
||||||
os.environ['PYTHONPATH'] = os.pathsep.join([test_dir,base_dir])
|
os.environ['PYTHONPATH'] = os.pathsep.join([test_dir,base_dir])
|
||||||
|
|
||||||
# Move to the test directory and run
|
# Move to the test directory and run
|
||||||
os.chdir(test_dir)
|
os.chdir(test_dir)
|
||||||
stdin, stdout, stderr = os.popen3(cmd)
|
stdin, stdout, stderr = os.popen3(cmd)
|
||||||
out, err = stdout.read(), stderr.read()
|
out, err = stdout.read(), stderr.read()
|
||||||
|
|
||||||
# Restore the old environment
|
# Restore the old environment
|
||||||
if old_django_settings_module:
|
if old_django_settings_module:
|
||||||
os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
|
os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
|
||||||
|
@ -82,18 +82,18 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# Move back to the old working directory
|
# Move back to the old working directory
|
||||||
os.chdir(old_cwd)
|
os.chdir(old_cwd)
|
||||||
|
|
||||||
return out, err
|
return out, err
|
||||||
|
|
||||||
def run_django_admin(self, args, settings_file=None):
|
def run_django_admin(self, args, settings_file=None):
|
||||||
bin_dir = os.path.dirname(bin.__file__)
|
bin_dir = os.path.dirname(bin.__file__)
|
||||||
return self.run_test(os.path.join(bin_dir,'django-admin.py'), args, settings_file)
|
return self.run_test(os.path.join(bin_dir,'django-admin.py'), args, settings_file)
|
||||||
|
|
||||||
def run_manage(self, args, settings_file=None):
|
def run_manage(self, args, settings_file=None):
|
||||||
conf_dir = os.path.dirname(conf.__file__)
|
conf_dir = os.path.dirname(conf.__file__)
|
||||||
template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py')
|
template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py')
|
||||||
|
|
||||||
test_dir = os.path.dirname(os.path.dirname(__file__))
|
test_dir = os.path.dirname(os.path.dirname(__file__))
|
||||||
test_manage_py = os.path.join(test_dir, 'manage.py')
|
test_manage_py = os.path.join(test_dir, 'manage.py')
|
||||||
shutil.copyfile(template_manage_py, test_manage_py)
|
shutil.copyfile(template_manage_py, test_manage_py)
|
||||||
|
|
||||||
|
@ -101,7 +101,7 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
|
|
||||||
# Cleanup - remove the generated manage.py script
|
# Cleanup - remove the generated manage.py script
|
||||||
os.remove(test_manage_py)
|
os.remove(test_manage_py)
|
||||||
|
|
||||||
return stdout, stderr
|
return stdout, stderr
|
||||||
|
|
||||||
def assertNoOutput(self, stream):
|
def assertNoOutput(self, stream):
|
||||||
|
@ -120,14 +120,14 @@ class AdminScriptTestCase(unittest.TestCase):
|
||||||
|
|
||||||
class DjangoAdminNoSettings(AdminScriptTestCase):
|
class DjangoAdminNoSettings(AdminScriptTestCase):
|
||||||
"A series of tests for django-admin.py when there is no settings.py file."
|
"A series of tests for django-admin.py when there is no settings.py file."
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"no settings: django-admin builtin commands fail with an import error when no settings provided"
|
"no settings: django-admin builtin commands fail with an import error when no settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
|
self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
|
||||||
|
|
||||||
def test_builtin_with_bad_settings(self):
|
def test_builtin_with_bad_settings(self):
|
||||||
"no settings: django-admin builtin commands fail if settings file (from argument) doesn't exist"
|
"no settings: django-admin builtin commands fail if settings file (from argument) doesn't exist"
|
||||||
args = ['sqlall','--settings=bad_settings', 'admin_scripts']
|
args = ['sqlall','--settings=bad_settings', 'admin_scripts']
|
||||||
|
@ -149,17 +149,17 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase):
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('settings.py')
|
self.write_settings('settings.py')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('settings.py')
|
self.remove_settings('settings.py')
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"default: django-admin builtin commands fail with an import error when no settings provided"
|
"default: django-admin builtin commands fail with an import error when no settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
|
self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
|
||||||
|
|
||||||
def test_builtin_with_settings(self):
|
def test_builtin_with_settings(self):
|
||||||
"default: django-admin builtin commands succeed if settings are provided as argument"
|
"default: django-admin builtin commands succeed if settings are provided as argument"
|
||||||
args = ['sqlall','--settings=settings', 'admin_scripts']
|
args = ['sqlall','--settings=settings', 'admin_scripts']
|
||||||
|
@ -194,14 +194,14 @@ class DjangoAdminDefaultSettings(AdminScriptTestCase):
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"default: django-admin can't execute user commands, even if settings are provided as argument"
|
"default: django-admin can't execute user commands, even if settings are provided as argument"
|
||||||
args = ['noargs_command', '--settings=settings']
|
args = ['noargs_command', '--settings=settings']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_environment(self):
|
def test_custom_command_with_environment(self):
|
||||||
"default: django-admin can't execute user commands, even if settings are provided in environment"
|
"default: django-admin can't execute user commands, even if settings are provided in environment"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
|
@ -215,17 +215,17 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase):
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('settings.py')
|
self.remove_settings('settings.py')
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"minimal: django-admin builtin commands fail with an import error when no settings provided"
|
"minimal: django-admin builtin commands fail with an import error when no settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
|
self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
|
||||||
|
|
||||||
def test_builtin_with_settings(self):
|
def test_builtin_with_settings(self):
|
||||||
"minimal: django-admin builtin commands fail if settings are provided as argument"
|
"minimal: django-admin builtin commands fail if settings are provided as argument"
|
||||||
args = ['sqlall','--settings=settings', 'admin_scripts']
|
args = ['sqlall','--settings=settings', 'admin_scripts']
|
||||||
|
@ -253,21 +253,21 @@ class DjangoAdminMinimalSettings(AdminScriptTestCase):
|
||||||
out, err = self.run_django_admin(args,'bad_settings')
|
out, err = self.run_django_admin(args,'bad_settings')
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Could not import settings 'bad_settings'")
|
self.assertOutput(err, "Could not import settings 'bad_settings'")
|
||||||
|
|
||||||
def test_custom_command(self):
|
def test_custom_command(self):
|
||||||
"minimal: django-admin can't execute user commands"
|
"minimal: django-admin can't execute user commands"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"minimal: django-admin can't execute user commands, even if settings are provided as argument"
|
"minimal: django-admin can't execute user commands, even if settings are provided as argument"
|
||||||
args = ['noargs_command', '--settings=settings']
|
args = ['noargs_command', '--settings=settings']
|
||||||
out, err = self.run_django_admin(args)
|
out, err = self.run_django_admin(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_environment(self):
|
def test_custom_command_with_environment(self):
|
||||||
"minimal: django-admin can't execute user commands, even if settings are provided in environment"
|
"minimal: django-admin can't execute user commands, even if settings are provided in environment"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
|
@ -281,10 +281,10 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('alternate_settings.py')
|
self.write_settings('alternate_settings.py')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('alternate_settings.py')
|
self.remove_settings('alternate_settings.py')
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"alternate: django-admin builtin commands fail with an import error when no settings provided"
|
"alternate: django-admin builtin commands fail with an import error when no settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
|
@ -345,17 +345,17 @@ class DjangoAdminAlternateSettings(AdminScriptTestCase):
|
||||||
class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
||||||
"""A series of tests for django-admin.py when multiple settings files
|
"""A series of tests for django-admin.py when multiple settings files
|
||||||
(including the default 'settings.py') are available. The default settings
|
(including the default 'settings.py') are available. The default settings
|
||||||
file is insufficient for performing the operations described, so the
|
file is insufficient for performing the operations described, so the
|
||||||
alternate settings must be used by the running script.
|
alternate settings must be used by the running script.
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
||||||
self.write_settings('alternate_settings.py')
|
self.write_settings('alternate_settings.py')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('settings.py')
|
self.remove_settings('settings.py')
|
||||||
self.remove_settings('alternate_settings.py')
|
self.remove_settings('alternate_settings.py')
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"alternate: django-admin builtin commands fail with an import error when no settings provided"
|
"alternate: django-admin builtin commands fail with an import error when no settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
|
@ -410,7 +410,7 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
||||||
out, err = self.run_django_admin(args,'alternate_settings')
|
out, err = self.run_django_admin(args,'alternate_settings')
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
##########################################################################
|
##########################################################################
|
||||||
# MANAGE.PY TESTS
|
# MANAGE.PY TESTS
|
||||||
# This next series of test classes checks the environment processing
|
# This next series of test classes checks the environment processing
|
||||||
|
@ -419,14 +419,14 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
||||||
|
|
||||||
class ManageNoSettings(AdminScriptTestCase):
|
class ManageNoSettings(AdminScriptTestCase):
|
||||||
"A series of tests for manage.py when there is no settings.py file."
|
"A series of tests for manage.py when there is no settings.py file."
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"no settings: manage.py builtin commands fail with an import error when no settings provided"
|
"no settings: manage.py builtin commands fail with an import error when no settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
|
||||||
|
|
||||||
def test_builtin_with_bad_settings(self):
|
def test_builtin_with_bad_settings(self):
|
||||||
"no settings: manage.py builtin commands fail if settings file (from argument) doesn't exist"
|
"no settings: manage.py builtin commands fail if settings file (from argument) doesn't exist"
|
||||||
args = ['sqlall','--settings=bad_settings', 'admin_scripts']
|
args = ['sqlall','--settings=bad_settings', 'admin_scripts']
|
||||||
|
@ -448,17 +448,17 @@ class ManageDefaultSettings(AdminScriptTestCase):
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('settings.py')
|
self.write_settings('settings.py')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('settings.py')
|
self.remove_settings('settings.py')
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"default: manage.py builtin commands succeed when default settings are appropriate"
|
"default: manage.py builtin commands succeed when default settings are appropriate"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertOutput(out, 'CREATE TABLE')
|
self.assertOutput(out, 'CREATE TABLE')
|
||||||
|
|
||||||
def test_builtin_with_settings(self):
|
def test_builtin_with_settings(self):
|
||||||
"default: manage.py builtin commands succeed if settings are provided as argument"
|
"default: manage.py builtin commands succeed if settings are provided as argument"
|
||||||
args = ['sqlall','--settings=settings', 'admin_scripts']
|
args = ['sqlall','--settings=settings', 'admin_scripts']
|
||||||
|
@ -493,14 +493,14 @@ class ManageDefaultSettings(AdminScriptTestCase):
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertOutput(out, "EXECUTE:NoArgsCommand")
|
self.assertOutput(out, "EXECUTE:NoArgsCommand")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"default: manage.py can execute user commands when settings are provided as argument"
|
"default: manage.py can execute user commands when settings are provided as argument"
|
||||||
args = ['noargs_command', '--settings=settings']
|
args = ['noargs_command', '--settings=settings']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertOutput(out, "EXECUTE:NoArgsCommand")
|
self.assertOutput(out, "EXECUTE:NoArgsCommand")
|
||||||
|
|
||||||
def test_custom_command_with_environment(self):
|
def test_custom_command_with_environment(self):
|
||||||
"default: manage.py can execute user commands when settings are provided in environment"
|
"default: manage.py can execute user commands when settings are provided in environment"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
|
@ -514,17 +514,17 @@ class ManageMinimalSettings(AdminScriptTestCase):
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('settings.py')
|
self.remove_settings('settings.py')
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"minimal: manage.py builtin commands fail with an import error when no settings provided"
|
"minimal: manage.py builtin commands fail with an import error when no settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
||||||
|
|
||||||
def test_builtin_with_settings(self):
|
def test_builtin_with_settings(self):
|
||||||
"minimal: manage.py builtin commands fail if settings are provided as argument"
|
"minimal: manage.py builtin commands fail if settings are provided as argument"
|
||||||
args = ['sqlall','--settings=settings', 'admin_scripts']
|
args = ['sqlall','--settings=settings', 'admin_scripts']
|
||||||
|
@ -552,21 +552,21 @@ class ManageMinimalSettings(AdminScriptTestCase):
|
||||||
out, err = self.run_manage(args,'bad_settings')
|
out, err = self.run_manage(args,'bad_settings')
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
self.assertOutput(err, 'App with label admin_scripts could not be found')
|
||||||
|
|
||||||
def test_custom_command(self):
|
def test_custom_command(self):
|
||||||
"minimal: manage.py can't execute user commands without appropriate settings"
|
"minimal: manage.py can't execute user commands without appropriate settings"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_settings(self):
|
def test_custom_command_with_settings(self):
|
||||||
"minimal: manage.py can't execute user commands, even if settings are provided as argument"
|
"minimal: manage.py can't execute user commands, even if settings are provided as argument"
|
||||||
args = ['noargs_command', '--settings=settings']
|
args = ['noargs_command', '--settings=settings']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(out)
|
self.assertNoOutput(out)
|
||||||
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
self.assertOutput(err, "Unknown command: 'noargs_command'")
|
||||||
|
|
||||||
def test_custom_command_with_environment(self):
|
def test_custom_command_with_environment(self):
|
||||||
"minimal: manage.py can't execute user commands, even if settings are provided in environment"
|
"minimal: manage.py can't execute user commands, even if settings are provided in environment"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
|
@ -580,10 +580,10 @@ class ManageAlternateSettings(AdminScriptTestCase):
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('alternate_settings.py')
|
self.write_settings('alternate_settings.py')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('alternate_settings.py')
|
self.remove_settings('alternate_settings.py')
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"alternate: manage.py builtin commands fail with an import error when no default settings provided"
|
"alternate: manage.py builtin commands fail with an import error when no default settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
|
@ -644,17 +644,17 @@ class ManageAlternateSettings(AdminScriptTestCase):
|
||||||
class ManageMultipleSettings(AdminScriptTestCase):
|
class ManageMultipleSettings(AdminScriptTestCase):
|
||||||
"""A series of tests for manage.py when multiple settings files
|
"""A series of tests for manage.py when multiple settings files
|
||||||
(including the default 'settings.py') are available. The default settings
|
(including the default 'settings.py') are available. The default settings
|
||||||
file is insufficient for performing the operations described, so the
|
file is insufficient for performing the operations described, so the
|
||||||
alternate settings must be used by the running script.
|
alternate settings must be used by the running script.
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
||||||
self.write_settings('alternate_settings.py')
|
self.write_settings('alternate_settings.py')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('settings.py')
|
self.remove_settings('settings.py')
|
||||||
self.remove_settings('alternate_settings.py')
|
self.remove_settings('alternate_settings.py')
|
||||||
|
|
||||||
def test_builtin_command(self):
|
def test_builtin_command(self):
|
||||||
"multiple: manage.py builtin commands fail with an import error when no settings provided"
|
"multiple: manage.py builtin commands fail with an import error when no settings provided"
|
||||||
args = ['sqlall','admin_scripts']
|
args = ['sqlall','admin_scripts']
|
||||||
|
@ -722,10 +722,10 @@ class CommandTypes(AdminScriptTestCase):
|
||||||
"Tests for the various types of base command types that can be defined."
|
"Tests for the various types of base command types that can be defined."
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('settings.py')
|
self.write_settings('settings.py')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('settings.py')
|
self.remove_settings('settings.py')
|
||||||
|
|
||||||
def test_version(self):
|
def test_version(self):
|
||||||
"--version is handled as a special case"
|
"--version is handled as a special case"
|
||||||
args = ['--version']
|
args = ['--version']
|
||||||
|
@ -738,7 +738,7 @@ class CommandTypes(AdminScriptTestCase):
|
||||||
"--help is handled as a special case"
|
"--help is handled as a special case"
|
||||||
args = ['--help']
|
args = ['--help']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
if sys.version_info < (2, 4):
|
if sys.version_info < (2, 5):
|
||||||
self.assertOutput(out, "usage: manage.py [options]")
|
self.assertOutput(out, "usage: manage.py [options]")
|
||||||
else:
|
else:
|
||||||
self.assertOutput(out, "Usage: manage.py [options]")
|
self.assertOutput(out, "Usage: manage.py [options]")
|
||||||
|
@ -750,14 +750,14 @@ class CommandTypes(AdminScriptTestCase):
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).")
|
self.assertOutput(out, "Prints the CREATE TABLE, custom SQL and CREATE INDEX SQL statements for the given model module name(s).")
|
||||||
|
|
||||||
def test_base_command(self):
|
def test_base_command(self):
|
||||||
"User BaseCommands can execute when a label is provided"
|
"User BaseCommands can execute when a label is provided"
|
||||||
args = ['base_command','testlabel']
|
args = ['base_command','testlabel']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None)]")
|
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', '1'), ('option_b', '2'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None)]")
|
||||||
|
|
||||||
def test_base_command_no_label(self):
|
def test_base_command_no_label(self):
|
||||||
"User BaseCommands can execute when no labels are provided"
|
"User BaseCommands can execute when no labels are provided"
|
||||||
args = ['base_command']
|
args = ['base_command']
|
||||||
|
@ -785,7 +785,7 @@ class CommandTypes(AdminScriptTestCase):
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None)]")
|
self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None)]")
|
||||||
|
|
||||||
def test_noargs(self):
|
def test_noargs(self):
|
||||||
"NoArg Commands can be executed"
|
"NoArg Commands can be executed"
|
||||||
args = ['noargs_command']
|
args = ['noargs_command']
|
||||||
|
@ -798,16 +798,16 @@ class CommandTypes(AdminScriptTestCase):
|
||||||
args = ['noargs_command','argument']
|
args = ['noargs_command','argument']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertOutput(err, "Error: Command doesn't accept any arguments")
|
self.assertOutput(err, "Error: Command doesn't accept any arguments")
|
||||||
|
|
||||||
def test_app_command(self):
|
def test_app_command(self):
|
||||||
"User AppCommands can execute when a single app name is provided"
|
"User AppCommands can execute when a single app name is provided"
|
||||||
args = ['app_command', 'auth']
|
args = ['app_command', 'auth']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertOutput(out, "EXECUTE:AppCommand app=<module 'django.contrib.auth.models'")
|
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, os.sep.join(['django','contrib','auth','models.py']))
|
||||||
self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
|
self.assertOutput(out, "'>, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
|
||||||
|
|
||||||
def test_app_command_no_apps(self):
|
def test_app_command_no_apps(self):
|
||||||
"User AppCommands raise an error when no app name is provided"
|
"User AppCommands raise an error when no app name is provided"
|
||||||
args = ['app_command']
|
args = ['app_command']
|
||||||
|
@ -830,7 +830,7 @@ class CommandTypes(AdminScriptTestCase):
|
||||||
args = ['app_command', 'NOT_AN_APP']
|
args = ['app_command', 'NOT_AN_APP']
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertOutput(err, "App with label NOT_AN_APP could not be found")
|
self.assertOutput(err, "App with label NOT_AN_APP could not be found")
|
||||||
|
|
||||||
def test_app_command_some_invalid_appnames(self):
|
def test_app_command_some_invalid_appnames(self):
|
||||||
"User AppCommands can execute when some of the provided app names are invalid"
|
"User AppCommands can execute when some of the provided app names are invalid"
|
||||||
args = ['app_command', 'auth', 'NOT_AN_APP']
|
args = ['app_command', 'auth', 'NOT_AN_APP']
|
||||||
|
@ -843,7 +843,7 @@ class CommandTypes(AdminScriptTestCase):
|
||||||
out, err = self.run_manage(args)
|
out, err = self.run_manage(args)
|
||||||
self.assertNoOutput(err)
|
self.assertNoOutput(err)
|
||||||
self.assertOutput(out, "EXECUTE:LabelCommand label=testlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
|
self.assertOutput(out, "EXECUTE:LabelCommand label=testlabel, options=[('pythonpath', None), ('settings', None), ('traceback', None)]")
|
||||||
|
|
||||||
def test_label_command_no_label(self):
|
def test_label_command_no_label(self):
|
||||||
"User LabelCommands raise an error if no label is provided"
|
"User LabelCommands raise an error if no label is provided"
|
||||||
args = ['label_command']
|
args = ['label_command']
|
||||||
|
@ -863,14 +863,14 @@ class ArgumentOrder(AdminScriptTestCase):
|
||||||
|
|
||||||
django-admin command arguments are parsed in 2 parts; the core arguments
|
django-admin command arguments are parsed in 2 parts; the core arguments
|
||||||
(--settings, --traceback and --pythonpath) are parsed using a Lax parser.
|
(--settings, --traceback and --pythonpath) are parsed using a Lax parser.
|
||||||
This Lax parser ignores any unknown options. Then the full settings are
|
This Lax parser ignores any unknown options. Then the full settings are
|
||||||
passed to the command parser, which extracts commands of interest to the
|
passed to the command parser, which extracts commands of interest to the
|
||||||
individual command.
|
individual command.
|
||||||
"""
|
"""
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
|
||||||
self.write_settings('alternate_settings.py')
|
self.write_settings('alternate_settings.py')
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
self.remove_settings('settings.py')
|
self.remove_settings('settings.py')
|
||||||
self.remove_settings('alternate_settings.py')
|
self.remove_settings('alternate_settings.py')
|
||||||
|
|
Loading…
Reference in New Issue