Andrew Godwin avatar Andrew Godwin committed 75aa263

Tests for the dependency solver.

Comments (0)

Files changed (11)

south/hacks/__init__.py

 This top file will automagically expose the correct Hacks class.
 """
 
+# Currently, these work for 1.0 and 1.1.
 from south.hacks.django_1_0 import Hacks
 
 hacks = Hacks()

south/tests/__init__.py

         """
         Changes the Django environment so we can run tests against our test apps.
         """
-        hacks.set_installed_apps(["fakeapp"])
+        hacks.set_installed_apps(["fakeapp", "otherfakeapp"])
     
     
     def tearDown(self):

south/tests/fakeapp/migrations/0003_alter_spam.py

 
 class Migration:
     
+    needed_by = (
+        ("otherfakeapp", "0003_third"),
+    )
+    
     def forwards(self):
         
         db.alter_column("southtest_spam", 'name', models.CharField(max_length=255, null=True))

south/tests/logic.py

 
 from south import migration
 from south.tests import Monkeypatcher
+from south.utils import snd
 
 # Add the tests directory so fakeapp is on sys.path
 test_root = os.path.dirname(__file__)
     def test_get_migrated_apps(self):
         
         P1 = __import__("fakeapp.migrations", {}, {}, [''])
+        P2 = __import__("otherfakeapp.migrations", {}, {}, [''])
         
         self.assertEqual(
-            [P1],
+            [P1,P2],
             list(migration.get_migrated_apps()),
         )
     
     def test_all_migrations(self):
         
         app = migration.get_app("fakeapp")
+        otherapp = migration.get_app("otherfakeapp")
         
-        self.assertEqual(
-            {app: {
-                "0001_spam": migration.get_migration(app, "0001_spam"),
-                "0002_eggs": migration.get_migration(app, "0002_eggs"),
-                "0003_alter_spam": migration.get_migration(app, "0003_alter_spam"),
-            }},
+        self.assertEqual({
+                app: {
+                    "0001_spam": migration.get_migration(app, "0001_spam"),
+                    "0002_eggs": migration.get_migration(app, "0002_eggs"),
+                    "0003_alter_spam": migration.get_migration(app, "0003_alter_spam"),
+                },
+                otherapp: {
+                    "0001_first": migration.get_migration(otherapp, "0001_first"),
+                    "0002_second": migration.get_migration(otherapp, "0002_second"),
+                    "0003_third": migration.get_migration(otherapp, "0003_third"),
+                },
+            },
             migration.all_migrations(),
         )
     
         
         # finish with no migrations, otherwise other tests fail...
         migration.migrate_app(app, target_name="zero", resolve_mode=None, fake=False, silent=True)
-        self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
+        self.assertEqual(list(migration.MigrationHistory.objects.all()), [])
+    
+    def test_dependencies(self):
+        
+        fakeapp = migration.get_app("fakeapp")
+        otherfakeapp = migration.get_app("otherfakeapp")
+        
+        # Test a simple path
+        tree = migration.dependency_tree()
+        self.assertEqual(
+            map(snd, migration.needed_before_forwards(tree, fakeapp, "0003_alter_spam")),
+            ['0001_spam', '0002_eggs'],
+        )
+        
+        # And a complex one, with both back and forwards deps
+        self.assertEqual(
+            map(snd, migration.needed_before_forwards(tree, otherfakeapp, "0003_third")),
+            ['0001_spam', '0001_first', '0002_second', '0002_eggs', '0003_alter_spam'],
+        )
Add a comment to this file

south/tests/otherfakeapp/__init__.py

Empty file added.

south/tests/otherfakeapp/migrations/0001_first.py

+from south.db import db
+from django.db import models
+
+class Migration:
+    
+    depends_on = (
+        ("fakeapp", "0001_spam"),
+    )
+    
+    def forwards(self):
+        pass
+    
+    def backwards(self):
+        pass
+

south/tests/otherfakeapp/migrations/0002_second.py

+from south.db import db
+from django.db import models
+
+class Migration:
+    
+    def forwards(self):
+        pass
+    
+    def backwards(self):
+        pass
+

south/tests/otherfakeapp/migrations/0003_third.py

+from south.db import db
+from django.db import models
+
+class Migration:
+    
+    def forwards(self):
+        pass
+    
+    def backwards(self):
+        pass
Add a comment to this file

south/tests/otherfakeapp/migrations/__init__.py

Empty file added.

south/tests/otherfakeapp/models.py

+# This file left intentionally blank.
     value = item
     for part in attribute.split("."):
         value = getattr(value, part)
-    return value
+    return value
+
+
+fst = lambda (x, y): x
+snd = lambda (x, y): y
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 ProjectModifiedEvent.java.
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.