mirror of
https://github.com/django/django.git
synced 2025-10-31 09:41:08 +00:00
Fixed #10200 -- Raised CommandError when errors happen in loaddata.
This commit is contained in:
@@ -4,7 +4,7 @@ import StringIO
|
||||
|
||||
from django.contrib.sites.models import Site
|
||||
from django.core import management
|
||||
from django.db import connection
|
||||
from django.db import connection, IntegrityError
|
||||
from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature
|
||||
|
||||
from .models import Article, Book, Spy, Tag, Visa
|
||||
@@ -232,11 +232,9 @@ class FixtureLoadingTests(TestCase):
|
||||
|
||||
def test_ambiguous_compressed_fixture(self):
|
||||
# The name "fixture5" is ambigous, so loading it will raise an error
|
||||
new_io = StringIO.StringIO()
|
||||
management.call_command('loaddata', 'fixture5', verbosity=0, stderr=new_io, commit=False)
|
||||
output = new_io.getvalue().strip().split('\n')
|
||||
self.assertEqual(len(output), 1)
|
||||
self.assertTrue(output[0].startswith("Multiple fixtures named 'fixture5'"))
|
||||
with self.assertRaisesRegexp(management.CommandError,
|
||||
"Multiple fixtures named 'fixture5'"):
|
||||
management.call_command('loaddata', 'fixture5', verbosity=0, commit=False)
|
||||
|
||||
def test_db_loading(self):
|
||||
# Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly
|
||||
@@ -258,10 +256,9 @@ class FixtureLoadingTests(TestCase):
|
||||
# is closed at the end of each test.
|
||||
if connection.vendor == 'mysql':
|
||||
connection.cursor().execute("SET sql_mode = 'TRADITIONAL'")
|
||||
new_io = StringIO.StringIO()
|
||||
management.call_command('loaddata', 'invalid.json', verbosity=0, stderr=new_io, commit=False)
|
||||
output = new_io.getvalue().strip().split('\n')
|
||||
self.assertRegexpMatches(output[-1], "Error: Could not load fixtures.Article\(pk=1\): .*$")
|
||||
with self.assertRaisesRegexp(IntegrityError,
|
||||
"Could not load fixtures.Article\(pk=1\): .*$"):
|
||||
management.call_command('loaddata', 'invalid.json', verbosity=0, commit=False)
|
||||
|
||||
def test_loading_using(self):
|
||||
# Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly
|
||||
@@ -316,11 +313,9 @@ class FixtureTransactionTests(TransactionTestCase):
|
||||
|
||||
# Try to load fixture 2 using format discovery; this will fail
|
||||
# because there are two fixture2's in the fixtures directory
|
||||
new_io = StringIO.StringIO()
|
||||
management.call_command('loaddata', 'fixture2', verbosity=0, stderr=new_io)
|
||||
output = new_io.getvalue().strip().split('\n')
|
||||
self.assertEqual(len(output), 1)
|
||||
self.assertTrue(output[0].startswith("Multiple fixtures named 'fixture2'"))
|
||||
with self.assertRaisesRegexp(management.CommandError,
|
||||
"Multiple fixtures named 'fixture2'"):
|
||||
management.call_command('loaddata', 'fixture2', verbosity=0)
|
||||
|
||||
# object list is unaffected
|
||||
self.assertQuerysetEqual(Article.objects.all(), [
|
||||
|
||||
Reference in New Issue
Block a user