Enhanced loaddata error message printed when no DB fixture is provided.
Fixes #7043 by fixing the last code path where a misleading 'No fixtures found.' error message was being shown. git-svn-id: http://code.djangoproject.com/svn/django/trunk@17051 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
69eadc7f15
commit
345be05622
|
@ -39,6 +39,12 @@ class Command(BaseCommand):
|
||||||
connection = connections[using]
|
connection = connections[using]
|
||||||
self.style = no_style()
|
self.style = no_style()
|
||||||
|
|
||||||
|
if not len(fixture_labels):
|
||||||
|
self.stderr.write(
|
||||||
|
self.style.ERROR("No database fixture specified. Please provide the path of at least one fixture in the command line.\n")
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
verbosity = int(options.get('verbosity'))
|
verbosity = int(options.get('verbosity'))
|
||||||
show_traceback = options.get('traceback')
|
show_traceback = options.get('traceback')
|
||||||
|
|
||||||
|
@ -245,10 +251,6 @@ class Command(BaseCommand):
|
||||||
transaction.commit(using=using)
|
transaction.commit(using=using)
|
||||||
transaction.leave_transaction_management(using=using)
|
transaction.leave_transaction_management(using=using)
|
||||||
|
|
||||||
if fixture_object_count == 0:
|
|
||||||
if verbosity >= 1:
|
|
||||||
self.stdout.write("No fixtures found.\n")
|
|
||||||
else:
|
|
||||||
if verbosity >= 1:
|
if verbosity >= 1:
|
||||||
if fixture_object_count == loaded_object_count:
|
if fixture_object_count == loaded_object_count:
|
||||||
self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (
|
self.stdout.write("Installed %d object(s) from %d fixture(s)\n" % (
|
||||||
|
|
|
@ -390,6 +390,21 @@ class TestFixtures(TestCase):
|
||||||
stderr.getvalue().startswith('Problem installing fixture')
|
stderr.getvalue().startswith('Problem installing fixture')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_loaddata_no_fixture_specified(self):
|
||||||
|
"""
|
||||||
|
Regression for #7043 - Error is quickly reported when no fixtures is provided in the command line.
|
||||||
|
"""
|
||||||
|
stderr = StringIO()
|
||||||
|
management.call_command(
|
||||||
|
'loaddata',
|
||||||
|
verbosity=0,
|
||||||
|
commit=False,
|
||||||
|
stderr=stderr,
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
stderr.getvalue(), 'No database fixture specified. Please provide the path of at least one fixture in the command line.\n'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class NaturalKeyFixtureTests(TestCase):
|
class NaturalKeyFixtureTests(TestCase):
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue