summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorGordon Pendleton <wgordonw1@gmail.com>2020-03-26 05:08:58 -0400
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-03-26 20:12:39 +0100
commitd0da2820cab495c35eac10680213f927be8b91b0 (patch)
tree0f065f06f8c84994741acc57f0814fb8677f3cc0 /tests
parent421622548060499881df9966b7a352bce63901cd (diff)
Fixed #31402 -- Added migrate --check option.
Command exits with non-zero status if unapplied migrations exist.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_commands.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 14c09c8f98..f7f8a68d4c 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -249,6 +249,39 @@ class MigrateTests(MigrationTestBase):
with self.assertRaisesMessage(CommandError, "Conflicting migrations detected"):
call_command("migrate", "migrations")
+ @override_settings(MIGRATION_MODULES={
+ 'migrations': 'migrations.test_migrations',
+ })
+ def test_migrate_check(self):
+ with self.assertRaises(SystemExit):
+ call_command('migrate', 'migrations', '0001', check_unapplied=True, verbosity=0)
+ self.assertTableNotExists('migrations_author')
+ self.assertTableNotExists('migrations_tribble')
+ self.assertTableNotExists('migrations_book')
+
+ @override_settings(MIGRATION_MODULES={
+ 'migrations': 'migrations.test_migrations_plan',
+ })
+ def test_migrate_check_plan(self):
+ out = io.StringIO()
+ with self.assertRaises(SystemExit):
+ call_command(
+ 'migrate',
+ 'migrations',
+ '0001',
+ check_unapplied=True,
+ plan=True,
+ stdout=out,
+ no_color=True,
+ )
+ self.assertEqual(
+ 'Planned operations:\n'
+ 'migrations.0001_initial\n'
+ ' Create model Salamander\n'
+ ' Raw Python operation -> Grow salamander tail.\n',
+ out.getvalue(),
+ )
+
@override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
def test_showmigrations_list(self):
"""