Commits

Andrew Godwin committed b6fa8b1

Patch from #433 for test code refactor

Comments (0)

Files changed (3)

south/management/commands/syncdb.py

             if verbosity:
                 print "\nNot synced (use migrations):\n - %s" % "\n - ".join(apps_migrated)
                 print "(use ./manage.py migrate to migrate these)"
+
+class MigrateAndSyncCommand(Command):
+    """Used for situations where "syncdb" is called by test frameworks."""
+    option_list = Command.option_list
+    for opt in option_list:
+        if "--migrate" == opt.get_opt_string():
+            opt.default = True
+            break
+
+def patch_for_test_db_setup():
+        management.get_commands()
+        if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE:
+            # point at the core syncdb command when creating tests
+            # tests should always be up to date with the most recent model structure
+            management._commands['syncdb'] = 'django.core'
+        else:
+            management._commands['syncdb'] = MigrateAndSyncCommand()

south/management/commands/test.py

-from django.core import management
 from django.core.management.commands import test
-from django.core.management.commands import syncdb
-from django.conf import settings
-
-from syncdb import Command as SyncDbCommand
-
-
-class MigrateAndSyncCommand(SyncDbCommand):
-    option_list = SyncDbCommand.option_list
-    for opt in option_list:
-        if "--migrate" == opt.get_opt_string():
-            opt.default = True
-            break
-
+import south.management.commands.syncdb
 
 class Command(test.Command):
-    
     def handle(self, *args, **kwargs):
-        management.get_commands()
-        if hasattr(settings, "SOUTH_TESTS_MIGRATE") and not settings.SOUTH_TESTS_MIGRATE:
-            # point at the core syncdb command when creating tests
-            # tests should always be up to date with the most recent model structure
-            management._commands['syncdb'] = 'django.core'
-        else:
-            management._commands['syncdb'] = MigrateAndSyncCommand()
-        super(Command, self).handle(*args, **kwargs)
+        south.management.commands.syncdb.patch_for_test_db_setup()
+        super(Command, self).handle(*args, **kwargs)

south/management/commands/testserver.py

-from django.core import management
 from django.core.management.commands import testserver
-from django.core.management.commands import syncdb
-from django.conf import settings
-
-from syncdb import Command as SyncDbCommand
-
-
-class MigrateAndSyncCommand(SyncDbCommand):
-    option_list = SyncDbCommand.option_list
-    for opt in option_list:
-        if "--migrate" == opt.get_opt_string():
-            opt.default = True
-            break
-
+import south.management.commands.syncdb
 
 class Command(testserver.Command):
-    
     def handle(self, *args, **kwargs):
-        management.get_commands()
-        if not hasattr(settings, "SOUTH_TESTS_MIGRATE") or not settings.SOUTH_TESTS_MIGRATE:
-            # point at the core syncdb command when creating tests
-            # tests should always be up to date with the most recent model structure
-            management._commands['syncdb'] = 'django.core'
-        else:
-            management._commands['syncdb'] = MigrateAndSyncCommand()
-        super(Command, self).handle(*args, **kwargs)
+        south.management.commands.syncdb.patch_for_test_db_setup()
+        super(Command, self).handle(*args, **kwargs)