summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-14 08:41:44 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-14 11:43:06 +0200
commit4a263af64e10319f70205cd7d993fc86ef3d4468 (patch)
tree8ac5331a7109e320c6ad60d686d4f8a72405a677
parentbab3ad54ff30848a16f08d72e70d8edbab019a63 (diff)
[3.0.x] Isolated migrations.test_commands.MigrateTests.test_migrate_plan.
Backport of 05186c03a30686f4898c1cb9acf4b8613035afcc from master
-rw-r--r--tests/migrations/test_commands.py96
1 files changed, 49 insertions, 47 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 64b5c9bfd0..f14f74b9a0 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -327,53 +327,55 @@ class MigrateTests(MigrationTestBase):
" Raw SQL operation -> ['SELECT * FROM migrations_author']\n",
out.getvalue()
)
- # Migrate to the third migration.
- call_command('migrate', 'migrations', '0003', verbosity=0)
- out = io.StringIO()
- # Show the plan for when there is nothing to apply.
- call_command('migrate', 'migrations', '0003', plan=True, stdout=out, no_color=True)
- self.assertEqual(
- 'Planned operations:\n'
- ' No planned migration operations.\n',
- out.getvalue()
- )
- out = io.StringIO()
- # Show the plan for reverse migration back to 0001.
- call_command('migrate', 'migrations', '0001', plan=True, stdout=out, no_color=True)
- self.assertEqual(
- 'Planned operations:\n'
- 'migrations.0003_third\n'
- ' Undo Create model Author\n'
- " Raw SQL operation -> ['SELECT * FROM migrations_book']\n"
- 'migrations.0002_second\n'
- ' Undo Create model Book\n'
- " Raw SQL operation -> ['SELECT * FROM migrations_salamand…\n",
- out.getvalue()
- )
- out = io.StringIO()
- # Show the migration plan to fourth, with truncated details.
- call_command('migrate', 'migrations', '0004', plan=True, stdout=out, no_color=True)
- self.assertEqual(
- 'Planned operations:\n'
- 'migrations.0004_fourth\n'
- ' Raw SQL operation -> SELECT * FROM migrations_author WHE…\n',
- out.getvalue()
- )
- # Show the plan when an operation is irreversible.
- # Migrate to the fourth migration.
- call_command('migrate', 'migrations', '0004', verbosity=0)
- out = io.StringIO()
- call_command('migrate', 'migrations', '0003', plan=True, stdout=out, no_color=True)
- self.assertEqual(
- 'Planned operations:\n'
- 'migrations.0004_fourth\n'
- ' Raw SQL operation -> IRREVERSIBLE\n',
- out.getvalue()
- )
- # Cleanup by unmigrating everything: fake the irreversible, then
- # migrate all to zero.
- call_command('migrate', 'migrations', '0003', fake=True, verbosity=0)
- call_command('migrate', 'migrations', 'zero', verbosity=0)
+ try:
+ # Migrate to the third migration.
+ call_command('migrate', 'migrations', '0003', verbosity=0)
+ out = io.StringIO()
+ # Show the plan for when there is nothing to apply.
+ call_command('migrate', 'migrations', '0003', plan=True, stdout=out, no_color=True)
+ self.assertEqual(
+ 'Planned operations:\n'
+ ' No planned migration operations.\n',
+ out.getvalue()
+ )
+ out = io.StringIO()
+ # Show the plan for reverse migration back to 0001.
+ call_command('migrate', 'migrations', '0001', plan=True, stdout=out, no_color=True)
+ self.assertEqual(
+ 'Planned operations:\n'
+ 'migrations.0003_third\n'
+ ' Undo Create model Author\n'
+ " Raw SQL operation -> ['SELECT * FROM migrations_book']\n"
+ 'migrations.0002_second\n'
+ ' Undo Create model Book\n'
+ " Raw SQL operation -> ['SELECT * FROM migrations_salamand…\n",
+ out.getvalue()
+ )
+ out = io.StringIO()
+ # Show the migration plan to fourth, with truncated details.
+ call_command('migrate', 'migrations', '0004', plan=True, stdout=out, no_color=True)
+ self.assertEqual(
+ 'Planned operations:\n'
+ 'migrations.0004_fourth\n'
+ ' Raw SQL operation -> SELECT * FROM migrations_author WHE…\n',
+ out.getvalue()
+ )
+ # Show the plan when an operation is irreversible.
+ # Migrate to the fourth migration.
+ call_command('migrate', 'migrations', '0004', verbosity=0)
+ out = io.StringIO()
+ call_command('migrate', 'migrations', '0003', plan=True, stdout=out, no_color=True)
+ self.assertEqual(
+ 'Planned operations:\n'
+ 'migrations.0004_fourth\n'
+ ' Raw SQL operation -> IRREVERSIBLE\n',
+ out.getvalue()
+ )
+ finally:
+ # Cleanup by unmigrating everything: fake the irreversible, then
+ # migrate all to zero.
+ call_command('migrate', 'migrations', '0003', fake=True, verbosity=0)
+ call_command('migrate', 'migrations', 'zero', verbosity=0)
@override_settings(MIGRATION_MODULES={'migrations': 'migrations.test_migrations_empty'})
def test_showmigrations_no_migrations(self):