From f0664dc8ae541b21e3cf421725e7933a9b3a799e Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Wed, 6 Jun 2012 13:53:12 +0200 Subject: [PATCH] Made TestNoInitialDataLoading pass with MySQL (Refs #15926) --- django/core/management/commands/flush.py | 5 ++-- django/core/management/commands/syncdb.py | 4 +-- .../fixtures_model_package/tests.py | 27 +------------------ 3 files changed, 5 insertions(+), 31 deletions(-) diff --git a/django/core/management/commands/flush.py b/django/core/management/commands/flush.py index 7eb71fd1bb..2fc2e7ed26 100644 --- a/django/core/management/commands/flush.py +++ b/django/core/management/commands/flush.py @@ -81,9 +81,8 @@ The full error: %s""" % (connection.settings_dict['NAME'], e)) # Reinstall the initial_data fixture. kwargs = options.copy() kwargs['database'] = db - if options.get('load_initial_data', True): - # Reinstall the initial_data fixture. - from django.core.management import call_command + if options.get('load_initial_data'): + # Reinstall the initial_data fixture. call_command('loaddata', 'initial_data', **options) else: diff --git a/django/core/management/commands/syncdb.py b/django/core/management/commands/syncdb.py index f751a3768b..cf26e754ae 100644 --- a/django/core/management/commands/syncdb.py +++ b/django/core/management/commands/syncdb.py @@ -2,6 +2,7 @@ from optparse import make_option import traceback from django.conf import settings +from django.core.management import call_command from django.core.management.base import NoArgsCommand from django.core.management.color import no_style from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal @@ -27,7 +28,7 @@ class Command(NoArgsCommand): verbosity = int(options.get('verbosity')) interactive = options.get('interactive') show_traceback = options.get('traceback') - load_initial_data = options.get('load_initial_data', True) + load_initial_data = options.get('load_initial_data') self.style = no_style() @@ -158,6 +159,5 @@ class Command(NoArgsCommand): # Load initial_data fixtures (unless that has been disabled) if load_initial_data: - from django.core.management import call_command call_command('loaddata', 'initial_data', verbosity=verbosity, database=db, skip_validation=True) diff --git a/tests/modeltests/fixtures_model_package/tests.py b/tests/modeltests/fixtures_model_package/tests.py index 0cc90381b8..1d2cc23577 100644 --- a/tests/modeltests/fixtures_model_package/tests.py +++ b/tests/modeltests/fixtures_model_package/tests.py @@ -27,34 +27,12 @@ class TestNoInitialDataLoading(TestCase): management.call_command( 'syncdb', verbosity=0, - commit=False - ) - self.assertQuerysetEqual( - Book.objects.all(), [ - u'Achieving self-awareness of Python programs' - ], - lambda a: a.name - ) - - Book.objects.all().delete() - - management.call_command( - 'syncdb', - verbosity=0, - commit=False, load_initial_data=False ) self.assertQuerysetEqual(Book.objects.all(), []) def test_flush(self): - Book.objects.all().delete() - - management.call_command( - 'flush', - verbosity=0, - interactive=False, - commit=False - ) + # Test presence of fixture (flush called by TransactionTestCase) self.assertQuerysetEqual( Book.objects.all(), [ u'Achieving self-awareness of Python programs' @@ -62,12 +40,9 @@ class TestNoInitialDataLoading(TestCase): lambda a: a.name ) - Book.objects.all().delete() - management.call_command( 'flush', verbosity=0, - commit=False, interactive=False, load_initial_data=False )