summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-07-09 23:53:16 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-07-09 23:53:43 -0700
commit008bff92b7028673cdab872a6733770606efce83 (patch)
tree2211d5a84e43a5c16396f5b388a7b3f5fe0bfc9b /tests
parentb7455b52a07feb6cee482ecef9c1797d9b16221f (diff)
Fixed #22970: Incorrect dependencies for existing migrated apps
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/models.py8
-rw-r--r--tests/migrations/test_autodetector.py43
-rw-r--r--tests/migrations/test_migrations_no_changes/0003_third.py11
3 files changed, 59 insertions, 3 deletions
diff --git a/tests/migrations/models.py b/tests/migrations/models.py
index 87165ab6e3..fc063f5cb0 100644
--- a/tests/migrations/models.py
+++ b/tests/migrations/models.py
@@ -42,3 +42,11 @@ class UnserializableModel(models.Model):
class Meta:
# Disable auto loading of this model as we load it on our own
apps = Apps()
+
+
+class UnmigratedModel(models.Model):
+ """
+ A model that is in a migration-less app (which this app is
+ if its migrations directory has not been repointed)
+ """
+ pass
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index c093e5c6e6..bc4478b22d 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -4,7 +4,8 @@ from django.db.migrations.autodetector import MigrationAutodetector
from django.db.migrations.questioner import MigrationQuestioner
from django.db.migrations.state import ProjectState, ModelState
from django.db.migrations.graph import MigrationGraph
-from django.db import models
+from django.db.migrations.loader import MigrationLoader
+from django.db import models, connection
from django.contrib.auth.models import AbstractBaseUser
@@ -58,6 +59,7 @@ class AutodetectorTests(TestCase):
third_thing = ModelState("thirdapp", "Thing", [("id", models.AutoField(primary_key=True))])
book = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Author")), ("title", models.CharField(max_length=200))])
book_proxy_fk = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("thirdapp.AuthorProxy")), ("title", models.CharField(max_length=200))])
+ book_migrations_fk = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("migrations.UnmigratedModel")), ("title", models.CharField(max_length=200))])
book_with_no_author = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("title", models.CharField(max_length=200))])
book_with_author_renamed = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("author", models.ForeignKey("testapp.Writer")), ("title", models.CharField(max_length=200))])
book_with_field_and_author_renamed = ModelState("otherapp", "Book", [("id", models.AutoField(primary_key=True)), ("writer", models.ForeignKey("testapp.Writer")), ("title", models.CharField(max_length=200))])
@@ -1017,3 +1019,42 @@ class AutodetectorTests(TestCase):
self.assertOperationTypes(changes, 'testapp', 0, ["CreateModel", "CreateModel"])
self.assertOperationAttributes(changes, 'testapp', 0, 0, name="Author")
self.assertOperationAttributes(changes, 'testapp', 0, 1, name="Aardvark")
+
+ def test_first_dependency(self):
+ """
+ Tests that a dependency to an app with no migrations uses __first__.
+ """
+ # Load graph
+ loader = MigrationLoader(connection)
+ # Make state
+ before = self.make_project_state([])
+ after = self.make_project_state([self.book_migrations_fk])
+ after.real_apps = ["migrations"]
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes(graph=loader.graph)
+ # Right number of migrations?
+ self.assertNumberMigrations(changes, 'otherapp', 1)
+ self.assertOperationTypes(changes, 'otherapp', 0, ["CreateModel"])
+ self.assertOperationAttributes(changes, 'otherapp', 0, 0, name="Book")
+ # Right dependencies?
+ self.assertEqual(changes['otherapp'][0].dependencies, [("migrations", "__first__")])
+
+ @override_settings(MIGRATION_MODULES={"migrations": "migrations.test_migrations"})
+ def test_last_dependency(self):
+ """
+ Tests that a dependency to an app with existing migrations uses __first__.
+ """
+ # Load graph
+ loader = MigrationLoader(connection)
+ # Make state
+ before = self.make_project_state([])
+ after = self.make_project_state([self.book_migrations_fk])
+ after.real_apps = ["migrations"]
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes(graph=loader.graph)
+ # Right number of migrations?
+ self.assertNumberMigrations(changes, 'otherapp', 1)
+ self.assertOperationTypes(changes, 'otherapp', 0, ["CreateModel"])
+ self.assertOperationAttributes(changes, 'otherapp', 0, 0, name="Book")
+ # Right dependencies?
+ self.assertEqual(changes['otherapp'][0].dependencies, [("migrations", "__last__")])
diff --git a/tests/migrations/test_migrations_no_changes/0003_third.py b/tests/migrations/test_migrations_no_changes/0003_third.py
index f8f3db9386..2418bd5e9f 100644
--- a/tests/migrations/test_migrations_no_changes/0003_third.py
+++ b/tests/migrations/test_migrations_no_changes/0003_third.py
@@ -16,8 +16,15 @@ class Migration(migrations.Migration):
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
],
- options={
- },
+ options={},
+ bases=(models.Model,),
+ ),
+ migrations.CreateModel(
+ name='UnmigratedModel',
+ fields=[
+ ('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
+ ],
+ options={},
bases=(models.Model,),
),
migrations.DeleteModel(