Ticket #13612: 13612.diff

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

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

  • tests/regressiontests/admin_scripts/tests.py

     
    840840        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
    841841
    842842    def test_builtin_with_settings(self):
    843         "alternate: manage.py builtin commands fail if settings are provided as argument but no defaults"
     843        "alternate: manage.py builtin commands succeed if settings are provided as argument"
    844844        args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
    845845        out, err = self.run_manage(args)
    846         self.assertNoOutput(out)
    847         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     846        self.assertNoOutput(err)
     847        self.assertOutput(out, 'CREATE TABLE')
    848848
    849849    def test_builtin_with_environment(self):
    850         "alternate: manage.py builtin commands fail if settings are provided in the environment but no defaults"
     850        "alternate: manage.py builtin commands succeed if settings are provided in the environment"
    851851        args = ['sqlall','admin_scripts']
    852852        out, err = self.run_manage(args,'alternate_settings')
    853         self.assertNoOutput(out)
    854         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     853        self.assertNoOutput(err)
     854        self.assertOutput(out, 'CREATE TABLE')
    855855
    856856    def test_builtin_with_bad_settings(self):
    857857        "alternate: manage.py builtin commands fail if settings file (from argument) doesn't exist"
     
    868868        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
    869869
    870870    def test_custom_command(self):
    871         "alternate: manage.py can't execute user commands"
     871        "alternate: manage.py can't execute user commands if it isn't provided settings"
    872872        args = ['noargs_command']
    873873        out, err = self.run_manage(args)
    874874        self.assertNoOutput(out)
    875         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     875        self.assertOutput(err, "Unknown command: 'noargs_command'")
    876876
    877877    def test_custom_command_with_settings(self):
    878         "alternate: manage.py can't execute user commands, even if settings are provided as argument"
     878        "alternate: manage.py can execute user commands if settings are provided as argument"
    879879        args = ['noargs_command', '--settings=alternate_settings']
    880880        out, err = self.run_manage(args)
    881         self.assertNoOutput(out)
    882         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     881        self.assertNoOutput(err)
     882        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    883883
    884884    def test_custom_command_with_environment(self):
    885         "alternate: manage.py can't execute user commands, even if settings are provided in environment"
     885        "alternate: manage.py can execute user commands if settings are provided in environment"
    886886        args = ['noargs_command']
    887887        out, err = self.run_manage(args,'alternate_settings')
    888         self.assertNoOutput(out)
    889         self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
     888        self.assertNoOutput(err)
     889        self.assertOutput(out, "EXECUTE:NoArgsCommand")
    890890
    891891
    892892class ManageMultipleSettings(AdminScriptTestCase):
  • django/conf/project_template/manage.py

     
    11#!/usr/bin/env python
    2 from django.core.management import execute_manager
     2from django.core import management
    33import imp
     4
    45try:
    56    imp.find_module('settings') # Assumed to be in the same directory.
     7
    68except ImportError:
     9
    710    import sys
    8     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__)
     11
     12    try:
     13        # No settings.py, try like django-admin.py does
     14        management.execute_from_command_line()
     15    except ImportError:
     16        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__)
     17
    918    sys.exit(1)
    1019
    1120import settings
    1221
    1322if __name__ == "__main__":
    14     execute_manager(settings)
     23    management.execute_manager(settings)
Back to Top