|
@@ -13,9 +13,14 @@ from django import conf, bin, get_version
|
|
|
from django.conf import settings
|
|
|
|
|
|
class AdminScriptTestCase(unittest.TestCase):
|
|
|
- def write_settings(self, filename, apps=None):
|
|
|
+ def write_settings(self, filename, apps=None, is_dir=False):
|
|
|
test_dir = os.path.dirname(os.path.dirname(__file__))
|
|
|
- settings_file = open(os.path.join(test_dir,filename), 'w')
|
|
|
+ if is_dir:
|
|
|
+ settings_dir = os.path.join(test_dir,filename)
|
|
|
+ os.mkdir(settings_dir)
|
|
|
+ settings_file = open(os.path.join(settings_dir,'__init__.py'), 'w')
|
|
|
+ else:
|
|
|
+ settings_file = open(os.path.join(test_dir, filename), 'w')
|
|
|
settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
|
|
|
exports = [
|
|
|
'DATABASE_ENGINE',
|
|
@@ -38,10 +43,13 @@ class AdminScriptTestCase(unittest.TestCase):
|
|
|
|
|
|
settings_file.close()
|
|
|
|
|
|
- def remove_settings(self, filename):
|
|
|
+ def remove_settings(self, filename, is_dir=False):
|
|
|
test_dir = os.path.dirname(os.path.dirname(__file__))
|
|
|
full_name = os.path.join(test_dir, filename)
|
|
|
- os.remove(full_name)
|
|
|
+ if is_dir:
|
|
|
+ shutil.rmtree(full_name)
|
|
|
+ else:
|
|
|
+ os.remove(full_name)
|
|
|
|
|
|
# Also try to remove the compiled file; if it exists, it could
|
|
|
# mess up later tests that depend upon the .py file not existing
|
|
@@ -509,6 +517,70 @@ class DjangoAdminMultipleSettings(AdminScriptTestCase):
|
|
|
self.assertNoOutput(err)
|
|
|
self.assertOutput(out, "EXECUTE:NoArgsCommand")
|
|
|
|
|
|
+
|
|
|
+class DjangoAdminSettingsDirectory(AdminScriptTestCase):
|
|
|
+ """
|
|
|
+ A series of tests for django-admin.py when the settings file is in a
|
|
|
+ directory. (see #9751).
|
|
|
+ """
|
|
|
+
|
|
|
+ def setUp(self):
|
|
|
+ self.write_settings('settings', is_dir=True)
|
|
|
+
|
|
|
+ def tearDown(self):
|
|
|
+ self.remove_settings('settings', is_dir=True)
|
|
|
+
|
|
|
+ def test_setup_environ(self):
|
|
|
+ "directory: startapp creates the correct directory"
|
|
|
+ test_dir = os.path.dirname(os.path.dirname(__file__))
|
|
|
+ args = ['startapp','settings_test']
|
|
|
+ out, err = self.run_django_admin(args,'settings')
|
|
|
+ self.assertNoOutput(err)
|
|
|
+ self.assertTrue(os.path.exists(os.path.join(test_dir, 'settings_test')))
|
|
|
+ shutil.rmtree(os.path.join(test_dir, 'settings_test'))
|
|
|
+
|
|
|
+ def test_builtin_command(self):
|
|
|
+ "directory: django-admin builtin commands fail with an import error when no settings provided"
|
|
|
+ args = ['sqlall','admin_scripts']
|
|
|
+ out, err = self.run_django_admin(args)
|
|
|
+ self.assertNoOutput(out)
|
|
|
+ self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
|
|
|
+
|
|
|
+ def test_builtin_with_bad_settings(self):
|
|
|
+ "directory: django-admin builtin commands fail if settings file (from argument) doesn't exist"
|
|
|
+ args = ['sqlall','--settings=bad_settings', 'admin_scripts']
|
|
|
+ out, err = self.run_django_admin(args)
|
|
|
+ self.assertOutput(err, "Could not import settings 'bad_settings'")
|
|
|
+
|
|
|
+ def test_builtin_with_bad_environment(self):
|
|
|
+ "directory: django-admin builtin commands fail if settings file (from environment) doesn't exist"
|
|
|
+ args = ['sqlall','admin_scripts']
|
|
|
+ out, err = self.run_django_admin(args,'bad_settings')
|
|
|
+ self.assertNoOutput(out)
|
|
|
+ self.assertOutput(err, "Could not import settings 'bad_settings'")
|
|
|
+
|
|
|
+ def test_custom_command(self):
|
|
|
+ "directory: django-admin can't execute user commands unless settings are provided"
|
|
|
+ args = ['noargs_command']
|
|
|
+ out, err = self.run_django_admin(args)
|
|
|
+ self.assertNoOutput(out)
|
|
|
+ self.assertOutput(err, "Unknown command: 'noargs_command'")
|
|
|
+
|
|
|
+ def test_builtin_with_settings(self):
|
|
|
+ "directory: django-admin builtin commands succeed if settings are provided as argument"
|
|
|
+ args = ['sqlall','--settings=settings', 'admin_scripts']
|
|
|
+ out, err = self.run_django_admin(args)
|
|
|
+ self.assertNoOutput(err)
|
|
|
+ self.assertOutput(out, 'CREATE TABLE')
|
|
|
+
|
|
|
+ def test_builtin_with_environment(self):
|
|
|
+ "directory: django-admin builtin commands succeed if settings are provided in the environment"
|
|
|
+ args = ['sqlall','admin_scripts']
|
|
|
+ out, err = self.run_django_admin(args,'settings')
|
|
|
+ self.assertNoOutput(err)
|
|
|
+ self.assertOutput(out, 'CREATE TABLE')
|
|
|
+
|
|
|
+
|
|
|
##########################################################################
|
|
|
# MANAGE.PY TESTS
|
|
|
# This next series of test classes checks the environment processing
|
|
@@ -1075,4 +1147,3 @@ class ArgumentOrder(AdminScriptTestCase):
|
|
|
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), ('settings', 'alternate_settings'), ('traceback', None), ('verbosity', '1')]")
|
|
|
-
|