diff options
| author | Jon Dufresne <jon.dufresne@gmail.com> | 2020-06-13 10:06:05 -0700 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-06-24 07:01:11 +0200 |
| commit | bce180dd05c425341261240fab1d2642e6d4bc65 (patch) | |
| tree | a4c92ac98c915a7844f678711b52870ae2380a49 /tests | |
| parent | 798835112d81b852efaae0e067af389c733cd1b3 (diff) | |
Refs #31703 -- Moved MigrationAutodetector.suggest_name() to Migration.
Allows expanding the method to inspect additional attributes of the
migration instance. For example, the Migration.initial attribute.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/migrations/test_autodetector.py | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/tests/migrations/test_autodetector.py b/tests/migrations/test_autodetector.py index ab52b8116d..dddda94eb2 100644 --- a/tests/migrations/test_autodetector.py +++ b/tests/migrations/test_autodetector.py @@ -2481,25 +2481,39 @@ class AutodetectorTests(TestCase): self.assertOperationAttributes(changes, 'app', 0, 1, name='book') -class AutodetectorSuggestNameTests(SimpleTestCase): +class MigrationSuggestNameTests(SimpleTestCase): def test_single_operation(self): - ops = [migrations.CreateModel('Person', fields=[])] - self.assertEqual(MigrationAutodetector.suggest_name(ops), 'person') - ops = [migrations.DeleteModel('Person')] - self.assertEqual(MigrationAutodetector.suggest_name(ops), 'delete_person') + class Migration(migrations.Migration): + operations = [migrations.CreateModel('Person', fields=[])] + + migration = Migration('0001_initial', 'test_app') + self.assertEqual(migration.suggest_name(), 'person') + + class Migration(migrations.Migration): + operations = [migrations.DeleteModel('Person')] + + migration = Migration('0002_initial', 'test_app') + self.assertEqual(migration.suggest_name(), 'delete_person') def test_two_create_models(self): - ops = [ - migrations.CreateModel('Person', fields=[]), - migrations.CreateModel('Animal', fields=[]), - ] - self.assertEqual(MigrationAutodetector.suggest_name(ops), 'animal_person') + class Migration(migrations.Migration): + operations = [ + migrations.CreateModel('Person', fields=[]), + migrations.CreateModel('Animal', fields=[]), + ] + + migration = Migration('0001_initial', 'test_app') + self.assertEqual(migration.suggest_name(), 'animal_person') def test_none_name(self): - ops = [migrations.RunSQL('SELECT 1 FROM person;')] - suggest_name = MigrationAutodetector.suggest_name(ops) + class Migration(migrations.Migration): + operations = [migrations.RunSQL('SELECT 1 FROM person;')] + + migration = Migration('0001_initial', 'test_app') + suggest_name = migration.suggest_name() self.assertIs(suggest_name.startswith('auto_'), True) def test_auto(self): - suggest_name = MigrationAutodetector.suggest_name([]) + migration = migrations.Migration('0001_initial', 'test_app') + suggest_name = migration.suggest_name() self.assertIs(suggest_name.startswith('auto_'), True) |
