Ticket #24396: 24396.patch

File 24396.patch, 2.3 KB (added by Aymeric Augustin, 10 years ago)
  • tests/migration_test_data_persistence/migrations/0002_add_book.py

    diff --git a/tests/migration_test_data_persistence/migrations/0002_add_book.py b/tests/migration_test_data_persistence/migrations/0002_add_book.py
    index 6ce7fff..9b6e617 100644
    a b from django.db import migrations  
    55
    66
    77def add_book(apps, schema_editor):
    8     apps.get_model("migration_test_data_persistence", "Book").objects.using(
    9         schema_editor.connection.alias,
    10     ).create(
     8    if schema_editor.connection.alias != 'default':
     9        return
     10    apps.get_model("migration_test_data_persistence", "Book").objects.create(
    1111        title="I Love Django",
    1212    )
    1313
  • tests/routers.py

    diff --git a/tests/routers.py b/tests/routers.py
    index e69de29..c71ec60 100644
    a b  
     1APPS_ON_OTHER_DATABASE = {
     2    # Contrib apps
     3    'auth',
     4    'contenttypes',
     5    'sites',
     6    # Test apps
     7    'multiple_database',
     8    'prefetch_related',
     9}
     10
     11class DjangoTestSuiteRouter(object):
     12
     13    def db_for_read(self, model, **hints):
     14        return None
     15
     16    def db_for_write(self, model, **hints):
     17        return None
     18
     19    def allow_relation(self, obj1, obj2, **hints):
     20        return None
     21
     22    def allow_migrate(self, db, model):
     23        """
     24        Migrate only apps that have tests cases with multi_db = True
     25        on the 'other' database.
     26        """
     27        if db == 'other':
     28            return model._meta.app_label in APPS_ON_OTHER_DATABASE
     29        return None
  • tests/runtests.py

    diff --git a/tests/runtests.py b/tests/runtests.py
    index f81fe74..80c3b02 100755
    a b def setup(verbosity, test_labels):  
    118118        'STATIC_URL': settings.STATIC_URL,
    119119        'STATIC_ROOT': settings.STATIC_ROOT,
    120120        'MIDDLEWARE_CLASSES': settings.MIDDLEWARE_CLASSES,
     121        'DATABASE_ROUTERS': settings.DATABASE_ROUTERS,
    121122    }
    122123
    123124    # Redirect some settings for the duration of these tests.
    def setup(verbosity, test_labels):  
    149150        'auth': 'django.contrib.auth.tests.migrations',
    150151        'contenttypes': 'contenttypes_tests.migrations',
    151152    }
     153    settings.DATABASE_ROUTERS = ['routers.DjangoTestSuiteRouter']
    152154
    153155    if verbosity > 0:
    154156        # Ensure any warnings captured to logging are piped through a verbose
Back to Top