Code

Ticket #13612: 13612.diff

File 13612.diff, 4.7 KB (added by graham_king, 3 years ago)

Try behaving like django-admin, only output error if that doesn't work. Also changed tests.

Line 
1Index: tests/regressiontests/admin_scripts/tests.py
2===================================================================
3--- tests/regressiontests/admin_scripts/tests.py        (revision 16251)
4+++ tests/regressiontests/admin_scripts/tests.py        (working copy)
5@@ -840,18 +840,18 @@
6         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
7 
8     def test_builtin_with_settings(self):
9-        "alternate: manage.py builtin commands fail if settings are provided as argument but no defaults"
10+        "alternate: manage.py builtin commands succeed if settings are provided as argument"
11         args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
12         out, err = self.run_manage(args)
13-        self.assertNoOutput(out)
14-        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
15+        self.assertNoOutput(err)
16+        self.assertOutput(out, 'CREATE TABLE')
17 
18     def test_builtin_with_environment(self):
19-        "alternate: manage.py builtin commands fail if settings are provided in the environment but no defaults"
20+        "alternate: manage.py builtin commands succeed if settings are provided in the environment"
21         args = ['sqlall','admin_scripts']
22         out, err = self.run_manage(args,'alternate_settings')
23-        self.assertNoOutput(out)
24-        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
25+        self.assertNoOutput(err)
26+        self.assertOutput(out, 'CREATE TABLE')
27 
28     def test_builtin_with_bad_settings(self):
29         "alternate: manage.py builtin commands fail if settings file (from argument) doesn't exist"
30@@ -868,25 +868,25 @@
31         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
32 
33     def test_custom_command(self):
34-        "alternate: manage.py can't execute user commands"
35+        "alternate: manage.py can't execute user commands if it isn't provided settings"
36         args = ['noargs_command']
37         out, err = self.run_manage(args)
38         self.assertNoOutput(out)
39-        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
40+        self.assertOutput(err, "Unknown command: 'noargs_command'")
41 
42     def test_custom_command_with_settings(self):
43-        "alternate: manage.py can't execute user commands, even if settings are provided as argument"
44+        "alternate: manage.py can execute user commands if settings are provided as argument"
45         args = ['noargs_command', '--settings=alternate_settings']
46         out, err = self.run_manage(args)
47-        self.assertNoOutput(out)
48-        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
49+        self.assertNoOutput(err)
50+        self.assertOutput(out, "EXECUTE:NoArgsCommand")
51 
52     def test_custom_command_with_environment(self):
53-        "alternate: manage.py can't execute user commands, even if settings are provided in environment"
54+        "alternate: manage.py can execute user commands if settings are provided in environment"
55         args = ['noargs_command']
56         out, err = self.run_manage(args,'alternate_settings')
57-        self.assertNoOutput(out)
58-        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
59+        self.assertNoOutput(err)
60+        self.assertOutput(out, "EXECUTE:NoArgsCommand")
61 
62 
63 class ManageMultipleSettings(AdminScriptTestCase):
64Index: django/conf/project_template/manage.py
65===================================================================
66--- django/conf/project_template/manage.py      (revision 16251)
67+++ django/conf/project_template/manage.py      (working copy)
68@@ -1,14 +1,23 @@
69 #!/usr/bin/env python
70-from django.core.management import execute_manager
71+from django.core import management
72 import imp
73+
74 try:
75     imp.find_module('settings') # Assumed to be in the same directory.
76+
77 except ImportError:
78+
79     import sys
80-    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
81+
82+    try:
83+        # No settings.py, try like django-admin.py does
84+        management.execute_from_command_line()
85+    except ImportError:
86+        sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__)
87+
88     sys.exit(1)
89 
90 import settings
91 
92 if __name__ == "__main__":
93-    execute_manager(settings)
94+    management.execute_manager(settings)