From 51f2de1530a49ef9c2f315025b47e107295cd38f Mon Sep 17 00:00:00 2001 From: Carl Meyer Date: Wed, 19 Nov 2014 19:43:12 -0700 Subject: [PATCH] Added another migration-executor test to avoid regressions. --- tests/migrations/test_executor.py | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/migrations/test_executor.py b/tests/migrations/test_executor.py index 61da17b341..1bc1ca781d 100644 --- a/tests/migrations/test_executor.py +++ b/tests/migrations/test_executor.py @@ -325,3 +325,38 @@ class ExecutorUnitTests(TestCase): should_be_rolled_back = [b2_impl, a4_impl, a2_impl, a3_impl] exp = [(m, True) for m in should_be_rolled_back] self.assertEqual(plan, exp) + + def test_backwards_nothing_to_do(self): + """ + If the current state satisfies the given target, do nothing. + + a: 1 <--- 2 + b: \- 1 + c: \- 1 + + If a1 is applied already and a2 is not, and we're asked to migrate to + a1, don't apply or unapply b1 or c1, regardless of their current state. + """ + a1_impl = FakeMigration('a1') + a1 = ('a', '1') + a2_impl = FakeMigration('a2') + a2 = ('a', '2') + b1_impl = FakeMigration('b1') + b1 = ('b', '1') + c1_impl = FakeMigration('c1') + c1 = ('c', '1') + graph = MigrationGraph() + graph.add_node(a1, a1_impl) + graph.add_node(a2, a2_impl) + graph.add_node(b1, b1_impl) + graph.add_node(c1, c1_impl) + graph.add_dependency(None, a2, a1) + graph.add_dependency(None, b1, a1) + graph.add_dependency(None, c1, a1) + + executor = MigrationExecutor(None) + executor.loader = FakeLoader(graph, {a1, b1}) + + plan = executor.migration_plan({a1}) + + self.assertEqual(plan, [])