|
@@ -2661,6 +2661,23 @@ class MigrationSuggestNameTests(SimpleTestCase):
|
|
|
migration = Migration('0002_initial', 'test_app')
|
|
|
self.assertEqual(migration.suggest_name(), 'delete_person')
|
|
|
|
|
|
+ def test_single_operation_long_name(self):
|
|
|
+ class Migration(migrations.Migration):
|
|
|
+ operations = [migrations.CreateModel('A' * 53, fields=[])]
|
|
|
+
|
|
|
+ migration = Migration('some_migration', 'test_app')
|
|
|
+ self.assertEqual(migration.suggest_name(), 'a' * 53)
|
|
|
+
|
|
|
+ def test_two_operations(self):
|
|
|
+ class Migration(migrations.Migration):
|
|
|
+ operations = [
|
|
|
+ migrations.CreateModel('Person', fields=[]),
|
|
|
+ migrations.DeleteModel('Animal'),
|
|
|
+ ]
|
|
|
+
|
|
|
+ migration = Migration('some_migration', 'test_app')
|
|
|
+ self.assertEqual(migration.suggest_name(), 'person_delete_animal')
|
|
|
+
|
|
|
def test_two_create_models(self):
|
|
|
class Migration(migrations.Migration):
|
|
|
operations = [
|
|
@@ -2669,7 +2686,7 @@ class MigrationSuggestNameTests(SimpleTestCase):
|
|
|
]
|
|
|
|
|
|
migration = Migration('0001_initial', 'test_app')
|
|
|
- self.assertEqual(migration.suggest_name(), 'animal_person')
|
|
|
+ self.assertEqual(migration.suggest_name(), 'person_animal')
|
|
|
|
|
|
def test_two_create_models_with_initial_true(self):
|
|
|
class Migration(migrations.Migration):
|
|
@@ -2682,6 +2699,32 @@ class MigrationSuggestNameTests(SimpleTestCase):
|
|
|
migration = Migration('0001_initial', 'test_app')
|
|
|
self.assertEqual(migration.suggest_name(), 'initial')
|
|
|
|
|
|
+ def test_many_operations_suffix(self):
|
|
|
+ class Migration(migrations.Migration):
|
|
|
+ operations = [
|
|
|
+ migrations.CreateModel('Person1', fields=[]),
|
|
|
+ migrations.CreateModel('Person2', fields=[]),
|
|
|
+ migrations.CreateModel('Person3', fields=[]),
|
|
|
+ migrations.DeleteModel('Person4'),
|
|
|
+ migrations.DeleteModel('Person5'),
|
|
|
+ ]
|
|
|
+
|
|
|
+ migration = Migration('some_migration', 'test_app')
|
|
|
+ self.assertEqual(
|
|
|
+ migration.suggest_name(),
|
|
|
+ 'person1_person2_person3_delete_person4_and_more',
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_operation_with_no_suggested_name(self):
|
|
|
+ class Migration(migrations.Migration):
|
|
|
+ operations = [
|
|
|
+ migrations.CreateModel('Person', fields=[]),
|
|
|
+ migrations.RunSQL('SELECT 1 FROM person;'),
|
|
|
+ ]
|
|
|
+
|
|
|
+ migration = Migration('some_migration', 'test_app')
|
|
|
+ self.assertIs(migration.suggest_name().startswith('auto_'), True)
|
|
|
+
|
|
|
def test_none_name(self):
|
|
|
class Migration(migrations.Migration):
|
|
|
operations = [migrations.RunSQL('SELECT 1 FROM person;')]
|