Skip to content

Commit

Permalink
migrations: Teach MigrationTests about existing duplicate migration n…
Browse files Browse the repository at this point in the history
…umbers
  • Loading branch information
moseb committed May 6, 2019
1 parent 6e8ab4e commit 6cdc98c
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions t/unit/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@


class MigrationTests(TestCase):
def test_no_duplicate_migration_numbers(self):
def test_no_future_duplicate_migration_numbers(self):
"""Verify no duplicate migration numbers.
Migration files with the same number can cause issues with
backward migrations, so avoid them.
"""
path = os.path.dirname(beat_migrations.__file__)
files = [f[:4] for f in os.listdir(path) if f.endswith('.py')]
expected_duplicates = [
(3, '0006'),
]
duplicates_extra = sum(count - 1 for count, _ in expected_duplicates)
duplicates_numbers = [number for _, number in expected_duplicates]
self.assertEqual(
len(files), len(set(files)),
msg='Detected migration files with the same migration number')
len(files), len(set(files)) + duplicates_extra,
msg=('Detected migration files with the same migration number'
' (besides {})'.format(' and '.join(duplicates_numbers))))

def test_models_match_migrations(self):
"""Make sure that no model changes exist.
Expand Down

0 comments on commit 6cdc98c

Please sign in to comment.