tests.py 770 B

123456789101112131415161718192021222324252627282930313233
  1. from django.test import TransactionTestCase
  2. from .models import Book
  3. class MigrationDataPersistenceTestCase(TransactionTestCase):
  4. """
  5. Tests that data loaded in migrations is available if we set
  6. serialized_rollback = True.
  7. """
  8. available_apps = ["migration_test_data_persistence"]
  9. serialized_rollback = True
  10. def test_persistence(self):
  11. self.assertEqual(
  12. Book.objects.count(),
  13. 1,
  14. )
  15. class MigrationDataNoPersistenceTestCase(TransactionTestCase):
  16. """
  17. Tests the failure case
  18. """
  19. available_apps = ["migration_test_data_persistence"]
  20. serialized_rollback = False
  21. def test_no_persistence(self):
  22. self.assertEqual(
  23. Book.objects.count(),
  24. 0,
  25. )