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

This commit is contained in:
Andrew Godwin 2013-06-19 15:36:02 +01:00
parent 9daf81b94e
commit 2ae8a8a77d
8 changed files with 33 additions and 12 deletions

View File

@ -602,3 +602,10 @@ STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.AppDirectoriesFinder', 'django.contrib.staticfiles.finders.AppDirectoriesFinder',
# 'django.contrib.staticfiles.finders.DefaultStorageFinder', # 'django.contrib.staticfiles.finders.DefaultStorageFinder',
) )
##############
# MIGRATIONS #
##############
# Migration module overrides for apps, by app label.
MIGRATION_MODULES = {}

View File

@ -331,14 +331,15 @@ class BaseDatabaseCreation(object):
settings.DATABASES[self.connection.alias]["NAME"] = test_database_name settings.DATABASES[self.connection.alias]["NAME"] = test_database_name
self.connection.settings_dict["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 # This ensures we don't get flooded with messages during testing
# (unless you really ask to be flooded) # (unless you really ask to be flooded)
call_command('syncdb', call_command('migrate',
verbosity=max(verbosity - 1, 0), verbosity=max(verbosity - 1, 0),
interactive=False, interactive=False,
database=self.connection.alias, 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 # 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 # custom SQL has been removed. The only test data should come from

View File

@ -4,6 +4,7 @@ from django.utils.functional import cached_property
from django.db.models.loading import cache from django.db.models.loading import cache
from django.db.migrations.recorder import MigrationRecorder from django.db.migrations.recorder import MigrationRecorder
from django.db.migrations.graph import MigrationGraph from django.db.migrations.graph import MigrationGraph
from django.conf import settings
class MigrationLoader(object): class MigrationLoader(object):
@ -36,6 +37,12 @@ class MigrationLoader(object):
self.disk_migrations = None self.disk_migrations = None
self.applied_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): def load_disk(self):
""" """
Loads the migrations from all INSTALLED_APPS from disk. Loads the migrations from all INSTALLED_APPS from disk.
@ -44,8 +51,8 @@ class MigrationLoader(object):
self.unmigrated_apps = set() self.unmigrated_apps = set()
for app in cache.get_apps(): for app in cache.get_apps():
# Get the migrations module directory # Get the migrations module directory
module_name = ".".join(app.__name__.split(".")[:-1] + ["migrations"]) app_label = app.__name__.split(".")[-2]
app_label = module_name.split(".")[-2] module_name = self.migration_module(app_label)
try: try:
module = import_module(module_name) module = import_module(module_name)
except ImportError as e: except ImportError as e:

View File

@ -1,4 +1,5 @@
from django.test import TransactionTestCase from django.test import TransactionTestCase
from django.test.utils import override_settings
from django.db import connection from django.db import connection
from django.db.migrations.executor import MigrationExecutor from django.db.migrations.executor import MigrationExecutor
@ -11,6 +12,9 @@ class ExecutorTests(TransactionTestCase):
test failures first, as they may be propagating into here. 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): def test_run(self):
""" """
Tests running a simple set of migrations. Tests running a simple set of migrations.

View File

@ -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 import connection
from django.db.migrations.loader import MigrationLoader from django.db.migrations.loader import MigrationLoader
from django.db.migrations.recorder import MigrationRecorder from django.db.migrations.recorder import MigrationRecorder
@ -30,12 +31,13 @@ class RecorderTests(TestCase):
) )
class LoaderTests(TransactionTestCase): class LoaderTests(TestCase):
""" """
Tests the disk and database loader, and running through migrations Tests the disk and database loader, and running through migrations
in memory. in memory.
""" """
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_load(self): def test_load(self):
""" """
Makes sure the loader can load the migrations for the test apps, Makes sure the loader can load the migrations for the test apps,

View File

@ -1,9 +1,9 @@
from django.test import TransactionTestCase from django.test import TestCase
from django.db import connection, models, migrations from django.db import connection, models, migrations
from django.db.migrations.state import ProjectState 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. 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 - Each test looks at their state changing, and then their database operation -

View File

@ -1,12 +1,12 @@
# encoding: utf8 # encoding: utf8
import datetime import datetime
from django.utils import six 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.migrations.writer import MigrationWriter
from django.db import models, migrations from django.db import models, migrations
class WriterTests(TransactionTestCase): class WriterTests(TestCase):
""" """
Tests the migration writer (makes migration files from Migration instances) Tests the migration writer (makes migration files from Migration instances)
""" """