summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRaffaele Salmaso <raffaele@salmaso.org>2014-08-19 15:24:31 +0200
committerTim Graham <timograham@gmail.com>2014-09-02 21:09:18 -0400
commit1435cfbe8dbd85c17c9a25af99f910c407dfa9bd (patch)
tree7b3902cec1c408336b6b908653fb02cecd2a47ee /tests
parentbda28097126c0ff77c51d598ccc19663bcd3ee95 (diff)
Fixed #23302 -- Added --name/-n option to makemigrations command
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py25
-rw-r--r--tests/migrations/test_commands.py31
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index c3bec6ba84..42569d354d 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -188,6 +188,31 @@ class AutodetectorTests(TestCase):
self.assertEqual(changes["otherapp"][0].name, "0001_initial")
self.assertNotIn("thirdapp", changes)
+ def test_custom_migration_name(self):
+ "Tests custom naming of migrations for graph matching."
+ # Make a fake graph
+ graph = MigrationGraph()
+ graph.add_node(("testapp", "0001_initial"), None)
+ graph.add_node(("testapp", "0002_foobar"), None)
+ graph.add_node(("otherapp", "0001_initial"), None)
+ graph.add_dependency("testapp.0002_foobar", ("testapp", "0002_foobar"), ("testapp", "0001_initial"))
+
+ # 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])
+ autodetector = MigrationAutodetector(before, after)
+ changes = autodetector._detect_changes()
+
+ # Run through arrange_for_graph
+ migration_name = 'custom_name'
+ changes = autodetector.arrange_for_graph(changes, graph, migration_name)
+
+ # Make sure there's a new name, deps match, etc.
+ self.assertEqual(changes["testapp"][0].name, "0003_%s" % migration_name)
+ self.assertEqual(changes["testapp"][0].dependencies, [("testapp", "0002_foobar")])
+ self.assertEqual(changes["otherapp"][0].name, "0002_%s" % migration_name)
+ self.assertEqual(changes["otherapp"][0].dependencies, [("otherapp", "0001_initial")])
+
def test_new_model(self):
"Tests autodetection of new models"
# Make state
diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
index 00b7f65ab8..798dd86fe5 100644
--- a/tests/migrations/test_commands.py
+++ b/tests/migrations/test_commands.py
@@ -546,3 +546,34 @@ class MakeMigrationsTests(MigrationTestBase):
questioner.input = old_input
if os.path.exists(merge_file):
os.remove(merge_file)
+
+ @override_system_checks([])
+ def test_makemigrations_with_custom_name(self):
+ """
+ Makes sure that makemigrations generate a custom migration.
+ """
+ def cmd(migration_count, migration_name, *args):
+ with override_settings(MIGRATION_MODULES={"migrations": self.migration_pkg}):
+ try:
+ call_command("makemigrations", "migrations", "--verbosity", "0", "--name", migration_name, *args)
+ except CommandError:
+ self.fail("Makemigrations errored in creating empty migration with custom name for a proper app.")
+ migration_file = os.path.join(self.migration_dir, "%s_%s.py" % (migration_count, migration_name))
+ # Check for existing migration file in migration folder
+ self.assertTrue(os.path.exists(migration_file))
+ with codecs.open(migration_file, "r", encoding="utf-8") as fp:
+ content = fp.read()
+ self.assertTrue("# -*- coding: utf-8 -*-" in content)
+ content = content.replace(" ", "")
+ return content
+
+ # generate an initial migration
+ migration_name_0001 = "my_initial_migration"
+ content = cmd("0001", migration_name_0001)
+ self.assertIn("dependencies=[\n]", content)
+
+ # generate an empty migration
+ migration_name_0002 = "my_custom_migration"
+ content = cmd("0002", migration_name_0002, "--empty")
+ self.assertIn("dependencies=[\n('migrations','0001_%s'),\n]" % migration_name_0001, content)
+ self.assertIn("operations=[\n]", content)