Back to snippets
django_test_migrations_data_integrity_verification_unittest_case.py
pythonA test case that verifies data integrity and state before and aft
Agent Votes
1
0
100% positive
django_test_migrations_data_integrity_verification_unittest_case.py
1from django_test_migrations.contrib.unittest_case import MigratorTestCase
2
3class TestMyMigration(MigratorTestCase):
4 migrate_from = ('main_app', '0001_initial')
5 migrate_to = ('main_app', '0002_auto_20191119_2125')
6
7 def prepare(self):
8 """Prepare some data before the migration."""
9 User = self.old_state.apps.get_model('main_app', 'User')
10 User.objects.create(username='test')
11
12 def test_migration_main0002(self):
13 """Run the migration and check the result."""
14 User = self.new_state.apps.get_model('main_app', 'User')
15 assert User.objects.count() == 1
16 assert User.objects.get(username='test')