summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2013-05-19 03:54:29 -0700
committerAndrew Godwin <andrew@aeracode.org>2013-05-19 03:54:29 -0700
commit7a99d1e167f81c5fcd1b9f7f548c5d6959cef2ef (patch)
tree95b881b3517c7ca713decac8957811f081a16215 /tests
parentcc62cbed76daeaea28c1e4892244bcf1e148f373 (diff)
parent65c557115f6e76293c39ce7b73b62216911f9489 (diff)
Merge pull request #1134 from senko/ticket_18990
Fixed #18990: Loaddata now complains if fixture doesn't exist
Diffstat (limited to 'tests')
-rw-r--r--tests/fixtures/tests.py23
-rw-r--r--tests/fixtures_model_package/tests.py6
-rw-r--r--tests/fixtures_regress/tests.py16
3 files changed, 32 insertions, 13 deletions
diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py
index 103612198e..f954933046 100644
--- a/tests/fixtures/tests.py
+++ b/tests/fixtures/tests.py
@@ -1,5 +1,7 @@
from __future__ import absolute_import
+import warnings
+
from django.contrib.sites.models import Site
from django.core import management
from django.db import connection, IntegrityError
@@ -137,8 +139,18 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
'<Book: Music for all ages by Artist formerly known as "Prince" and Django Reinhardt>'
])
- # Load a fixture that doesn't exist
- management.call_command('loaddata', 'unknown.json', verbosity=0, commit=False)
+ # Loading a fixture that doesn't exist emits a warning
+ with warnings.catch_warnings(record=True) as w:
+ management.call_command('loaddata', 'unknown.json', verbosity=0,
+ commit=False)
+ self.assertEqual(len(w), 1)
+ self.assertTrue(w[0].message, "No fixture named 'unknown' found.")
+
+ # An attempt to load a nonexistent 'initial_data' fixture isn't an error
+ with warnings.catch_warnings(record=True) as w:
+ management.call_command('loaddata', 'initial_data.json', verbosity=0,
+ commit=False)
+ self.assertEqual(len(w), 0)
# object list is unaffected
self.assertQuerysetEqual(Article.objects.all(), [
@@ -273,10 +285,11 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase):
def test_unmatched_identifier_loading(self):
# Try to load db fixture 3. This won't load because the database identifier doesn't match
- management.call_command('loaddata', 'db_fixture_3', verbosity=0, commit=False)
- self.assertQuerysetEqual(Article.objects.all(), [])
+ with warnings.catch_warnings(record=True):
+ management.call_command('loaddata', 'db_fixture_3', verbosity=0, commit=False)
- management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default', commit=False)
+ with warnings.catch_warnings(record=True):
+ management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default', commit=False)
self.assertQuerysetEqual(Article.objects.all(), [])
def test_output_formats(self):
diff --git a/tests/fixtures_model_package/tests.py b/tests/fixtures_model_package/tests.py
index c250f647ce..fbd0271336 100644
--- a/tests/fixtures_model_package/tests.py
+++ b/tests/fixtures_model_package/tests.py
@@ -1,5 +1,7 @@
from __future__ import unicode_literals
+import warnings
+
from django.core import management
from django.db import transaction
from django.test import TestCase, TransactionTestCase
@@ -100,7 +102,9 @@ class FixtureTestCase(TestCase):
)
# Load a fixture that doesn't exist
- management.call_command("loaddata", "unknown.json", verbosity=0, commit=False)
+ with warnings.catch_warnings(record=True):
+ management.call_command("loaddata", "unknown.json", verbosity=0, commit=False)
+
self.assertQuerysetEqual(
Article.objects.all(), [
"Django conquers world!",
diff --git a/tests/fixtures_regress/tests.py b/tests/fixtures_regress/tests.py
index 02e923e386..5114302267 100644
--- a/tests/fixtures_regress/tests.py
+++ b/tests/fixtures_regress/tests.py
@@ -4,6 +4,7 @@ from __future__ import absolute_import, unicode_literals
import os
import re
+import warnings
from django.core.serializers.base import DeserializationError
from django.core import management
@@ -441,13 +442,14 @@ class TestFixtures(TestCase):
def test_loaddata_not_existant_fixture_file(self):
stdout_output = StringIO()
- management.call_command(
- 'loaddata',
- 'this_fixture_doesnt_exist',
- verbosity=2,
- commit=False,
- stdout=stdout_output,
- )
+ with warnings.catch_warnings(record=True):
+ management.call_command(
+ 'loaddata',
+ 'this_fixture_doesnt_exist',
+ verbosity=2,
+ commit=False,
+ stdout=stdout_output,
+ )
self.assertTrue("No xml fixture 'this_fixture_doesnt_exist' in" in
force_text(stdout_output.getvalue()))