Created
October 27, 2016 19:23
-
-
Save Fitblip/4545b95dea3b5618dc8413cede28eb14 to your computer and use it in GitHub Desktop.
Django test for un-run migtraionts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
It's worth noting that we use the built-in User model, but also have a tweak that enforces email | |
uniqueness (which IMO is a pretty large oversight by the django folks), so that's why it's acceptable | |
that `Migrations for 'auth'` is in the payload. | |
''' | |
class TestForNonGeneratedMigrations(TestCase): | |
def test_for_migrations_to_run(self): | |
stdout = StringIO.StringIO() | |
call_command('makemigrations', no_color=True, dry_run=True, stdout=stdout) | |
# If we have any lines that begin with "Migrations for" that are *not* for the django 'auth' app (since we | |
# have a custom tweak to the model to enforce email uniqueness), then blow up. | |
unrun_migrations = [] | |
for line in stdout.getvalue().split('\n'): | |
if line.startswith('Migrations for') and "Migrations for 'auth'" not in line: | |
unrun_migrations.append(line) | |
self.assertEqual(len(unrun_migrations), 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment