PageRenderTime 374ms CodeModel.GetById 120ms app.highlight 211ms RepoModel.GetById 31ms app.codeStats 1ms

/tests/regressiontests/admin_scripts/tests.py

https://code.google.com/p/mango-py/
Python | 1293 lines | 1192 code | 67 blank | 34 comment | 90 complexity | b59da4d4d2c3806b16567cc87888cd86 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1"""
   2A series of tests to establish that the command-line managment tools work as
   3advertised - especially with regards to the handling of the DJANGO_SETTINGS_MODULE
   4and default settings.py files.
   5"""
   6import os
   7import shutil
   8import sys
   9import re
  10
  11from django import conf, bin, get_version
  12from django.conf import settings
  13from django.utils import unittest
  14
  15
  16class AdminScriptTestCase(unittest.TestCase):
  17    def write_settings(self, filename, apps=None, is_dir=False, sdict=None):
  18        test_dir = os.path.dirname(os.path.dirname(__file__))
  19        if is_dir:
  20            settings_dir = os.path.join(test_dir,filename)
  21            os.mkdir(settings_dir)
  22            settings_file = open(os.path.join(settings_dir,'__init__.py'), 'w')
  23        else:
  24            settings_file = open(os.path.join(test_dir, filename), 'w')
  25        settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
  26        exports = [
  27            'DATABASES',
  28            'ROOT_URLCONF'
  29        ]
  30        for s in exports:
  31            if hasattr(settings, s):
  32                o = getattr(settings, s)
  33                if not isinstance(o, dict):
  34                    o = "'%s'" % o
  35                settings_file.write("%s = %s\n" % (s, o))
  36
  37        if apps is None:
  38            apps = ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts']
  39
  40        if apps:
  41            settings_file.write("INSTALLED_APPS = %s\n" % apps)
  42
  43        if sdict:
  44            for k, v in sdict.items():
  45                settings_file.write("%s = %s\n" % (k, v))
  46
  47        settings_file.close()
  48
  49    def remove_settings(self, filename, is_dir=False):
  50        test_dir = os.path.dirname(os.path.dirname(__file__))
  51        full_name = os.path.join(test_dir, filename)
  52        if is_dir:
  53            shutil.rmtree(full_name)
  54        else:
  55            os.remove(full_name)
  56
  57        # Also try to remove the compiled file; if it exists, it could
  58        # mess up later tests that depend upon the .py file not existing
  59        try:
  60            if sys.platform.startswith('java'):
  61                # Jython produces module$py.class files
  62                os.remove(re.sub(r'\.py$', '$py.class', full_name))
  63            else:
  64                # CPython produces module.pyc files
  65                os.remove(full_name + 'c')
  66        except OSError:
  67            pass
  68
  69    def _ext_backend_paths(self):
  70        """
  71        Returns the paths for any external backend packages.
  72        """
  73        paths = []
  74        first_package_re = re.compile(r'(^[^\.]+)\.')
  75        for backend in settings.DATABASES.values():
  76            result = first_package_re.findall(backend['ENGINE'])
  77            if result and result != 'django':
  78                backend_pkg = __import__(result[0])
  79                backend_dir = os.path.dirname(backend_pkg.__file__)
  80                paths.append(os.path.dirname(backend_dir))
  81        return paths
  82
  83    def run_test(self, script, args, settings_file=None, apps=None):
  84        test_dir = os.path.dirname(os.path.dirname(__file__))
  85        project_dir = os.path.dirname(test_dir)
  86        base_dir = os.path.dirname(project_dir)
  87        ext_backend_base_dirs = self._ext_backend_paths()
  88
  89        # Remember the old environment
  90        old_django_settings_module = os.environ.get('DJANGO_SETTINGS_MODULE', None)
  91        if sys.platform.startswith('java'):
  92            python_path_var_name = 'JYTHONPATH'
  93        else:
  94            python_path_var_name = 'PYTHONPATH'
  95
  96        old_python_path = os.environ.get(python_path_var_name, None)
  97        old_cwd = os.getcwd()
  98
  99        # Set the test environment
 100        if settings_file:
 101            os.environ['DJANGO_SETTINGS_MODULE'] = settings_file
 102        elif 'DJANGO_SETTINGS_MODULE' in os.environ:
 103            del os.environ['DJANGO_SETTINGS_MODULE']
 104        python_path = [test_dir, base_dir]
 105        python_path.extend(ext_backend_base_dirs)
 106        os.environ[python_path_var_name] = os.pathsep.join(python_path)
 107
 108        # Build the command line
 109        executable = sys.executable
 110        arg_string = ' '.join(['%s' % arg for arg in args])
 111        if ' ' in executable:
 112            cmd = '""%s" "%s" %s"' % (executable, script, arg_string)
 113        else:
 114            cmd = '%s "%s" %s' % (executable, script, arg_string)
 115
 116        # Move to the test directory and run
 117        os.chdir(test_dir)
 118        try:
 119            from subprocess import Popen, PIPE
 120            p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE)
 121            stdin, stdout, stderr = (p.stdin, p.stdout, p.stderr)
 122            p.wait()
 123        except ImportError:
 124            stdin, stdout, stderr = os.popen3(cmd)
 125        out, err = stdout.read(), stderr.read()
 126
 127        # Restore the old environment
 128        if old_django_settings_module:
 129            os.environ['DJANGO_SETTINGS_MODULE'] = old_django_settings_module
 130        if old_python_path:
 131            os.environ[python_path_var_name] = old_python_path
 132        # Move back to the old working directory
 133        os.chdir(old_cwd)
 134
 135        return out, err
 136
 137    def run_django_admin(self, args, settings_file=None):
 138        bin_dir = os.path.abspath(os.path.dirname(bin.__file__))
 139        return self.run_test(os.path.join(bin_dir,'django-admin.py'), args, settings_file)
 140
 141    def run_manage(self, args, settings_file=None):
 142        conf_dir = os.path.dirname(conf.__file__)
 143        template_manage_py = os.path.join(conf_dir, 'project_template', 'manage.py')
 144
 145        test_dir = os.path.dirname(os.path.dirname(__file__))
 146        test_manage_py = os.path.join(test_dir, 'manage.py')
 147        shutil.copyfile(template_manage_py, test_manage_py)
 148
 149        stdout, stderr = self.run_test('./manage.py', args, settings_file)
 150
 151        # Cleanup - remove the generated manage.py script
 152        os.remove(test_manage_py)
 153
 154        return stdout, stderr
 155
 156    def assertNoOutput(self, stream):
 157        "Utility assertion: assert that the given stream is empty"
 158        self.assertEqual(len(stream), 0, "Stream should be empty: actually contains '%s'" % stream)
 159    def assertOutput(self, stream, msg):
 160        "Utility assertion: assert that the given message exists in the output"
 161        self.assertTrue(msg in stream, "'%s' does not match actual output text '%s'" % (msg, stream))
 162
 163##########################################################################
 164# DJANGO ADMIN TESTS
 165# This first series of test classes checks the environment processing
 166# of the django-admin.py script
 167##########################################################################
 168
 169
 170class DjangoAdminNoSettings(AdminScriptTestCase):
 171    "A series of tests for django-admin.py when there is no settings.py file."
 172
 173    def test_builtin_command(self):
 174        "no settings: django-admin builtin commands fail with an import error when no settings provided"
 175        args = ['sqlall','admin_scripts']
 176        out, err = self.run_django_admin(args)
 177        self.assertNoOutput(out)
 178        self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
 179
 180    def test_builtin_with_bad_settings(self):
 181        "no settings: django-admin builtin commands fail if settings file (from argument) doesn't exist"
 182        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 183        out, err = self.run_django_admin(args)
 184        self.assertNoOutput(out)
 185        self.assertOutput(err, "Could not import settings 'bad_settings'")
 186
 187    def test_builtin_with_bad_environment(self):
 188        "no settings: django-admin builtin commands fail if settings file (from environment) doesn't exist"
 189        args = ['sqlall','admin_scripts']
 190        out, err = self.run_django_admin(args,'bad_settings')
 191        self.assertNoOutput(out)
 192        self.assertOutput(err, "Could not import settings 'bad_settings'")
 193
 194
 195class DjangoAdminDefaultSettings(AdminScriptTestCase):
 196    """A series of tests for django-admin.py when using a settings.py file that
 197    contains the test application.
 198    """
 199    def setUp(self):
 200        self.write_settings('settings.py')
 201
 202    def tearDown(self):
 203        self.remove_settings('settings.py')
 204
 205    def test_builtin_command(self):
 206        "default: django-admin builtin commands fail with an import error when no settings provided"
 207        args = ['sqlall','admin_scripts']
 208        out, err = self.run_django_admin(args)
 209        self.assertNoOutput(out)
 210        self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
 211
 212    def test_builtin_with_settings(self):
 213        "default: django-admin builtin commands succeed if settings are provided as argument"
 214        args = ['sqlall','--settings=settings', 'admin_scripts']
 215        out, err = self.run_django_admin(args)
 216        self.assertNoOutput(err)
 217        self.assertOutput(out, 'CREATE TABLE')
 218
 219    def test_builtin_with_environment(self):
 220        "default: django-admin builtin commands succeed if settings are provided in the environment"
 221        args = ['sqlall','admin_scripts']
 222        out, err = self.run_django_admin(args,'settings')
 223        self.assertNoOutput(err)
 224        self.assertOutput(out, 'CREATE TABLE')
 225
 226    def test_builtin_with_bad_settings(self):
 227        "default: django-admin builtin commands fail if settings file (from argument) doesn't exist"
 228        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 229        out, err = self.run_django_admin(args)
 230        self.assertNoOutput(out)
 231        self.assertOutput(err, "Could not import settings 'bad_settings'")
 232
 233    def test_builtin_with_bad_environment(self):
 234        "default: django-admin builtin commands fail if settings file (from environment) doesn't exist"
 235        args = ['sqlall','admin_scripts']
 236        out, err = self.run_django_admin(args,'bad_settings')
 237        self.assertNoOutput(out)
 238        self.assertOutput(err, "Could not import settings 'bad_settings'")
 239
 240    def test_custom_command(self):
 241        "default: django-admin can't execute user commands if it isn't provided settings"
 242        args = ['noargs_command']
 243        out, err = self.run_django_admin(args)
 244        self.assertNoOutput(out)
 245        self.assertOutput(err, "Unknown command: 'noargs_command'")
 246
 247    def test_custom_command_with_settings(self):
 248        "default: django-admin can execute user commands if settings are provided as argument"
 249        args = ['noargs_command', '--settings=settings']
 250        out, err = self.run_django_admin(args)
 251        self.assertNoOutput(err)
 252        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 253
 254    def test_custom_command_with_environment(self):
 255        "default: django-admin can execute user commands if settings are provided in environment"
 256        args = ['noargs_command']
 257        out, err = self.run_django_admin(args,'settings')
 258        self.assertNoOutput(err)
 259        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 260
 261class DjangoAdminFullPathDefaultSettings(AdminScriptTestCase):
 262    """A series of tests for django-admin.py when using a settings.py file that
 263    contains the test application specified using a full path.
 264    """
 265    def setUp(self):
 266        self.write_settings('settings.py', ['django.contrib.auth', 'django.contrib.contenttypes', 'regressiontests.admin_scripts'])
 267
 268    def tearDown(self):
 269        self.remove_settings('settings.py')
 270
 271    def test_builtin_command(self):
 272        "fulldefault: django-admin builtin commands fail with an import error when no settings provided"
 273        args = ['sqlall','admin_scripts']
 274        out, err = self.run_django_admin(args)
 275        self.assertNoOutput(out)
 276        self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
 277
 278    def test_builtin_with_settings(self):
 279        "fulldefault: django-admin builtin commands succeed if a settings file is provided"
 280        args = ['sqlall','--settings=settings', 'admin_scripts']
 281        out, err = self.run_django_admin(args)
 282        self.assertNoOutput(err)
 283        self.assertOutput(out, 'CREATE TABLE')
 284
 285    def test_builtin_with_environment(self):
 286        "fulldefault: django-admin builtin commands succeed if the environment contains settings"
 287        args = ['sqlall','admin_scripts']
 288        out, err = self.run_django_admin(args,'settings')
 289        self.assertNoOutput(err)
 290        self.assertOutput(out, 'CREATE TABLE')
 291
 292    def test_builtin_with_bad_settings(self):
 293        "fulldefault: django-admin builtin commands fail if settings file (from argument) doesn't exist"
 294        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 295        out, err = self.run_django_admin(args)
 296        self.assertNoOutput(out)
 297        self.assertOutput(err, "Could not import settings 'bad_settings'")
 298
 299    def test_builtin_with_bad_environment(self):
 300        "fulldefault: django-admin builtin commands fail if settings file (from environment) doesn't exist"
 301        args = ['sqlall','admin_scripts']
 302        out, err = self.run_django_admin(args,'bad_settings')
 303        self.assertNoOutput(out)
 304        self.assertOutput(err, "Could not import settings 'bad_settings'")
 305
 306    def test_custom_command(self):
 307        "fulldefault: django-admin can't execute user commands unless settings are provided"
 308        args = ['noargs_command']
 309        out, err = self.run_django_admin(args)
 310        self.assertNoOutput(out)
 311        self.assertOutput(err, "Unknown command: 'noargs_command'")
 312
 313    def test_custom_command_with_settings(self):
 314        "fulldefault: django-admin can execute user commands if settings are provided as argument"
 315        args = ['noargs_command', '--settings=settings']
 316        out, err = self.run_django_admin(args)
 317        self.assertNoOutput(err)
 318        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 319
 320    def test_custom_command_with_environment(self):
 321        "fulldefault: django-admin can execute user commands if settings are provided in environment"
 322        args = ['noargs_command']
 323        out, err = self.run_django_admin(args,'settings')
 324        self.assertNoOutput(err)
 325        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 326
 327class DjangoAdminMinimalSettings(AdminScriptTestCase):
 328    """A series of tests for django-admin.py when using a settings.py file that
 329    doesn't contain the test application.
 330    """
 331    def setUp(self):
 332        self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
 333
 334    def tearDown(self):
 335        self.remove_settings('settings.py')
 336
 337    def test_builtin_command(self):
 338        "minimal: django-admin builtin commands fail with an import error when no settings provided"
 339        args = ['sqlall','admin_scripts']
 340        out, err = self.run_django_admin(args)
 341        self.assertNoOutput(out)
 342        self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
 343
 344    def test_builtin_with_settings(self):
 345        "minimal: django-admin builtin commands fail if settings are provided as argument"
 346        args = ['sqlall','--settings=settings', 'admin_scripts']
 347        out, err = self.run_django_admin(args)
 348        self.assertNoOutput(out)
 349        self.assertOutput(err, 'App with label admin_scripts could not be found')
 350
 351    def test_builtin_with_environment(self):
 352        "minimal: django-admin builtin commands fail if settings are provided in the environment"
 353        args = ['sqlall','admin_scripts']
 354        out, err = self.run_django_admin(args,'settings')
 355        self.assertNoOutput(out)
 356        self.assertOutput(err, 'App with label admin_scripts could not be found')
 357
 358    def test_builtin_with_bad_settings(self):
 359        "minimal: django-admin builtin commands fail if settings file (from argument) doesn't exist"
 360        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 361        out, err = self.run_django_admin(args)
 362        self.assertNoOutput(out)
 363        self.assertOutput(err, "Could not import settings 'bad_settings'")
 364
 365    def test_builtin_with_bad_environment(self):
 366        "minimal: django-admin builtin commands fail if settings file (from environment) doesn't exist"
 367        args = ['sqlall','admin_scripts']
 368        out, err = self.run_django_admin(args,'bad_settings')
 369        self.assertNoOutput(out)
 370        self.assertOutput(err, "Could not import settings 'bad_settings'")
 371
 372    def test_custom_command(self):
 373        "minimal: django-admin can't execute user commands unless settings are provided"
 374        args = ['noargs_command']
 375        out, err = self.run_django_admin(args)
 376        self.assertNoOutput(out)
 377        self.assertOutput(err, "Unknown command: 'noargs_command'")
 378
 379    def test_custom_command_with_settings(self):
 380        "minimal: django-admin can't execute user commands, even if settings are provided as argument"
 381        args = ['noargs_command', '--settings=settings']
 382        out, err = self.run_django_admin(args)
 383        self.assertNoOutput(out)
 384        self.assertOutput(err, "Unknown command: 'noargs_command'")
 385
 386    def test_custom_command_with_environment(self):
 387        "minimal: django-admin can't execute user commands, even if settings are provided in environment"
 388        args = ['noargs_command']
 389        out, err = self.run_django_admin(args,'settings')
 390        self.assertNoOutput(out)
 391        self.assertOutput(err, "Unknown command: 'noargs_command'")
 392
 393class DjangoAdminAlternateSettings(AdminScriptTestCase):
 394    """A series of tests for django-admin.py when using a settings file
 395    with a name other than 'settings.py'.
 396    """
 397    def setUp(self):
 398        self.write_settings('alternate_settings.py')
 399
 400    def tearDown(self):
 401        self.remove_settings('alternate_settings.py')
 402
 403    def test_builtin_command(self):
 404        "alternate: django-admin builtin commands fail with an import error when no settings provided"
 405        args = ['sqlall','admin_scripts']
 406        out, err = self.run_django_admin(args)
 407        self.assertNoOutput(out)
 408        self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
 409
 410    def test_builtin_with_settings(self):
 411        "alternate: django-admin builtin commands succeed if settings are provided as argument"
 412        args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
 413        out, err = self.run_django_admin(args)
 414        self.assertNoOutput(err)
 415        self.assertOutput(out, 'CREATE TABLE')
 416
 417    def test_builtin_with_environment(self):
 418        "alternate: django-admin builtin commands succeed if settings are provided in the environment"
 419        args = ['sqlall','admin_scripts']
 420        out, err = self.run_django_admin(args,'alternate_settings')
 421        self.assertNoOutput(err)
 422        self.assertOutput(out, 'CREATE TABLE')
 423
 424    def test_builtin_with_bad_settings(self):
 425        "alternate: django-admin builtin commands fail if settings file (from argument) doesn't exist"
 426        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 427        out, err = self.run_django_admin(args)
 428        self.assertNoOutput(out)
 429        self.assertOutput(err, "Could not import settings 'bad_settings'")
 430
 431    def test_builtin_with_bad_environment(self):
 432        "alternate: django-admin builtin commands fail if settings file (from environment) doesn't exist"
 433        args = ['sqlall','admin_scripts']
 434        out, err = self.run_django_admin(args,'bad_settings')
 435        self.assertNoOutput(out)
 436        self.assertOutput(err, "Could not import settings 'bad_settings'")
 437
 438    def test_custom_command(self):
 439        "alternate: django-admin can't execute user commands unless settings are provided"
 440        args = ['noargs_command']
 441        out, err = self.run_django_admin(args)
 442        self.assertNoOutput(out)
 443        self.assertOutput(err, "Unknown command: 'noargs_command'")
 444
 445    def test_custom_command_with_settings(self):
 446        "alternate: django-admin can execute user commands if settings are provided as argument"
 447        args = ['noargs_command', '--settings=alternate_settings']
 448        out, err = self.run_django_admin(args)
 449        self.assertNoOutput(err)
 450        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 451
 452    def test_custom_command_with_environment(self):
 453        "alternate: django-admin can execute user commands if settings are provided in environment"
 454        args = ['noargs_command']
 455        out, err = self.run_django_admin(args,'alternate_settings')
 456        self.assertNoOutput(err)
 457        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 458
 459
 460class DjangoAdminMultipleSettings(AdminScriptTestCase):
 461    """A series of tests for django-admin.py when multiple settings files
 462    (including the default 'settings.py') are available. The default settings
 463    file is insufficient for performing the operations described, so the
 464    alternate settings must be used by the running script.
 465    """
 466    def setUp(self):
 467        self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
 468        self.write_settings('alternate_settings.py')
 469
 470    def tearDown(self):
 471        self.remove_settings('settings.py')
 472        self.remove_settings('alternate_settings.py')
 473
 474    def test_builtin_command(self):
 475        "alternate: django-admin builtin commands fail with an import error when no settings provided"
 476        args = ['sqlall','admin_scripts']
 477        out, err = self.run_django_admin(args)
 478        self.assertNoOutput(out)
 479        self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
 480
 481    def test_builtin_with_settings(self):
 482        "alternate: django-admin builtin commands succeed if settings are provided as argument"
 483        args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
 484        out, err = self.run_django_admin(args)
 485        self.assertNoOutput(err)
 486        self.assertOutput(out, 'CREATE TABLE')
 487
 488    def test_builtin_with_environment(self):
 489        "alternate: django-admin builtin commands succeed if settings are provided in the environment"
 490        args = ['sqlall','admin_scripts']
 491        out, err = self.run_django_admin(args,'alternate_settings')
 492        self.assertNoOutput(err)
 493        self.assertOutput(out, 'CREATE TABLE')
 494
 495    def test_builtin_with_bad_settings(self):
 496        "alternate: django-admin builtin commands fail if settings file (from argument) doesn't exist"
 497        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 498        out, err = self.run_django_admin(args)
 499        self.assertOutput(err, "Could not import settings 'bad_settings'")
 500
 501    def test_builtin_with_bad_environment(self):
 502        "alternate: django-admin builtin commands fail if settings file (from environment) doesn't exist"
 503        args = ['sqlall','admin_scripts']
 504        out, err = self.run_django_admin(args,'bad_settings')
 505        self.assertNoOutput(out)
 506        self.assertOutput(err, "Could not import settings 'bad_settings'")
 507
 508    def test_custom_command(self):
 509        "alternate: django-admin can't execute user commands unless settings are provided"
 510        args = ['noargs_command']
 511        out, err = self.run_django_admin(args)
 512        self.assertNoOutput(out)
 513        self.assertOutput(err, "Unknown command: 'noargs_command'")
 514
 515    def test_custom_command_with_settings(self):
 516        "alternate: django-admin can't execute user commands, even if settings are provided as argument"
 517        args = ['noargs_command', '--settings=alternate_settings']
 518        out, err = self.run_django_admin(args)
 519        self.assertNoOutput(err)
 520        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 521
 522    def test_custom_command_with_environment(self):
 523        "alternate: django-admin can't execute user commands, even if settings are provided in environment"
 524        args = ['noargs_command']
 525        out, err = self.run_django_admin(args,'alternate_settings')
 526        self.assertNoOutput(err)
 527        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 528
 529
 530class DjangoAdminSettingsDirectory(AdminScriptTestCase):
 531    """
 532    A series of tests for django-admin.py when the settings file is in a
 533    directory. (see #9751).
 534    """
 535
 536    def setUp(self):
 537        self.write_settings('settings', is_dir=True)
 538
 539    def tearDown(self):
 540        self.remove_settings('settings', is_dir=True)
 541
 542    def test_setup_environ(self):
 543        "directory: startapp creates the correct directory"
 544        test_dir = os.path.dirname(os.path.dirname(__file__))
 545        args = ['startapp','settings_test']
 546        out, err = self.run_django_admin(args,'settings')
 547        self.assertNoOutput(err)
 548        self.assertTrue(os.path.exists(os.path.join(test_dir, 'settings_test')))
 549        shutil.rmtree(os.path.join(test_dir, 'settings_test'))
 550
 551    def test_builtin_command(self):
 552        "directory: django-admin builtin commands fail with an import error when no settings provided"
 553        args = ['sqlall','admin_scripts']
 554        out, err = self.run_django_admin(args)
 555        self.assertNoOutput(out)
 556        self.assertOutput(err, 'environment variable DJANGO_SETTINGS_MODULE is undefined')
 557
 558    def test_builtin_with_bad_settings(self):
 559        "directory: django-admin builtin commands fail if settings file (from argument) doesn't exist"
 560        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 561        out, err = self.run_django_admin(args)
 562        self.assertOutput(err, "Could not import settings 'bad_settings'")
 563
 564    def test_builtin_with_bad_environment(self):
 565        "directory: django-admin builtin commands fail if settings file (from environment) doesn't exist"
 566        args = ['sqlall','admin_scripts']
 567        out, err = self.run_django_admin(args,'bad_settings')
 568        self.assertNoOutput(out)
 569        self.assertOutput(err, "Could not import settings 'bad_settings'")
 570
 571    def test_custom_command(self):
 572        "directory: django-admin can't execute user commands unless settings are provided"
 573        args = ['noargs_command']
 574        out, err = self.run_django_admin(args)
 575        self.assertNoOutput(out)
 576        self.assertOutput(err, "Unknown command: 'noargs_command'")
 577
 578    def test_builtin_with_settings(self):
 579        "directory: django-admin builtin commands succeed if settings are provided as argument"
 580        args = ['sqlall','--settings=settings', 'admin_scripts']
 581        out, err = self.run_django_admin(args)
 582        self.assertNoOutput(err)
 583        self.assertOutput(out, 'CREATE TABLE')
 584
 585    def test_builtin_with_environment(self):
 586        "directory: django-admin builtin commands succeed if settings are provided in the environment"
 587        args = ['sqlall','admin_scripts']
 588        out, err = self.run_django_admin(args,'settings')
 589        self.assertNoOutput(err)
 590        self.assertOutput(out, 'CREATE TABLE')
 591
 592
 593##########################################################################
 594# MANAGE.PY TESTS
 595# This next series of test classes checks the environment processing
 596# of the generated manage.py script
 597##########################################################################
 598
 599class ManageNoSettings(AdminScriptTestCase):
 600    "A series of tests for manage.py when there is no settings.py file."
 601
 602    def test_builtin_command(self):
 603        "no settings: manage.py builtin commands fail with an import error when no settings provided"
 604        args = ['sqlall','admin_scripts']
 605        out, err = self.run_manage(args)
 606        self.assertNoOutput(out)
 607        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 608
 609    def test_builtin_with_bad_settings(self):
 610        "no settings: manage.py builtin commands fail if settings file (from argument) doesn't exist"
 611        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 612        out, err = self.run_manage(args)
 613        self.assertNoOutput(out)
 614        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 615
 616    def test_builtin_with_bad_environment(self):
 617        "no settings: manage.py builtin commands fail if settings file (from environment) doesn't exist"
 618        args = ['sqlall','admin_scripts']
 619        out, err = self.run_manage(args,'bad_settings')
 620        self.assertNoOutput(out)
 621        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 622
 623
 624class ManageDefaultSettings(AdminScriptTestCase):
 625    """A series of tests for manage.py when using a settings.py file that
 626    contains the test application.
 627    """
 628    def setUp(self):
 629        self.write_settings('settings.py')
 630
 631    def tearDown(self):
 632        self.remove_settings('settings.py')
 633
 634    def test_builtin_command(self):
 635        "default: manage.py builtin commands succeed when default settings are appropriate"
 636        args = ['sqlall','admin_scripts']
 637        out, err = self.run_manage(args)
 638        self.assertNoOutput(err)
 639        self.assertOutput(out, 'CREATE TABLE')
 640
 641    def test_builtin_with_settings(self):
 642        "default: manage.py builtin commands succeed if settings are provided as argument"
 643        args = ['sqlall','--settings=settings', 'admin_scripts']
 644        out, err = self.run_manage(args)
 645        self.assertNoOutput(err)
 646        self.assertOutput(out, 'CREATE TABLE')
 647
 648    def test_builtin_with_environment(self):
 649        "default: manage.py builtin commands succeed if settings are provided in the environment"
 650        args = ['sqlall','admin_scripts']
 651        out, err = self.run_manage(args,'settings')
 652        self.assertNoOutput(err)
 653        self.assertOutput(out, 'CREATE TABLE')
 654
 655    def test_builtin_with_bad_settings(self):
 656        "default: manage.py builtin commands succeed if settings file (from argument) doesn't exist"
 657        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 658        out, err = self.run_manage(args)
 659        self.assertNoOutput(out)
 660        self.assertOutput(err, "Could not import settings 'bad_settings'")
 661
 662    def test_builtin_with_bad_environment(self):
 663        "default: manage.py builtin commands fail if settings file (from environment) doesn't exist"
 664        args = ['sqlall','admin_scripts']
 665        out, err = self.run_manage(args,'bad_settings')
 666        self.assertNoOutput(err)
 667        self.assertOutput(out, 'CREATE TABLE')
 668
 669    def test_custom_command(self):
 670        "default: manage.py can execute user commands when default settings are appropriate"
 671        args = ['noargs_command']
 672        out, err = self.run_manage(args)
 673        self.assertNoOutput(err)
 674        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 675
 676    def test_custom_command_with_settings(self):
 677        "default: manage.py can execute user commands when settings are provided as argument"
 678        args = ['noargs_command', '--settings=settings']
 679        out, err = self.run_manage(args)
 680        self.assertNoOutput(err)
 681        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 682
 683    def test_custom_command_with_environment(self):
 684        "default: manage.py can execute user commands when settings are provided in environment"
 685        args = ['noargs_command']
 686        out, err = self.run_manage(args,'settings')
 687        self.assertNoOutput(err)
 688        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 689
 690
 691class ManageFullPathDefaultSettings(AdminScriptTestCase):
 692    """A series of tests for manage.py when using a settings.py file that
 693    contains the test application specified using a full path.
 694    """
 695    def setUp(self):
 696        self.write_settings('settings.py', ['django.contrib.auth', 'django.contrib.contenttypes', 'regressiontests.admin_scripts'])
 697
 698    def tearDown(self):
 699        self.remove_settings('settings.py')
 700
 701    def test_builtin_command(self):
 702        "fulldefault: manage.py builtin commands succeed when default settings are appropriate"
 703        args = ['sqlall','admin_scripts']
 704        out, err = self.run_manage(args)
 705        self.assertNoOutput(err)
 706        self.assertOutput(out, 'CREATE TABLE')
 707
 708    def test_builtin_with_settings(self):
 709        "fulldefault: manage.py builtin commands succeed if settings are provided as argument"
 710        args = ['sqlall','--settings=settings', 'admin_scripts']
 711        out, err = self.run_manage(args)
 712        self.assertNoOutput(err)
 713        self.assertOutput(out, 'CREATE TABLE')
 714
 715    def test_builtin_with_environment(self):
 716        "fulldefault: manage.py builtin commands succeed if settings are provided in the environment"
 717        args = ['sqlall','admin_scripts']
 718        out, err = self.run_manage(args,'settings')
 719        self.assertNoOutput(err)
 720        self.assertOutput(out, 'CREATE TABLE')
 721
 722    def test_builtin_with_bad_settings(self):
 723        "fulldefault: manage.py builtin commands succeed if settings file (from argument) doesn't exist"
 724        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 725        out, err = self.run_manage(args)
 726        self.assertNoOutput(out)
 727        self.assertOutput(err, "Could not import settings 'bad_settings'")
 728
 729    def test_builtin_with_bad_environment(self):
 730        "fulldefault: manage.py builtin commands fail if settings file (from environment) doesn't exist"
 731        args = ['sqlall','admin_scripts']
 732        out, err = self.run_manage(args,'bad_settings')
 733        self.assertNoOutput(err)
 734        self.assertOutput(out, 'CREATE TABLE')
 735
 736    def test_custom_command(self):
 737        "fulldefault: manage.py can execute user commands when default settings are appropriate"
 738        args = ['noargs_command']
 739        out, err = self.run_manage(args)
 740        self.assertNoOutput(err)
 741        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 742
 743    def test_custom_command_with_settings(self):
 744        "fulldefault: manage.py can execute user commands when settings are provided as argument"
 745        args = ['noargs_command', '--settings=settings']
 746        out, err = self.run_manage(args)
 747        self.assertNoOutput(err)
 748        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 749
 750    def test_custom_command_with_environment(self):
 751        "fulldefault: manage.py can execute user commands when settings are provided in environment"
 752        args = ['noargs_command']
 753        out, err = self.run_manage(args,'settings')
 754        self.assertNoOutput(err)
 755        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 756
 757class ManageMinimalSettings(AdminScriptTestCase):
 758    """A series of tests for manage.py when using a settings.py file that
 759    doesn't contain the test application.
 760    """
 761    def setUp(self):
 762        self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
 763
 764    def tearDown(self):
 765        self.remove_settings('settings.py')
 766
 767    def test_builtin_command(self):
 768        "minimal: manage.py builtin commands fail with an import error when no settings provided"
 769        args = ['sqlall','admin_scripts']
 770        out, err = self.run_manage(args)
 771        self.assertNoOutput(out)
 772        self.assertOutput(err, 'App with label admin_scripts could not be found')
 773
 774    def test_builtin_with_settings(self):
 775        "minimal: manage.py builtin commands fail if settings are provided as argument"
 776        args = ['sqlall','--settings=settings', 'admin_scripts']
 777        out, err = self.run_manage(args)
 778        self.assertNoOutput(out)
 779        self.assertOutput(err, 'App with label admin_scripts could not be found')
 780
 781    def test_builtin_with_environment(self):
 782        "minimal: manage.py builtin commands fail if settings are provided in the environment"
 783        args = ['sqlall','admin_scripts']
 784        out, err = self.run_manage(args,'settings')
 785        self.assertNoOutput(out)
 786        self.assertOutput(err, 'App with label admin_scripts could not be found')
 787
 788    def test_builtin_with_bad_settings(self):
 789        "minimal: manage.py builtin commands fail if settings file (from argument) doesn't exist"
 790        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 791        out, err = self.run_manage(args)
 792        self.assertNoOutput(out)
 793        self.assertOutput(err, "Could not import settings 'bad_settings'")
 794
 795    def test_builtin_with_bad_environment(self):
 796        "minimal: manage.py builtin commands fail if settings file (from environment) doesn't exist"
 797        args = ['sqlall','admin_scripts']
 798        out, err = self.run_manage(args,'bad_settings')
 799        self.assertNoOutput(out)
 800        self.assertOutput(err, 'App with label admin_scripts could not be found')
 801
 802    def test_custom_command(self):
 803        "minimal: manage.py can't execute user commands without appropriate settings"
 804        args = ['noargs_command']
 805        out, err = self.run_manage(args)
 806        self.assertNoOutput(out)
 807        self.assertOutput(err, "Unknown command: 'noargs_command'")
 808
 809    def test_custom_command_with_settings(self):
 810        "minimal: manage.py can't execute user commands, even if settings are provided as argument"
 811        args = ['noargs_command', '--settings=settings']
 812        out, err = self.run_manage(args)
 813        self.assertNoOutput(out)
 814        self.assertOutput(err, "Unknown command: 'noargs_command'")
 815
 816    def test_custom_command_with_environment(self):
 817        "minimal: manage.py can't execute user commands, even if settings are provided in environment"
 818        args = ['noargs_command']
 819        out, err = self.run_manage(args,'settings')
 820        self.assertNoOutput(out)
 821        self.assertOutput(err, "Unknown command: 'noargs_command'")
 822
 823class ManageAlternateSettings(AdminScriptTestCase):
 824    """A series of tests for manage.py when using a settings file
 825    with a name other than 'settings.py'.
 826    """
 827    def setUp(self):
 828        self.write_settings('alternate_settings.py')
 829
 830    def tearDown(self):
 831        self.remove_settings('alternate_settings.py')
 832
 833    def test_builtin_command(self):
 834        "alternate: manage.py builtin commands fail with an import error when no default settings provided"
 835        args = ['sqlall','admin_scripts']
 836        out, err = self.run_manage(args)
 837        self.assertNoOutput(out)
 838        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 839
 840    def test_builtin_with_settings(self):
 841        "alternate: manage.py builtin commands fail if settings are provided as argument but no defaults"
 842        args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
 843        out, err = self.run_manage(args)
 844        self.assertNoOutput(out)
 845        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 846
 847    def test_builtin_with_environment(self):
 848        "alternate: manage.py builtin commands fail if settings are provided in the environment but no defaults"
 849        args = ['sqlall','admin_scripts']
 850        out, err = self.run_manage(args,'alternate_settings')
 851        self.assertNoOutput(out)
 852        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 853
 854    def test_builtin_with_bad_settings(self):
 855        "alternate: manage.py builtin commands fail if settings file (from argument) doesn't exist"
 856        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 857        out, err = self.run_manage(args)
 858        self.assertNoOutput(out)
 859        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 860
 861    def test_builtin_with_bad_environment(self):
 862        "alternate: manage.py builtin commands fail if settings file (from environment) doesn't exist"
 863        args = ['sqlall','admin_scripts']
 864        out, err = self.run_manage(args,'bad_settings')
 865        self.assertNoOutput(out)
 866        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 867
 868    def test_custom_command(self):
 869        "alternate: manage.py can't execute user commands"
 870        args = ['noargs_command']
 871        out, err = self.run_manage(args)
 872        self.assertNoOutput(out)
 873        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 874
 875    def test_custom_command_with_settings(self):
 876        "alternate: manage.py can't execute user commands, even if settings are provided as argument"
 877        args = ['noargs_command', '--settings=alternate_settings']
 878        out, err = self.run_manage(args)
 879        self.assertNoOutput(out)
 880        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 881
 882    def test_custom_command_with_environment(self):
 883        "alternate: manage.py can't execute user commands, even if settings are provided in environment"
 884        args = ['noargs_command']
 885        out, err = self.run_manage(args,'alternate_settings')
 886        self.assertNoOutput(out)
 887        self.assertOutput(err, "Can't find the file 'settings.py' in the directory containing './manage.py'")
 888
 889
 890class ManageMultipleSettings(AdminScriptTestCase):
 891    """A series of tests for manage.py when multiple settings files
 892    (including the default 'settings.py') are available. The default settings
 893    file is insufficient for performing the operations described, so the
 894    alternate settings must be used by the running script.
 895    """
 896    def setUp(self):
 897        self.write_settings('settings.py', apps=['django.contrib.auth','django.contrib.contenttypes'])
 898        self.write_settings('alternate_settings.py')
 899
 900    def tearDown(self):
 901        self.remove_settings('settings.py')
 902        self.remove_settings('alternate_settings.py')
 903
 904    def test_builtin_command(self):
 905        "multiple: manage.py builtin commands fail with an import error when no settings provided"
 906        args = ['sqlall','admin_scripts']
 907        out, err = self.run_manage(args)
 908        self.assertNoOutput(out)
 909        self.assertOutput(err, 'App with label admin_scripts could not be found.')
 910
 911    def test_builtin_with_settings(self):
 912        "multiple: manage.py builtin commands succeed if settings are provided as argument"
 913        args = ['sqlall','--settings=alternate_settings', 'admin_scripts']
 914        out, err = self.run_manage(args)
 915        self.assertNoOutput(err)
 916        self.assertOutput(out, 'CREATE TABLE')
 917
 918    def test_builtin_with_environment(self):
 919        "multiple: manage.py builtin commands fail if settings are provided in the environment"
 920        # FIXME: This doesn't seem to be the correct output.
 921        args = ['sqlall','admin_scripts']
 922        out, err = self.run_manage(args,'alternate_settings')
 923        self.assertNoOutput(out)
 924        self.assertOutput(err, 'App with label admin_scripts could not be found.')
 925
 926    def test_builtin_with_bad_settings(self):
 927        "multiple: manage.py builtin commands fail if settings file (from argument) doesn't exist"
 928        args = ['sqlall','--settings=bad_settings', 'admin_scripts']
 929        out, err = self.run_manage(args)
 930        self.assertNoOutput(out)
 931        self.assertOutput(err, "Could not import settings 'bad_settings'")
 932
 933    def test_builtin_with_bad_environment(self):
 934        "multiple: manage.py builtin commands fail if settings file (from environment) doesn't exist"
 935        args = ['sqlall','admin_scripts']
 936        out, err = self.run_manage(args,'bad_settings')
 937        self.assertNoOutput(out)
 938        self.assertOutput(err, "App with label admin_scripts could not be found")
 939
 940    def test_custom_command(self):
 941        "multiple: manage.py can't execute user commands using default settings"
 942        args = ['noargs_command']
 943        out, err = self.run_manage(args)
 944        self.assertNoOutput(out)
 945        self.assertOutput(err, "Unknown command: 'noargs_command'")
 946
 947    def test_custom_command_with_settings(self):
 948        "multiple: manage.py can execute user commands if settings are provided as argument"
 949        args = ['noargs_command', '--settings=alternate_settings']
 950        out, err = self.run_manage(args)
 951        self.assertNoOutput(err)
 952        self.assertOutput(out, "EXECUTE:NoArgsCommand")
 953
 954    def test_custom_command_with_environment(self):
 955        "multiple: manage.py can execute user commands if settings are provided in environment"
 956        args = ['noargs_command']
 957        out, err = self.run_manage(args,'alternate_settings')
 958        self.assertNoOutput(out)
 959        self.assertOutput(err, "Unknown command: 'noargs_command'")
 960
 961class ManageSettingsWithImportError(AdminScriptTestCase):
 962    """Tests for manage.py when using the default settings.py file
 963    with an import error. Ticket #14130.
 964    """
 965    def setUp(self):
 966        self.write_settings_with_import_error('settings.py')
 967
 968    def tearDown(self):
 969        self.remove_settings('settings.py')
 970
 971    def write_settings_with_import_error(self, filename, apps=None, is_dir=False, sdict=None):
 972        test_dir = os.path.dirname(os.path.dirname(__file__))
 973        if is_dir:
 974            settings_dir = os.path.join(test_dir,filename)
 975            os.mkdir(settings_dir)
 976            settings_file = open(os.path.join(settings_dir,'__init__.py'), 'w')
 977        else:
 978            settings_file = open(os.path.join(test_dir, filename), 'w')
 979        settings_file.write('# Settings file automatically generated by regressiontests.admin_scripts test case\n')
 980        settings_file.write('# The next line will cause an import error:\nimport foo42bar\n')
 981
 982        settings_file.close()
 983
 984    def test_builtin_command(self):
 985        "import error: manage.py builtin commands shows useful diagnostic info when settings with import errors is provided"
 986        args = ['sqlall','admin_scripts']
 987        out, err = self.run_manage(args)
 988        self.assertNoOutput(out)
 989        self.assertOutput(err, "ImportError: No module named foo42bar")
 990
 991class ManageValidate(AdminScriptTestCase):
 992    def tearDown(self):
 993        self.remove_settings('settings.py')
 994
 995    def test_nonexistent_app(self):
 996        "manage.py validate reports an error on a non-existent app in INSTALLED_APPS"
 997        self.write_settings('settings.py', apps=['admin_scriptz.broken_app'], sdict={'USE_I18N': False})
 998        args = ['validate']
 999        out, err = self.run_manage(args)
