2024-09-04 15:33:44 +02:00
|
|
|
from django.core.management import call_command
|
2015-01-28 13:35:27 +01:00
|
|
|
from django.test import TestCase, TransactionTestCase
|
|
|
|
|
2014-06-09 04:30:15 +02:00
|
|
|
from .models import Book
|
|
|
|
|
|
|
|
|
|
|
|
class MigrationDataPersistenceTestCase(TransactionTestCase):
|
|
|
|
"""
|
2016-10-27 09:53:39 +02:00
|
|
|
Data loaded in migrations is available if
|
|
|
|
TransactionTestCase.serialized_rollback = True.
|
2014-06-09 04:30:15 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
available_apps = ["migration_test_data_persistence"]
|
|
|
|
serialized_rollback = True
|
|
|
|
|
|
|
|
def test_persistence(self):
|
|
|
|
self.assertEqual(
|
|
|
|
Book.objects.count(),
|
|
|
|
1,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2024-09-04 15:33:44 +02:00
|
|
|
class MigrationDataPersistenceClassSetup(TransactionTestCase):
|
|
|
|
"""
|
|
|
|
Data loaded in migrations is available during class setup if
|
|
|
|
TransactionTestCase.serialized_rollback = True.
|
|
|
|
"""
|
|
|
|
|
|
|
|
available_apps = ["migration_test_data_persistence"]
|
|
|
|
serialized_rollback = True
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
# Simulate another TransactionTestCase having just torn down.
|
|
|
|
call_command("flush", verbosity=0, interactive=False)
|
|
|
|
super().setUpClass()
|
|
|
|
cls.book = Book.objects.first()
|
|
|
|
|
|
|
|
def test_data_available_in_class_setup(self):
|
|
|
|
self.assertIsInstance(self.book, Book)
|
|
|
|
|
|
|
|
|
2014-06-24 05:25:09 +02:00
|
|
|
class MigrationDataNormalPersistenceTestCase(TestCase):
|
2014-06-09 04:30:15 +02:00
|
|
|
"""
|
2016-10-27 09:53:39 +02:00
|
|
|
Data loaded in migrations is available on TestCase
|
2014-06-09 04:30:15 +02:00
|
|
|
"""
|
|
|
|
|
2014-06-24 05:25:09 +02:00
|
|
|
def test_persistence(self):
|
2014-06-09 04:30:15 +02:00
|
|
|
self.assertEqual(
|
|
|
|
Book.objects.count(),
|
2014-06-24 05:25:09 +02:00
|
|
|
1,
|
2014-06-09 04:30:15 +02:00
|
|
|
)
|