Changeset 7595
- Timestamp:
- 06/08/08 03:21:18 (3 months ago)
- Files:
-
- django/trunk/AUTHORS (modified) (1 diff)
- django/trunk/django/core/management/commands/loaddata.py (modified) (6 diffs)
- django/trunk/tests/regressiontests/fixtures_regress/fixtures/bad_fixture1.unkn (added)
- django/trunk/tests/regressiontests/fixtures_regress/fixtures/bad_fixture2.xml (added)
- django/trunk/tests/regressiontests/fixtures_regress/models.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/AUTHORS
r7586 r7595 79 79 btoll@bestweb.net 80 80 Jonathan Buchanan <jonathan.buchanan@gmail.com> 81 Keith Bussell <kbussell@gmail.com> 81 82 Juan Manuel Caicedo <juan.manuel.caicedo@gmail.com> 82 83 Trevor Caira <trevor@caira.com> django/trunk/django/core/management/commands/loaddata.py
r7294 r7595 33 33 fixture_count = 0 34 34 object_count = 0 35 objects_per_fixture = [] 35 36 models = set() 36 37 … … 61 62 formats = [] 62 63 63 if verbosity >= 2:64 if formats:64 if formats: 65 if verbosity > 1: 65 66 print "Loading '%s' fixtures..." % fixture_name 66 else: 67 print "Skipping fixture '%s': %s is not a known serialization format" % (fixture_name, format) 67 else: 68 sys.stderr.write( 69 self.style.ERROR("Problem installing fixture '%s': %s is not a known serialization format." % 70 (fixture_name, format))) 71 transaction.rollback() 72 transaction.leave_transaction_management() 73 return 68 74 69 75 if os.path.isabs(fixture_name): … … 94 100 else: 95 101 fixture_count += 1 102 objects_per_fixture.append(0) 96 103 if verbosity > 0: 97 104 print "Installing %s fixture '%s' from %s." % \ … … 101 108 for obj in objects: 102 109 object_count += 1 110 objects_per_fixture[-1] += 1 103 111 models.add(obj.object.__class__) 104 112 obj.save() … … 118 126 fixture.close() 119 127 except: 120 if verbosity > = 2:128 if verbosity > 1: 121 129 print "No %s fixture '%s' in %s." % \ 122 130 (format, fixture_name, humanize(fixture_dir)) 123 131 132 133 # If any of the fixtures we loaded contain 0 objects, assume that an 134 # error was encountered during fixture loading. 135 if 0 in objects_per_fixture: 136 sys.stderr.write( 137 self.style.ERROR("No fixture data found for '%s'. (File format may be invalid.)" % 138 (fixture_name))) 139 transaction.rollback() 140 transaction.leave_transaction_management() 141 return 142 143 # If we found even one object in a fixture, we need to reset the 144 # database sequences. 124 145 if object_count > 0: 125 146 sequence_sql = connection.ops.sequence_reset_sql(self.style, models) … … 129 150 for line in sequence_sql: 130 151 cursor.execute(line) 131 152 132 153 transaction.commit() 133 154 transaction.leave_transaction_management() 134 155 135 156 if object_count == 0: 136 if verbosity > = 2:157 if verbosity > 1: 137 158 print "No fixtures found." 138 159 else: django/trunk/tests/regressiontests/fixtures_regress/models.py
r7145 r7595 72 72 1 73 73 74 ############################################### 75 # Test for ticket #4371 -- fixture loading fails silently in testcases 76 # Validate that error conditions are caught correctly 77 78 # redirect stderr for the next few tests... 79 >>> import sys 80 >>> savestderr = sys.stderr 81 >>> sys.stderr = sys.stdout 82 83 # Loading data of an unknown format should fail 84 >>> management.call_command('loaddata', 'bad_fixture1.unkn', verbosity=0) 85 Problem installing fixture 'bad_fixture1': unkn is not a known serialization format. 86 87 # Loading a fixture file with invalid data using explicit filename 88 >>> management.call_command('loaddata', 'bad_fixture2.xml', verbosity=0) 89 No fixture data found for 'bad_fixture2'. (File format may be invalid.) 90 91 # Loading a fixture file with invalid data without file extension 92 >>> management.call_command('loaddata', 'bad_fixture2', verbosity=0) 93 No fixture data found for 'bad_fixture2'. (File format may be invalid.) 94 95 >>> sys.stderr = savestderr 96 74 97 """}
