summaryrefslogtreecommitdiff
path: root/tests/regressiontests/admin_scripts/tests.py
diff options
context:
space:
mode:
authorJacob Kaplan-Moss <jacob@jacobian.org>2009-05-12 21:45:03 +0000
committerJacob Kaplan-Moss <jacob@jacobian.org>2009-05-12 21:45:03 +0000
commitd20a0834ac344ee79880c353d2c40639ee3837da (patch)
tree7a06defc49010a7944eb7b847efb55abcd66ae31 /tests/regressiontests/admin_scripts/tests.py
parent9140f97f9db83db37e0d7e6a97f45aa27ac1bd8f (diff)
Fixed #9751: admin scripts now calculate the project directory correctly when the settings module is a directory with an ``__init__.py``. Thanks to Eric Holscher.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@10751 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests/admin_scripts/tests.py')
-rw-r--r--tests/regressiontests/admin_scripts/tests.py81
1 files changed, 76 insertions, 5 deletions
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index dd2f515d12..0e28a9749f 100644
--- a/tests/regressiontests/admin_scripts/tests.py
+++ b/tests/regressiontests/admin_scripts/tests.py
@@ -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')]")
-