Ticket #18990: 18990_tests.patch

File 18990_tests.patch, 4.9 KB (added by Roman Gladkov, 12 years ago)
  • django/core/management/commands/loaddata.py

    diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
    index 32ae8ab..4fe99f3 100644
    a b class Command(BaseCommand):  
    9797        if has_bz2:
    9898            compression_types['bz2'] = bz2.BZ2File
    9999
     100        fixture_file_found = False
     101
    100102        app_module_paths = []
    101103        for app in get_apps():
    102104            if hasattr(app, '__path__'):
    class Command(BaseCommand):  
    164166                            open_method = compression_types[compression_format]
    165167                            try:
    166168                                fixture = open_method(full_path, 'r')
     169                                fixture_file_found = True
    167170                            except IOError:
    168171                                if verbosity >= 2:
    169172                                    self.stdout.write("No %s fixture '%s' in %s." % \
    class Command(BaseCommand):  
    215218                                    raise CommandError(
    216219                                        "No fixture data found for '%s'. (File format may be invalid.)" %
    217220                                            (fixture_name))
     221                    if not fixture_file_found:
     222                        self.stderr.write("Any fixture file couldn't be found for '%s'" %
     223                                          fixture_label)
    218224
    219225            # Since we disabled constraint checks, we must manually check for
    220226            # any invalid keys that might have been added
  • tests/modeltests/fixtures/tests.py

    diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
    index f9b0ac8..a80ca72 100644
    a b class FixtureLoadingTests(TestCase):  
    130130        ])
    131131
    132132        # Load a fixture that doesn't exist
    133         management.call_command('loaddata', 'unknown.json', verbosity=0, commit=False)
     133        management.call_command('loaddata', 'unknown.json', verbosity=0, stderr=six.StringIO(), commit=False)
    134134
    135135        # object list is unaffected
    136136        self.assertQuerysetEqual(Article.objects.all(), [
    class FixtureLoadingTests(TestCase):  
    265265
    266266    def test_unmatched_identifier_loading(self):
    267267        # Try to load db fixture 3. This won't load because the database identifier doesn't match
    268         management.call_command('loaddata', 'db_fixture_3', verbosity=0, commit=False)
     268        management.call_command('loaddata', 'db_fixture_3', verbosity=0, stderr=six.StringIO(), commit=False)
    269269        self.assertQuerysetEqual(Article.objects.all(), [])
    270270
    271         management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default', commit=False)
     271        management.call_command('loaddata', 'db_fixture_3', verbosity=0, stderr=six.StringIO(),
     272                                using='default', commit=False)
    272273        self.assertQuerysetEqual(Article.objects.all(), [])
    273274
    274275    def test_output_formats(self):
  • tests/modeltests/fixtures_model_package/tests.py

    diff --git a/tests/modeltests/fixtures_model_package/tests.py b/tests/modeltests/fixtures_model_package/tests.py
    index d147fe6..68edd91 100644
    a b from __future__ import unicode_literals  
    33from django.core import management
    44from django.db import transaction
    55from django.test import TestCase, TransactionTestCase
     6from django.utils import six
    67
    78from .models import Article, Book
    89
    class FixtureTestCase(TestCase):  
    9394        )
    9495
    9596        # Load a fixture that doesn't exist
    96         management.call_command("loaddata", "unknown.json", verbosity=0, commit=False)
     97        management.call_command("loaddata", "unknown.json", verbosity=0, stderr=six.StringIO(), commit=False)
    9798        self.assertQuerysetEqual(
    9899            Article.objects.all(), [
    99100                "Django conquers world!",
  • tests/regressiontests/fixtures_regress/tests.py

    diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
    index 678db4a..ce287dc 100644
    a b class TestFixtures(TestCase):  
    428428            verbosity=2,
    429429            commit=False,
    430430            stdout=stdout_output,
     431            stderr=six.StringIO()
    431432        )
    432433        self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in
    433434            stdout_output.getvalue())
    434435
     436    def test_loaddata_not_fixture_file(self):
     437        stderr_output = six.StringIO()
     438        management.call_command(
     439            'loaddata',
     440            'this_fixture_doesnt_exist',
     441            commit=False,
     442            stderr=stderr_output,
     443            stdout=six.StringIO()
     444        )
     445
     446        self.assertTrue("Any fixture file couldn't be found for 'this_fixture_doesnt_exist'" in
     447                        stderr_output.getvalue())
     448
    435449
    436450class NaturalKeyFixtureTests(TestCase):
    437451
Back to Top