Andrew Godwin avatar Andrew Godwin committed 6b8d771

Working and passing test for rebase.

Comments (0)

Files changed (3)


     return exists
 def get_dependencies(target, migrations):
-    forwards = list
+    forwards = lambda allow_rebase=False: list()
     backwards = list
     if target is None:
         backwards = migrations[0].backwards_plan


         return self.migrations[index]
     next = memoize(next)
-    def is_base(self):
+    def is_rebase(self):
-        Returns whether this migration is a 'base' migration - one which is
-        a safe place for the migrator to stop.
+        Returns whether this migration is a 'rebase' migration - one which is
+        a safe place for the migrator to stop before it gets to the start.
         This is true if it's an initial migration, or if it's been created by
-        return (self.previous() is None) or getattr(self.migration_class(), "rebase", False) 
-    is_base = memoize(is_base)
+        return getattr(self.migration_class(), "rebase", False) 
+    is_rebase = memoize(is_rebase)
     def _get_dependency_objects(self, attrname):
         for item in reversed(base_plan):
             if allow_rebase:
                 new_plan.insert(0, item)
-                if item.is_base():
+                if item.is_rebase():
-                if not item.is_base():
+                if not item.is_rebase():
                     new_plan.insert(0, item)
         return new_plan


     Tests if the various logic functions in migration actually work.
-    installed_apps = ["fakeapp", "otherfakeapp"]
+    installed_apps = ["fakeapp", "otherfakeapp", "rebasedapp"]
+    def setUp(self):
+        super(TestMigrationLogic, self).setUp()
+        Migrations.calculate_dependencies(force=True)
     def assertListEqual(self, list1, list2):
         list1 = list(list1)
         Tests that the rebase logic correctly starts at a rebase migration,
         but only if we're doing a fresh install.
-        pass
+        rebasedapp = Migrations("rebasedapp")
+        # Test with no rebase
+        self.assertEqual(
+            [
+                rebasedapp['0001_bottom'],
+                rebasedapp['0002_mid'],
+                rebasedapp['0004_top'],
+            ],
+            rebasedapp['0004_top'].forwards_plan(allow_rebase=False),
+        )
+        # Test with rebase
+        self.assertEqual(
+            [
+                rebasedapp['0003_rebase'],
+                rebasedapp['0004_top'],
+            ],
+            rebasedapp['0004_top'].forwards_plan(allow_rebase=True),
+        )
 class TestMigrationUtils(Monkeypatcher):
     installed_apps = ["fakeapp", "otherfakeapp"]
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.