Ticket #4371: Bug4371_take2.diff
File Bug4371_take2.diff, 3.4 KB (added by , 17 years ago) |
---|
-
django/core/management/commands/loaddata.py
58 58 else: 59 59 formats = [] 60 60 61 if verbosity > 0:62 if formats:61 if formats: 62 if verbosity > 0: 63 63 print "Loading '%s' fixtures..." % fixture_name 64 else: 65 print "Skipping fixture '%s': %s is not a known serialization format" % (fixture_name, format) 64 else: 65 sys.stderr.write( 66 self.style.ERROR("Problem installing fixture '%s': %s is not a known serialization format." % 67 (fixture_name, format))) 68 transaction.rollback() 69 transaction.leave_transaction_management() 70 return 66 71 67 72 for fixture_dir in app_fixtures + list(settings.FIXTURE_DIRS) + ['']: 68 73 if verbosity > 1: … … 109 114 if verbosity > 1: 110 115 print "No %s fixture '%s' in %s." % \ 111 116 (format, fixture_name, humanize(fixture_dir)) 112 117 113 118 if count[0] > 0: 114 119 sequence_sql = connection.ops.sequence_reset_sql(self.style, models) 115 120 if sequence_sql: … … 117 122 print "Resetting sequences" 118 123 for line in sequence_sql: 119 124 cursor.execute(line) 125 elif count[1] > 0: 126 # If we found a fixture file to load, but no objects were loaded, assume error. 127 sys.stderr.write( 128 self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)" % 129 (fixture_name))) 130 transaction.rollback() 131 transaction.leave_transaction_management() 132 return 120 133 121 134 transaction.commit() 122 135 transaction.leave_transaction_management() -
tests/regressiontests/fixtures_regress/models.py
49 49 >>> Stuff.objects.all() 50 50 [<Stuff: None is owned by None>] 51 51 52 ############################################### 53 # Test for ticket #4371 -- fixture loading fails silently in testcases 54 # Validate that error conditions are caught correctly 55 56 # redirect stderr for the next few tests... 57 >>> import sys 58 >>> savestderr = sys.stderr 59 >>> sys.stderr = sys.stdout 60 61 # Loading data of an unknown format should fail 62 >>> management.call_command('loaddata', 'bad_fixture1.unkn', verbosity=0) 63 Problem installing fixture 'bad_fixture1': unkn is not a known serialization format. 64 65 # Loading a fixture file with invalid data using explicit filename 66 >>> management.call_command('loaddata', 'bad_fixture2.xml', verbosity=0) 67 No fixture data found for 'bad_fixture2'. (File format may be invalid.) 68 69 # Loading a fixture file with invalid data without file extension 70 >>> management.call_command('loaddata', 'bad_fixture2', verbosity=0) 71 No fixture data found for 'bad_fixture2'. (File format may be invalid.) 72 73 >>> sys.stderr = savestderr 52 74 """}