diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2012-12-18 09:02:07 +0000 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2012-12-18 09:02:07 +0000 |
| commit | b62e82365ad56ca930f7abb1d1dbdf9ce5a7c7c3 (patch) | |
| tree | 76bce44f4c7ee6172dcf116be6e4a26e380ef20a /tests/regressiontests/multiple_database/tests.py | |
| parent | 6a632e04578776e877adc5e2dc53f008c890a0d4 (diff) | |
| parent | c64b57d16688025b2d48668d5c4cb9eda7484612 (diff) | |
Merge remote-tracking branch 'core/master' into schema-alteration
Conflicts:
django/db/models/loading.py
django/db/models/options.py
Diffstat (limited to 'tests/regressiontests/multiple_database/tests.py')
| -rw-r--r-- | tests/regressiontests/multiple_database/tests.py | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/tests/regressiontests/multiple_database/tests.py b/tests/regressiontests/multiple_database/tests.py index 79fe6beebd..a903ea11a0 100644 --- a/tests/regressiontests/multiple_database/tests.py +++ b/tests/regressiontests/multiple_database/tests.py @@ -16,16 +16,6 @@ from django.utils.six import StringIO from .models import Book, Person, Pet, Review, UserProfile -def copy_content_types_from_default_to_other(): - # On post_syncdb, content types are created in the 'default' database. - # However, tests of generic foreign keys require them in 'other' too. - # The problem is masked on backends that defer constraints checks: at the - # end of each test, there's a rollback, and constraints are never checked. - # It only appears on MySQL + InnoDB. - for ct in ContentType.objects.using('default').all(): - ct.save(using='other') - - class QueryTestCase(TestCase): multi_db = True @@ -705,8 +695,6 @@ class QueryTestCase(TestCase): def test_generic_key_separation(self): "Generic fields are constrained to a single database" - copy_content_types_from_default_to_other() - # Create a book and author on the default database pro = Book.objects.create(title="Pro Django", published=datetime.date(2008, 12, 16)) @@ -734,8 +722,6 @@ class QueryTestCase(TestCase): def test_generic_key_reverse_operations(self): "Generic reverse manipulations are all constrained to a single DB" - copy_content_types_from_default_to_other() - dive = Book.objects.using('other').create(title="Dive into Python", published=datetime.date(2009, 5, 4)) @@ -780,8 +766,6 @@ class QueryTestCase(TestCase): def test_generic_key_cross_database_protection(self): "Operations that involve sharing generic key objects across databases raise an error" - copy_content_types_from_default_to_other() - # Create a book and author on the default database pro = Book.objects.create(title="Pro Django", published=datetime.date(2008, 12, 16)) @@ -833,8 +817,6 @@ class QueryTestCase(TestCase): def test_generic_key_deletion(self): "Cascaded deletions of Generic Key relations issue queries on the right database" - copy_content_types_from_default_to_other() - dive = Book.objects.using('other').create(title="Dive into Python", published=datetime.date(2009, 5, 4)) review = Review.objects.using('other').create(source="Python Weekly", content_object=dive) @@ -1402,8 +1384,6 @@ class RouterTestCase(TestCase): def test_generic_key_cross_database_protection(self): "Generic Key operations can span databases if they share a source" - copy_content_types_from_default_to_other() - # Create a book and author on the default database pro = Book.objects.using('default' ).create(title="Pro Django", published=datetime.date(2008, 12, 16)) @@ -1515,8 +1495,6 @@ class RouterTestCase(TestCase): def test_generic_key_managers(self): "Generic key relations are represented by managers, and can be controlled like managers" - copy_content_types_from_default_to_other() - pro = Book.objects.using('other').create(title="Pro Django", published=datetime.date(2008, 12, 16)) @@ -1922,3 +1900,39 @@ class RouterModelArgumentTestCase(TestCase): pet = Pet.objects.create(owner=person, name='Wart') # test related FK collection person.delete() + + +class SyncOnlyDefaultDatabaseRouter(object): + def allow_syncdb(self, db, model): + return db == DEFAULT_DB_ALIAS + + +class SyncDBTestCase(TestCase): + multi_db = True + + def test_syncdb_to_other_database(self): + """Regression test for #16039: syncdb with --database option.""" + cts = ContentType.objects.using('other').filter(app_label='multiple_database') + + count = cts.count() + self.assertGreater(count, 0) + + cts.delete() + management.call_command('syncdb', verbosity=0, interactive=False, + load_initial_data=False, database='other') + self.assertEqual(cts.count(), count) + + def test_syncdb_to_other_database_with_router(self): + """Regression test for #16039: syncdb with --database option.""" + cts = ContentType.objects.using('other').filter(app_label='multiple_database') + + cts.delete() + try: + old_routers = router.routers + router.routers = [SyncOnlyDefaultDatabaseRouter()] + management.call_command('syncdb', verbosity=0, interactive=False, + load_initial_data=False, database='other') + finally: + router.routers = old_routers + + self.assertEqual(cts.count(), 0) |
