summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-06-19 15:36:22 +0100
committerAndrew Godwin <andrew@aeracode.org>2013-06-19 15:36:22 +0100
commitab5cbae9b7f2639ae33165e36c30e6563c1364c4 (patch)
treeb2577e845fe0d732b458ea93a08282e41dacda9e /tests
parent2ae8a8a77d6968a155db9b17ba13e21d91bd351b (diff)
First stab at some migration creation commands
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py24
-rw-r--r--tests/migrations/test_migrations/0001_initial.py (renamed from tests/migrations/migrations/0001_initial.py)0
-rw-r--r--tests/migrations/test_migrations/0002_second.py (renamed from tests/migrations/migrations/0002_second.py)0
-rw-r--r--tests/migrations/test_migrations/__init__.py (renamed from tests/migrations/migrations/__init__.py)0
-rw-r--r--tests/schema/tests.py2
5 files changed, 23 insertions, 3 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 1fc8f7aefb..2b9ce21a1d 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -1,12 +1,12 @@
# encoding: utf8
-from django.test import TransactionTestCase
-from django.db.migrations.autodetector import MigrationAutodetector
+from django.test import TestCase
+from django.db.migrations.autodetector import MigrationAutodetector, MigrationQuestioner
from django.db.migrations.state import ProjectState, ModelState
from django.db.migrations.graph import MigrationGraph
from django.db import models
-class AutodetectorTests(TransactionTestCase):
+class AutodetectorTests(TestCase):
"""
Tests the migration autodetector.
"""
@@ -14,6 +14,7 @@ class AutodetectorTests(TransactionTestCase):
author_empty = ModelState("testapp", "Author", [("id", models.AutoField(primary_key=True))])
other_pony = ModelState("otherapp", "Pony", [("id", models.AutoField(primary_key=True))])
other_stable = ModelState("otherapp", "Stable", [("id", models.AutoField(primary_key=True))])
+ third_thing = ModelState("thirdapp", "Thing", [("id", models.AutoField(primary_key=True))])
def make_project_state(self, model_states):
"Shortcut to make ProjectStates from lists of predefined models"
@@ -44,6 +45,23 @@ class AutodetectorTests(TransactionTestCase):
self.assertEqual(changes["otherapp"][0].name, "0002_pony_stable")
self.assertEqual(changes["otherapp"][0].dependencies, [("otherapp", "0001_initial")])
+ def test_trim_apps(self):
+ "Tests that trim does not remove dependencies but does remove unwanted apps"
+ # Use project state to make a new migration change set
+ before = self.make_project_state([])
+ after = self.make_project_state([self.author_empty, self.other_pony, self.other_stable, self.third_thing])
+ autodetector = MigrationAutodetector(before, after, MigrationQuestioner({"ask_initial": True}))
+ changes = autodetector.changes()
+ # Run through arrange_for_graph
+ graph = MigrationGraph()
+ changes = autodetector.arrange_for_graph(changes, graph)
+ changes["testapp"][0].dependencies.append(("otherapp", "0001_initial"))
+ changes = autodetector.trim_to_apps(changes, set(["testapp"]))
+ # Make sure there's the right set of migrations
+ self.assertEqual(changes["testapp"][0].name, "0001_initial")
+ self.assertEqual(changes["otherapp"][0].name, "0001_initial")
+ self.assertNotIn("thirdapp", changes)
+
def test_new_model(self):
"Tests autodetection of new models"
# Make state
diff --git a/tests/migrations/migrations/0001_initial.py b/tests/migrations/test_migrations/0001_initial.py
index e2ed8559a6..e2ed8559a6 100644
--- a/tests/migrations/migrations/0001_initial.py
+++ b/tests/migrations/test_migrations/0001_initial.py
diff --git a/tests/migrations/migrations/0002_second.py b/tests/migrations/test_migrations/0002_second.py
index ace9a83347..ace9a83347 100644
--- a/tests/migrations/migrations/0002_second.py
+++ b/tests/migrations/test_migrations/0002_second.py
diff --git a/tests/migrations/migrations/__init__.py b/tests/migrations/test_migrations/__init__.py
index e69de29bb2..e69de29bb2 100644
--- a/tests/migrations/migrations/__init__.py
+++ b/tests/migrations/test_migrations/__init__.py
diff --git a/tests/schema/tests.py b/tests/schema/tests.py
index f643f3ed68..89853088ac 100644
--- a/tests/schema/tests.py
+++ b/tests/schema/tests.py
@@ -17,6 +17,8 @@ class SchemaTests(TransactionTestCase):
as sometimes the code to check if a test has worked is almost as complex
as the code it is testing.
"""
+
+ available_apps = []
models = [Author, AuthorWithM2M, Book, BookWithSlug, BookWithM2M, Tag, TagUniqueRename, UniqueTest]
no_table_strings = ["no such table", "unknown table", "does not exist"]