Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix test running with new apps stuff/migrate actually running migrations

  • Loading branch information...
commit 2ae8a8a77d6968a155db9b17ba13e21d91bd351b 1 parent 9daf81b
@andrewgodwin andrewgodwin authored
View
7 django/conf/global_settings.py
@@ -602,3 +602,10 @@
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder',
)
+
+##############
+# MIGRATIONS #
+##############
+
+# Migration module overrides for apps, by app label.
+MIGRATION_MODULES = {}
View
7 django/db/backends/creation.py
@@ -331,14 +331,15 @@ def create_test_db(self, verbosity=1, autoclobber=False):
settings.DATABASES[self.connection.alias]["NAME"] = test_database_name
self.connection.settings_dict["NAME"] = test_database_name
- # Report syncdb messages at one level lower than that requested.
+ # Report migrate messages at one level lower than that requested.
# This ensures we don't get flooded with messages during testing
# (unless you really ask to be flooded)
- call_command('syncdb',
+ call_command('migrate',
verbosity=max(verbosity - 1, 0),
interactive=False,
database=self.connection.alias,
- load_initial_data=False)
+ load_initial_data=False,
+ test_database=True)
# We need to then do a flush to ensure that any data installed by
# custom SQL has been removed. The only test data should come from
View
11 django/db/migrations/loader.py
@@ -4,6 +4,7 @@
from django.db.models.loading import cache
from django.db.migrations.recorder import MigrationRecorder
from django.db.migrations.graph import MigrationGraph
+from django.conf import settings
class MigrationLoader(object):
@@ -36,6 +37,12 @@ def __init__(self, connection):
self.disk_migrations = None
self.applied_migrations = None
+ def migration_module(self, app_label):
+ if app_label in settings.MIGRATION_MODULES:
+ return settings.MIGRATION_MODULES[app_label]
+ app = cache.get_app(app_label)
+ return ".".join(app.__name__.split(".")[:-1] + ["migrations"])
+
def load_disk(self):
"""
Loads the migrations from all INSTALLED_APPS from disk.
@@ -44,8 +51,8 @@ def load_disk(self):
self.unmigrated_apps = set()
for app in cache.get_apps():
# Get the migrations module directory
- module_name = ".".join(app.__name__.split(".")[:-1] + ["migrations"])
- app_label = module_name.split(".")[-2]
+ app_label = app.__name__.split(".")[-2]
+ module_name = self.migration_module(app_label)
try:
module = import_module(module_name)
except ImportError as e:
View
2  django/test/runner.py
@@ -266,7 +266,7 @@ def setup_databases(verbosity, interactive, **kwargs):
# Second pass -- actually create the databases.
old_names = []
mirrors = []
-
+
for signature, (db_name, aliases) in dependency_ordered(
test_databases.items(), dependencies):
test_db_name = None
View
4 tests/migrations/test_executor.py
@@ -1,4 +1,5 @@
from django.test import TransactionTestCase
+from django.test.utils import override_settings
from django.db import connection
from django.db.migrations.executor import MigrationExecutor
@@ -11,6 +12,9 @@ class ExecutorTests(TransactionTestCase):
test failures first, as they may be propagating into here.
"""
+ available_apps = ["migrations"]
+
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_run(self):
"""
Tests running a simple set of migrations.
View
6 tests/migrations/test_loader.py
@@ -1,4 +1,5 @@
-from django.test import TestCase, TransactionTestCase
+from django.test import TestCase
+from django.test.utils import override_settings
from django.db import connection
from django.db.migrations.loader import MigrationLoader
from django.db.migrations.recorder import MigrationRecorder
@@ -30,12 +31,13 @@ def test_apply(self):
)
-class LoaderTests(TransactionTestCase):
+class LoaderTests(TestCase):
"""
Tests the disk and database loader, and running through migrations
in memory.
"""
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_load(self):
"""
Makes sure the loader can load the migrations for the test apps,
View
4 tests/migrations/test_operations.py
@@ -1,9 +1,9 @@
-from django.test import TransactionTestCase
+from django.test import TestCase
from django.db import connection, models, migrations
from django.db.migrations.state import ProjectState
-class OperationTests(TransactionTestCase):
+class OperationTests(TestCase):
"""
Tests running the operations and making sure they do what they say they do.
Each test looks at their state changing, and then their database operation -
View
4 tests/migrations/test_writer.py
@@ -1,12 +1,12 @@
# encoding: utf8
import datetime
from django.utils import six
-from django.test import TransactionTestCase
+from django.test import TestCase
from django.db.migrations.writer import MigrationWriter
from django.db import models, migrations
-class WriterTests(TransactionTestCase):
+class WriterTests(TestCase):
"""
Tests the migration writer (makes migration files from Migration instances)
"""
Please sign in to comment.
Something went wrong with that request. Please try again.