Fixed #25304 -- Allowed management commands to check if migrations are applied.

This commit is contained in:
Mounir Messelmeni 2016-02-12 11:02:36 +01:00 committed by Tim Graham
parent 004ba0f99e
commit 50931dfa53
8 changed files with 76 additions and 39 deletions

View file

@ -7,12 +7,14 @@ from django.core import management
from django.core.management import BaseCommand, CommandError, find_commands
from django.core.management.utils import find_command, popen_wrapper
from django.db import connection
from django.test import SimpleTestCase, override_settings
from django.test import SimpleTestCase, mock, override_settings
from django.test.utils import captured_stderr, extend_sys_path
from django.utils import translation
from django.utils._os import upath
from django.utils.six import StringIO
from .management.commands import dance
# A minimal set of apps to avoid system checks running on all apps.
@override_settings(
@ -161,6 +163,18 @@ class CommandTests(SimpleTestCase):
finally:
BaseCommand.check = saved_check
def test_check_migrations(self):
requires_migrations_checks = dance.Command.requires_migrations_checks
try:
with mock.patch.object(BaseCommand, 'check_migrations') as check_migrations:
management.call_command('dance', verbosity=0)
self.assertFalse(check_migrations.called)
dance.Command.requires_migrations_checks = True
management.call_command('dance', verbosity=0)
self.assertTrue(check_migrations.called)
finally:
dance.Command.requires_migrations_checks = requires_migrations_checks
class CommandRunTests(AdminScriptTestCase):
"""