summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-14 09:37:45 +0200
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-10-14 11:45:47 +0200
commitd2f02aa56b57f8b3de1b624f8b1a909c67b6823a (patch)
treed9cd5df6553e726cc3f9402bad11616aacc24c06 /tests
parentd4d37d09008f920c8cd4faa9ec075de51da0a36f (diff)
[2.2.x] Fixed #30870 -- Fixed showing that RunPython operations are irreversible by migrate --plan.
Thanks Hasan Ramezani for the initial patch and Kyle Dickerson for the report. Backport of 06d34aab7cfb1632a1538a243db81f24498525ff from master.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_commands.py22
-rw-r--r--tests/migrations/test_migrations_plan/0005_fifth.py22
2 files changed, 44 insertions, 0 deletions
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 36e8f2f5ea..06cc77287e 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -360,6 +360,28 @@ class MigrateTests(MigrationTestBase):
' Raw SQL operation -> IRREVERSIBLE\n',
out.getvalue()
)
+ out = io.StringIO()
+ call_command('migrate', 'migrations', '0005', plan=True, stdout=out, no_color=True)
+ # Operation is marked as irreversible only in the revert plan.
+ self.assertEqual(
+ 'Planned operations:\n'
+ 'migrations.0005_fifth\n'
+ ' Raw Python operation\n'
+ ' Raw Python operation\n'
+ ' Raw Python operation -> Feed salamander.\n',
+ out.getvalue()
+ )
+ call_command('migrate', 'migrations', '0005', verbosity=0)
+ out = io.StringIO()
+ call_command('migrate', 'migrations', '0004', plan=True, stdout=out, no_color=True)
+ self.assertEqual(
+ 'Planned operations:\n'
+ 'migrations.0005_fifth\n'
+ ' Raw Python operation -> IRREVERSIBLE\n'
+ ' Raw Python operation -> IRREVERSIBLE\n'
+ ' Raw Python operation\n',
+ out.getvalue()
+ )
# Cleanup by unmigrating everything: fake the irreversible, then
# migrate all to zero.
call_command('migrate', 'migrations', '0003', fake=True, verbosity=0)
diff --git a/tests/migrations/test_migrations_plan/0005_fifth.py b/tests/migrations/test_migrations_plan/0005_fifth.py
new file mode 100644
index 0000000000..3c569ffded
--- /dev/null
+++ b/tests/migrations/test_migrations_plan/0005_fifth.py
@@ -0,0 +1,22 @@
+from django.db import migrations
+
+
+def grow_tail(x, y):
+ pass
+
+
+def feed(x, y):
+ """Feed salamander."""
+ pass
+
+
+class Migration(migrations.Migration):
+ dependencies = [
+ ('migrations', '0004_fourth'),
+ ]
+
+ operations = [
+ migrations.RunPython(migrations.RunPython.noop),
+ migrations.RunPython(grow_tail),
+ migrations.RunPython(feed, migrations.RunPython.noop),
+ ]