def serializerTest(format, self): # Clear the database first management.flush(verbosity=0, interactive=False) # Create all the objects defined in the test data objects = [] transaction.enter_transaction_management() transaction.managed(True) for (func, pk, klass, datum) in test_data: objects.append(func[0](pk, klass, datum)) transaction.commit() transaction.leave_transaction_management() # Add the generic tagged objects to the object list objects.extend(Tag.objects.all()) # Serialize the test database serialized_data = serializers.serialize(format, objects, indent=2) # Flush the database and recreate from the serialized data management.flush(verbosity=0, interactive=False) transaction.enter_transaction_management() transaction.managed(True) for obj in serializers.deserialize(format, serialized_data): obj.save() transaction.commit() transaction.leave_transaction_management() # Assert that the deserialized data is the same # as the original source for (func, pk, klass, datum) in test_data: func[1](self, pk, klass, datum)
def install_fixtures(self): """If the Test Case class has a 'fixtures' member, clear the database and install the named fixtures at the start of each test. """ management.flush(verbosity=0, interactive=False) if hasattr(self, 'fixtures'): management.load_data(self.fixtures, verbosity=0)
def _pre_setup(self): """Perform any pre-test setup. This includes: * If the Test Case class has a 'fixtures' member, clearing the database and installing the named fixtures at the start of each test. * Clearing the mail test outbox. """ management.flush(verbosity=0, interactive=False) if hasattr(self, 'fixtures'): management.load_data(self.fixtures, verbosity=0) mail.outbox = []