Skip to content

Instantly share code, notes, and snippets.

@Fitblip
Created October 27, 2016 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fitblip/4545b95dea3b5618dc8413cede28eb14 to your computer and use it in GitHub Desktop.
Save Fitblip/4545b95dea3b5618dc8413cede28eb14 to your computer and use it in GitHub Desktop.
Django test for un-run migtraionts
'''
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