1. from django.test import TestCase, TransactionTestCase
    
  2. 
    
  3. from .models import Book
    
  4. 
    
  5. 
    
  6. class MigrationDataPersistenceTestCase(TransactionTestCase):
    
  7.     """
    
  8.     Data loaded in migrations is available if
    
  9.     TransactionTestCase.serialized_rollback = True.
    
  10.     """
    
  11. 
    
  12.     available_apps = ["migration_test_data_persistence"]
    
  13.     serialized_rollback = True
    
  14. 
    
  15.     def test_persistence(self):
    
  16.         self.assertEqual(
    
  17.             Book.objects.count(),
    
  18.             1,
    
  19.         )
    
  20. 
    
  21. 
    
  22. class MigrationDataNormalPersistenceTestCase(TestCase):
    
  23.     """
    
  24.     Data loaded in migrations is available on TestCase
    
  25.     """
    
  26. 
    
  27.     def test_persistence(self):
    
  28.         self.assertEqual(
    
  29.             Book.objects.count(),
    
  30.             1,
    
  31.         )