summaryrefslogtreecommitdiff
path: root/tests/migration_test_data_persistence
diff options
context:
space:
mode:
authorAndrew Godwin <andrew@aeracode.org>2014-06-08 19:30:15 -0700
committerAndrew Godwin <andrew@aeracode.org>2014-06-08 19:33:52 -0700
commit08218252d8be4633ac0e94863da527d824648d63 (patch)
tree7b2724bc7730960af1ba7b539192132ccae2f50c /tests/migration_test_data_persistence
parentbf019c977055ade45c5c260ed235bb5dcf7e2be7 (diff)
[1.7.x] Fixed #22487: Optional rollback emulation for migrated apps
Conflicts: django/db/backends/creation.py django/test/runner.py docs/ref/settings.txt docs/topics/testing/advanced.txt
Diffstat (limited to 'tests/migration_test_data_persistence')
-rw-r--r--tests/migration_test_data_persistence/__init__.py0
-rw-r--r--tests/migration_test_data_persistence/migrations/0001_initial.py34
-rw-r--r--tests/migration_test_data_persistence/migrations/__init__.py0
-rw-r--r--tests/migration_test_data_persistence/models.py5
-rw-r--r--tests/migration_test_data_persistence/tests.py33
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,
+ )