diff options
| author | Andrew Godwin <andrew@aeracode.org> | 2014-06-08 19:30:15 -0700 |
|---|---|---|
| committer | Andrew Godwin <andrew@aeracode.org> | 2014-06-08 19:30:15 -0700 |
| commit | 8c12d51ea27479555e226894c50c83043211d71d (patch) | |
| tree | db1e1e462f3a9eaf56733fce6c87aabb1b498705 /tests/migration_test_data_persistence | |
| parent | 8721adcbfbc0bba7fe8341605a4ab4dffd9774d6 (diff) | |
Fixed #22487: Optional rollback emulation for migrated apps
Diffstat (limited to 'tests/migration_test_data_persistence')
5 files changed, 72 insertions, 0 deletions
diff --git a/tests/migration_test_data_persistence/__init__.py b/tests/migration_test_data_persistence/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/migration_test_data_persistence/__init__.py diff --git a/tests/migration_test_data_persistence/migrations/0001_initial.py b/tests/migration_test_data_persistence/migrations/0001_initial.py new file mode 100644 index 0000000000..0b13e8b200 --- /dev/null +++ b/tests/migration_test_data_persistence/migrations/0001_initial.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +def add_book(apps, schema_editor): + apps.get_model("migration_test_data_persistence", "Book").objects.using( + schema_editor.connection.alias, + ).create( + title="I Love Django", + ) + + +class Migration(migrations.Migration): + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Book', + fields=[ + ('id', models.AutoField(verbose_name='ID', primary_key=True, serialize=False, auto_created=True)), + ('title', models.CharField(max_length=100)), + ], + options={ + }, + bases=(models.Model,), + ), + migrations.RunPython( + add_book, + ), + ] diff --git a/tests/migration_test_data_persistence/migrations/__init__.py b/tests/migration_test_data_persistence/migrations/__init__.py new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/tests/migration_test_data_persistence/migrations/__init__.py diff --git a/tests/migration_test_data_persistence/models.py b/tests/migration_test_data_persistence/models.py new file mode 100644 index 0000000000..1b0b795d2c --- /dev/null +++ b/tests/migration_test_data_persistence/models.py @@ -0,0 +1,5 @@ +from django.db import models + + +class Book(models.Model): + title = models.CharField(max_length=100) diff --git a/tests/migration_test_data_persistence/tests.py b/tests/migration_test_data_persistence/tests.py new file mode 100644 index 0000000000..1b89c17b8b --- /dev/null +++ b/tests/migration_test_data_persistence/tests.py @@ -0,0 +1,33 @@ +from django.test import TransactionTestCase +from .models import Book + + +class MigrationDataPersistenceTestCase(TransactionTestCase): + """ + Tests that data loaded in migrations is available if we set + serialized_rollback = True. + """ + + available_apps = ["migration_test_data_persistence"] + serialized_rollback = True + + def test_persistence(self): + self.assertEqual( + Book.objects.count(), + 1, + ) + + +class MigrationDataNoPersistenceTestCase(TransactionTestCase): + """ + Tests the failure case + """ + + available_apps = ["migration_test_data_persistence"] + serialized_rollback = False + + def test_no_persistence(self): + self.assertEqual( + Book.objects.count(), + 0, + ) |
