Ticket #18990: 18990_tests.path

File 18990_tests.path, 4.9 KB (added by d1ffuz0r, 3 years ago)

Some modifications and tests for the path

Line 
1diff --git a/django/core/management/commands/loaddata.py b/django/core/management/commands/loaddata.py
2index 32ae8ab..4fe99f3 100644
3--- a/django/core/management/commands/loaddata.py
4+++ b/django/core/management/commands/loaddata.py
5@@ -97,6 +97,8 @@ class Command(BaseCommand):
6         if has_bz2:
7             compression_types['bz2'] = bz2.BZ2File
8 
9+        fixture_file_found = False
10+
11         app_module_paths = []
12         for app in get_apps():
13             if hasattr(app, '__path__'):
14@@ -164,6 +166,7 @@ class Command(BaseCommand):
15                             open_method = compression_types[compression_format]
16                             try:
17                                 fixture = open_method(full_path, 'r')
18+                                fixture_file_found = True
19                             except IOError:
20                                 if verbosity >= 2:
21                                     self.stdout.write("No %s fixture '%s' in %s." % \
22@@ -215,6 +218,9 @@ class Command(BaseCommand):
23                                     raise CommandError(
24                                         "No fixture data found for '%s'. (File format may be invalid.)" %
25                                             (fixture_name))
26+                    if not fixture_file_found:
27+                        self.stderr.write("Any fixture file couldn't be found for '%s'" %
28+                                          fixture_label)
29 
30             # Since we disabled constraint checks, we must manually check for
31             # any invalid keys that might have been added
32diff --git a/tests/modeltests/fixtures/tests.py b/tests/modeltests/fixtures/tests.py
33index f9b0ac8..a80ca72 100644
34--- a/tests/modeltests/fixtures/tests.py
35+++ b/tests/modeltests/fixtures/tests.py
36@@ -130,7 +130,7 @@ class FixtureLoadingTests(TestCase):
37         ])
38 
39         # Load a fixture that doesn't exist
40-        management.call_command('loaddata', 'unknown.json', verbosity=0, commit=False)
41+        management.call_command('loaddata', 'unknown.json', verbosity=0, stderr=six.StringIO(), commit=False)
42 
43         # object list is unaffected
44         self.assertQuerysetEqual(Article.objects.all(), [
45@@ -265,10 +265,11 @@ class FixtureLoadingTests(TestCase):
46 
47     def test_unmatched_identifier_loading(self):
48         # Try to load db fixture 3. This won't load because the database identifier doesn't match
49-        management.call_command('loaddata', 'db_fixture_3', verbosity=0, commit=False)
50+        management.call_command('loaddata', 'db_fixture_3', verbosity=0, stderr=six.StringIO(), commit=False)
51         self.assertQuerysetEqual(Article.objects.all(), [])
52 
53-        management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default', commit=False)
54+        management.call_command('loaddata', 'db_fixture_3', verbosity=0, stderr=six.StringIO(),
55+                                using='default', commit=False)
56         self.assertQuerysetEqual(Article.objects.all(), [])
57 
58     def test_output_formats(self):
59diff --git a/tests/modeltests/fixtures_model_package/tests.py b/tests/modeltests/fixtures_model_package/tests.py
60index d147fe6..68edd91 100644
61--- a/tests/modeltests/fixtures_model_package/tests.py
62+++ b/tests/modeltests/fixtures_model_package/tests.py
63@@ -3,6 +3,7 @@ from __future__ import unicode_literals
64 from django.core import management
65 from django.db import transaction
66 from django.test import TestCase, TransactionTestCase
67+from django.utils import six
68 
69 from .models import Article, Book
70 
71@@ -93,7 +94,7 @@ class FixtureTestCase(TestCase):
72         )
73 
74         # Load a fixture that doesn't exist
75-        management.call_command("loaddata", "unknown.json", verbosity=0, commit=False)
76+        management.call_command("loaddata", "unknown.json", verbosity=0, stderr=six.StringIO(), commit=False)
77         self.assertQuerysetEqual(
78             Article.objects.all(), [
79                 "Django conquers world!",
80diff --git a/tests/regressiontests/fixtures_regress/tests.py b/tests/regressiontests/fixtures_regress/tests.py
81index 678db4a..ce287dc 100644
82--- a/tests/regressiontests/fixtures_regress/tests.py
83+++ b/tests/regressiontests/fixtures_regress/tests.py
84@@ -428,10 +428,24 @@ class TestFixtures(TestCase):
85             verbosity=2,
86             commit=False,
87             stdout=stdout_output,
88+            stderr=six.StringIO()
89         )
90         self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in
91             stdout_output.getvalue())
92 
93+    def test_loaddata_not_fixture_file(self):
94+        stderr_output = six.StringIO()
95+        management.call_command(
96+            'loaddata',
97+            'this_fixture_doesnt_exist',
98+            commit=False,
99+            stderr=stderr_output,
100+            stdout=six.StringIO()
101+        )
102+
103+        self.assertTrue("Any fixture file couldn't be found for 'this_fixture_doesnt_exist'" in
104+                        stderr_output.getvalue())
105+
106 
107 class NaturalKeyFixtureTests(TestCase):
108 
Back to Top