summaryrefslogtreecommitdiff
path: root/tests/migrations/test_commands.py
diff options
context:
space:
mode:
authorMatthijs Kooijman <matthijs@stdin.nl>2019-12-20 20:49:56 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-01-20 14:39:02 +0100
commit2a2ea4ee18fdcf2c95bf6435bc63b74623e3085b (patch)
tree32c7c87c71535a8493c07e2073f1bfcd1aa7e24d /tests/migrations/test_commands.py
parent26be703fe679a58bbdccf37a276a9c430ccb29f7 (diff)
Refs #31117 -- Made various tests properly handle unexpected databases aliases.
- Used selected "databases" instead of django.db.connections. - Made routers in tests.migrations skip migrations on unexpected databases. - Added DiscoverRunnerGetDatabasesTests.assertSkippedDatabases() hook which properly asserts messages about skipped databases.
Diffstat (limited to 'tests/migrations/test_commands.py')
-rw-r--r--tests/migrations/test_commands.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 5f57dc7cad..b98b77cd99 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -129,7 +129,7 @@ class MigrateTests(MigrationTestBase):
that check.
"""
# Make sure no tables are created
- for db in connections:
+ for db in self.databases:
self.assertTableNotExists("migrations_author", using=db)
self.assertTableNotExists("migrations_tribble", using=db)
# Run the migrations to 0001 only
@@ -192,7 +192,7 @@ class MigrateTests(MigrationTestBase):
call_command("migrate", "migrations", "zero", verbosity=0)
call_command("migrate", "migrations", "zero", verbosity=0, database="other")
# Make sure it's all gone
- for db in connections:
+ for db in self.databases:
self.assertTableNotExists("migrations_author", using=db)
self.assertTableNotExists("migrations_tribble", using=db)
self.assertTableNotExists("migrations_book", using=db)
@@ -931,7 +931,7 @@ class MakeMigrationsTests(MigrationTestBase):
# With a router that doesn't prohibit migrating 'other',
# consistency is checked.
- with self.settings(DATABASE_ROUTERS=['migrations.routers.EmptyRouter']):
+ with self.settings(DATABASE_ROUTERS=['migrations.routers.DefaultOtherRouter']):
with self.assertRaisesMessage(Exception, 'Other connection'):
call_command('makemigrations', 'migrations', verbosity=0)
self.assertEqual(has_table.call_count, 4) # 'default' and 'other'
@@ -944,12 +944,14 @@ class MakeMigrationsTests(MigrationTestBase):
allow_migrate.assert_any_call('other', 'migrations', model_name='UnicodeModel')
# allow_migrate() is called with the correct arguments.
self.assertGreater(len(allow_migrate.mock_calls), 0)
+ called_aliases = set()
for mock_call in allow_migrate.mock_calls:
_, call_args, call_kwargs = mock_call
connection_alias, app_name = call_args
- self.assertIn(connection_alias, ['default', 'other'])
+ called_aliases.add(connection_alias)
# Raises an error if invalid app_name/model_name occurs.
apps.get_app_config(app_name).get_model(call_kwargs['model_name'])
+ self.assertEqual(called_aliases, set(connections))
self.assertEqual(has_table.call_count, 4)
def test_failing_migration(self):