summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAdam Johnson <me@adamj.eu>2019-11-23 11:08:45 +0000
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2020-05-28 11:42:53 +0200
commitfa58450a9ab8a1bdd2a5090b51b00078fd85ffa6 (patch)
tree564cf0f25dda6c27ef94c57f276db42cf61abbd2 /tests
parent5bd585a82dd963b3d8fdac2b37ff5276f71c5b27 (diff)
Fixed #31468 -- Allowed specifying migration filename in Operation.
This adds also suggested filename for many built-in operations.
Diffstat (limited to 'tests')
-rw-r--r--tests/migrations/test_autodetector.py5
-rw-r--r--tests/migrations/test_operations.py38
-rw-r--r--tests/postgres_tests/test_operations.py2
3 files changed, 45 insertions, 0 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py
index 52d8e305ce..ab52b8116d 100644
--- a/tests/migrations/test_autodetector.py
+++ b/tests/migrations/test_autodetector.py
@@ -2495,6 +2495,11 @@ class AutodetectorSuggestNameTests(SimpleTestCase):
]
self.assertEqual(MigrationAutodetector.suggest_name(ops), 'animal_person')
+ def test_none_name(self):
+ ops = [migrations.RunSQL('SELECT 1 FROM person;')]
+ suggest_name = MigrationAutodetector.suggest_name(ops)
+ self.assertIs(suggest_name.startswith('auto_'), True)
+
def test_auto(self):
suggest_name = MigrationAutodetector.suggest_name([])
self.assertIs(suggest_name.startswith('auto_'), True)
diff --git a/tests/migrations/test_operations.py b/tests/migrations/test_operations.py
index e985535679..855a052058 100644
--- a/tests/migrations/test_operations.py
+++ b/tests/migrations/test_operations.py
@@ -36,6 +36,7 @@ class OperationTests(OperationTestBase):
],
)
self.assertEqual(operation.describe(), "Create model Pony")
+ self.assertEqual(operation.migration_name_fragment, 'pony')
# Test the state alteration
project_state = ProjectState()
new_state = project_state.clone()
@@ -486,6 +487,7 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.DeleteModel("Pony")
self.assertEqual(operation.describe(), "Delete model Pony")
+ self.assertEqual(operation.migration_name_fragment, 'delete_pony')
new_state = project_state.clone()
operation.state_forwards("test_dlmo", new_state)
self.assertNotIn(("test_dlmo", "pony"), new_state.models)
@@ -559,6 +561,7 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.RenameModel("Pony", "Horse")
self.assertEqual(operation.describe(), "Rename model Pony to Horse")
+ self.assertEqual(operation.migration_name_fragment, 'rename_pony_horse')
# Test initial state and database
self.assertIn(("test_rnmo", "pony"), project_state.models)
self.assertNotIn(("test_rnmo", "horse"), project_state.models)
@@ -855,6 +858,7 @@ class OperationTests(OperationTestBase):
models.FloatField(null=True, default=5),
)
self.assertEqual(operation.describe(), "Add field height to Pony")
+ self.assertEqual(operation.migration_name_fragment, 'pony_height')
project_state, new_state = self.make_test_state("test_adfl", operation)
self.assertEqual(len(new_state.models["test_adfl", "pony"].fields), 4)
field = new_state.models['test_adfl', 'pony'].fields['height']
@@ -1155,6 +1159,7 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.RemoveField("Pony", "pink")
self.assertEqual(operation.describe(), "Remove field pink from Pony")
+ self.assertEqual(operation.migration_name_fragment, 'remove_pony_pink')
new_state = project_state.clone()
operation.state_forwards("test_rmfl", new_state)
self.assertEqual(len(new_state.models["test_rmfl", "pony"].fields), 2)
@@ -1198,6 +1203,7 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.AlterModelTable("Pony", "test_almota_pony_2")
self.assertEqual(operation.describe(), "Rename table for Pony to test_almota_pony_2")
+ self.assertEqual(operation.migration_name_fragment, 'alter_pony_table')
new_state = project_state.clone()
operation.state_forwards("test_almota", new_state)
self.assertEqual(new_state.models["test_almota", "pony"].options["db_table"], "test_almota_pony_2")
@@ -1286,6 +1292,7 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.AlterField("Pony", "pink", models.IntegerField(null=True))
self.assertEqual(operation.describe(), "Alter field pink on Pony")
+ self.assertEqual(operation.migration_name_fragment, 'alter_pony_pink')
new_state = project_state.clone()
operation.state_forwards("test_alfl", new_state)
self.assertIs(project_state.models['test_alfl', 'pony'].fields['pink'].null, False)
@@ -1543,6 +1550,7 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.RenameField("Pony", "pink", "blue")
self.assertEqual(operation.describe(), "Rename field pink on Pony to blue")
+ self.assertEqual(operation.migration_name_fragment, 'rename_pink_pony_blue')
new_state = project_state.clone()
operation.state_forwards("test_rnfl", new_state)
self.assertIn("blue", new_state.models["test_rnfl", "pony"].fields)
@@ -1624,6 +1632,10 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.AlterUniqueTogether("Pony", [("pink", "weight")])
self.assertEqual(operation.describe(), "Alter unique_together for Pony (1 constraint(s))")
+ self.assertEqual(
+ operation.migration_name_fragment,
+ 'alter_pony_unique_together',
+ )
new_state = project_state.clone()
operation.state_forwards("test_alunto", new_state)
self.assertEqual(len(project_state.models["test_alunto", "pony"].options.get("unique_together", set())), 0)
@@ -1675,6 +1687,10 @@ class OperationTests(OperationTestBase):
index = models.Index(fields=["pink"], name="test_adin_pony_pink_idx")
operation = migrations.AddIndex("Pony", index)
self.assertEqual(operation.describe(), "Create index test_adin_pony_pink_idx on field(s) pink of model Pony")
+ self.assertEqual(
+ operation.migration_name_fragment,
+ 'pony_test_adin_pony_pink_idx',
+ )
new_state = project_state.clone()
operation.state_forwards("test_adin", new_state)
# Test the database alteration
@@ -1702,6 +1718,10 @@ class OperationTests(OperationTestBase):
self.assertIndexExists("test_rmin_pony", ["pink", "weight"])
operation = migrations.RemoveIndex("Pony", "pony_test_idx")
self.assertEqual(operation.describe(), "Remove index pony_test_idx from Pony")
+ self.assertEqual(
+ operation.migration_name_fragment,
+ 'remove_pony_pony_test_idx',
+ )
new_state = project_state.clone()
operation.state_forwards("test_rmin", new_state)
# Test the state alteration
@@ -1789,6 +1809,10 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.AlterIndexTogether("Pony", [("pink", "weight")])
self.assertEqual(operation.describe(), "Alter index_together for Pony (1 constraint(s))")
+ self.assertEqual(
+ operation.migration_name_fragment,
+ 'alter_pony_index_together',
+ )
new_state = project_state.clone()
operation.state_forwards("test_alinto", new_state)
self.assertEqual(len(project_state.models["test_alinto", "pony"].options.get("index_together", set())), 0)
@@ -1845,6 +1869,10 @@ class OperationTests(OperationTestBase):
self.assertEqual(
gt_operation.describe(), "Create constraint test_add_constraint_pony_pink_gt_2 on model Pony"
)
+ self.assertEqual(
+ gt_operation.migration_name_fragment,
+ 'pony_test_add_constraint_pony_pink_gt_2',
+ )
# Test the state alteration
new_state = project_state.clone()
gt_operation.state_forwards("test_addconstraint", new_state)
@@ -1982,6 +2010,10 @@ class OperationTests(OperationTestBase):
self.assertEqual(
gt_operation.describe(), "Remove constraint test_remove_constraint_pony_pink_gt_2 from model Pony"
)
+ self.assertEqual(
+ gt_operation.migration_name_fragment,
+ 'remove_pony_test_remove_constraint_pony_pink_gt_2',
+ )
# Test state alteration
new_state = project_state.clone()
gt_operation.state_forwards("test_removeconstraint", new_state)
@@ -2212,6 +2244,7 @@ class OperationTests(OperationTestBase):
# Test the state alteration (no DB alteration to test)
operation = migrations.AlterModelOptions("Pony", {"permissions": [("can_groom", "Can groom")]})
self.assertEqual(operation.describe(), "Change Meta options on Pony")
+ self.assertEqual(operation.migration_name_fragment, 'alter_pony_options')
new_state = project_state.clone()
operation.state_forwards("test_almoop", new_state)
self.assertEqual(len(project_state.models["test_almoop", "pony"].options.get("permissions", [])), 0)
@@ -2249,6 +2282,10 @@ class OperationTests(OperationTestBase):
# Test the state alteration
operation = migrations.AlterOrderWithRespectTo("Rider", "pony")
self.assertEqual(operation.describe(), "Set order_with_respect_to on Rider to pony")
+ self.assertEqual(
+ operation.migration_name_fragment,
+ 'alter_rider_order_with_respect_to',
+ )
new_state = project_state.clone()
operation.state_forwards("test_alorwrtto", new_state)
self.assertIsNone(
@@ -2298,6 +2335,7 @@ class OperationTests(OperationTestBase):
]
)
self.assertEqual(operation.describe(), "Change managers on Pony")
+ self.assertEqual(operation.migration_name_fragment, 'alter_pony_managers')
managers = project_state.models["test_almoma", "pony"].managers
self.assertEqual(managers, [])
diff --git a/tests/postgres_tests/test_operations.py b/tests/postgres_tests/test_operations.py
index 8cc9a2b66e..a10f5da440 100644
--- a/tests/postgres_tests/test_operations.py
+++ b/tests/postgres_tests/test_operations.py
@@ -175,6 +175,7 @@ class CreateExtensionTests(PostgreSQLTestCase):
def test_allow_migrate(self):
operation = CreateExtension('tablefunc')
+ self.assertEqual(operation.migration_name_fragment, 'create_extension_tablefunc')
project_state = ProjectState()
new_state = project_state.clone()
# Create an extension.
@@ -192,6 +193,7 @@ class CreateExtensionTests(PostgreSQLTestCase):
def test_create_existing_extension(self):
operation = BloomExtension()
+ self.assertEqual(operation.migration_name_fragment, 'create_extension_bloom')
project_state = ProjectState()
new_state = project_state.clone()
# Don't create an existing extension.