1000        self.assertNoOutput(out)
1001        self.assertOutput(err, 'No module named admin_scriptz')
1002
1003    def test_broken_app(self):
1004        "manage.py validate reports an ImportError if an app's models.py raises one on import"
1005        self.write_settings('settings.py', apps=['admin_scripts.broken_app'])
1006        args = ['validate']
1007        out, err = self.run_manage(args)
1008        self.assertNoOutput(out)
1009        self.assertOutput(err, 'ImportError')
1010
1011    def test_complex_app(self):
1012        "manage.py validate does not raise an ImportError validating a complex app with nested calls to load_app"
1013        self.write_settings('settings.py',
1014            apps=['admin_scripts.complex_app', 'admin_scripts.simple_app'],
1015            sdict={'DEBUG': True})
1016        args = ['validate']
1017        out, err = self.run_manage(args)
1018        self.assertNoOutput(err)
1019        self.assertOutput(out, '0 errors found')
1020
1021    def test_app_with_import(self):
1022        "manage.py validate does not raise errors when an app imports a base class that itself has an abstract base"
1023        self.write_settings('settings.py',
1024            apps=['admin_scripts.app_with_import', 'django.contrib.comments'],
1025            sdict={'DEBUG': True})
1026        args = ['validate']
1027        out, err = self.run_manage(args)
1028        self.assertNoOutput(err)
1029        self.assertOutput(out, '0 errors found')
1030
1031class ManageRunserver(AdminScriptTestCase):
1032    def setUp(self):
1033        from django.core.management.commands.runserver import BaseRunserverCommand
1034        def monkey_run(*args, **options): return
1035
1036        self.cmd = BaseRunserverCommand()
1037        self.cmd.run = monkey_run
1038
1039    def assertServerSettings(self, addr, port, ipv6=None, raw_ipv6=False):
1040        self.assertEqual(self.cmd.addr, addr)
1041        self.assertEqual(self.cmd.port, port)
1042        self.assertEqual(self.cmd.use_ipv6, ipv6)
1043        self.assertEqual(self.cmd._raw_ipv6, raw_ipv6)
1044
1045    def test_runserver_addrport(self):
1046        self.cmd.handle()
1047        self.assertServerSettings('127.0.0.1', '8000')
1048
1049        self.cmd.handle(addrport="1.2.3.4:8000")
1050        self.assertServerSettings('1.2.3.4', '8000')
1051
1052        self.cmd.handle(addrport="7000")
1053        self.assertServerSettings('127.0.0.1', '7000')
1054
1055        # IPv6
1056        self.cmd.handle(addrport="", use_ipv6=True)
1057        self.assertServerSettings('::1', '8000', ipv6=True, raw_ipv6=True)
1058
1059        self.cmd.handle(addrport="7000", use_ipv6=True)
1060        self.assertServerSettings('::1', '7000', ipv6=True, raw_ipv6=True)
1061
1062        self.cmd.handle(addrport="[2001:0db8:1234:5678::9]:7000")
1063        self.assertServerSettings('2001:0db8:1234:5678::9', '7000', ipv6=True, raw_ipv6=True)
1064
1065        # Hostname
1066        self.cmd.handle(addrport="localhost:8000")
1067        self.assertServerSettings('localhost', '8000')
1068
1069        self.cmd.handle(addrport="test.domain.local:7000")
1070        self.assertServerSettings('test.domain.local', '7000')
1071
1072        self.cmd.handle(addrport="test.domain.local:7000", use_ipv6=True)
1073        self.assertServerSettings('test.domain.local', '7000', ipv6=True)
1074
1075        # Potentially ambiguous
1076
1077        # Only 4 characters, all of which could be in an ipv6 address
1078        self.cmd.handle(addrport="beef:7654")
1079        self.assertServerSettings('beef', '7654')
1080
1081        # Uses only characters that could be in an ipv6 address
1082        self.cmd.handle(addrport="deadbeef:7654")
1083        self.assertServerSettings('deadbeef', '7654')
1084
1085
1086##########################################################################
1087# COMMAND PROCESSING TESTS
1088# Check that user-space commands are correctly handled - in particular,
1089# that arguments to the commands are correctly parsed and processed.
1090##########################################################################
1091
1092class CommandTypes(AdminScriptTestCase):
1093    "Tests for the various types of base command types that can be defined."
1094    def setUp(self):
1095        self.write_settings('settings.py')
1096
1097    def tearDown(self):
1098        self.remove_settings('settings.py')
1099
1100    def test_version(self):
1101        "--version is handled as a special case"
1102        args = ['--version']
1103        out, err = self.run_manage(args)
1104        self.assertNoOutput(err)
1105        # Only check the first part of the version number
1106        self.assertOutput(out, g

Large files files are truncated, but you can click here to view the full file