Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 1228013 - Add a test for missing Django migrations
This test checks that `./manage.py makemigrations` was run, and the
resultant migrations file committed to the repo, since the last time the
Django models were updated.

Django 1.8 only supports an `exit_code` option, which unhelpfully makes
the command `sys.exit(1)` if there are *no* missing migrations, when
we're more interested in the opposite. As such, we have to confirm that
it does exit 1 (which causes a `SystemExit` exception).

On Django master they've replaced `exit_code` with `check_changes` that
inverts the check, which we should switch to once we're using a version
of Django that includes that fix.
  • Loading branch information
Ed Morley committed Nov 25, 2015
1 parent cd353f5 commit dd53914
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/test_setup.py
Expand Up @@ -3,6 +3,7 @@
from celery import current_app
from django.conf import settings
from django.core.cache import cache
from django.core.management import call_command


@pytest.fixture
Expand All @@ -16,6 +17,16 @@ def db_conn():
)


def test_no_missing_migrations():
"""Check no model changes have been made since the last `./manage.py makemigrations`."""
with pytest.raises(SystemExit) as e:
# Replace with `check_changes=True` once we're using a Django version that includes:
# https://code.djangoproject.com/ticket/25604
# https://github.com/django/django/pull/5453
call_command('makemigrations', interactive=False, dry_run=True, exit_code=True)
assert str(e.value) == '1'


def test_datasource_db_created(jobs_ds, db_conn):
cur = db_conn.cursor()
cur.execute("SHOW DATABASES;")
Expand Down

0 comments on commit dd53914

Please sign in to comment.