Skip to content

Commit 5b9236a

Browse files
author
Andy Babic
committed
Test migration outcomes
1 parent cc850e9 commit 5b9236a

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed

tests/test_migration_outcomes.py

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
from django.test import TestCase
2+
from testapp.constants import COMPLEX_MODIFIED_BODY_VALUE, COMPLEX_ORIGINAL_BODY_VALUE
3+
from testapp.models import TestPage, TestSnippet
4+
5+
6+
class TestMigrationOutcomes(TestCase):
7+
@classmethod
8+
def setUpTestData(cls):
9+
for i, page in enumerate(TestPage.objects.all().order_by("id"), start=1):
10+
setattr(cls, f"page_{i}", page)
11+
for i, snippet in enumerate(TestSnippet.objects.all().order_by("id"), start=1):
12+
setattr(cls, f"snippet_{i}", snippet)
13+
14+
def test_original_pages_and_snippets_have_retained_their_original_body_values(self):
15+
"""
16+
Test the objects created in `0002_create_test_objects` and DID NOT have their `body` value
17+
updated in later migrations have retained their original values after:
18+
19+
- Swapping the native StreamField for a custom one in `0003_swap_native_streamfield_for_mlstreamfield`
20+
- Updating their title in `0007_modify_title_values` and resaving
21+
- Updating their title in `0008_modify_title_values_with_bulk_update` via a bulk update
22+
"""
23+
self.assertEqual(self.page_1.title, "Modified Test Page")
24+
for i, block in enumerate(self.page_1.body.raw_data):
25+
compare_to = COMPLEX_ORIGINAL_BODY_VALUE[i]
26+
self.assertEqual(block["type"], compare_to["type"])
27+
self.assertEqual(block["value"], compare_to["value"])
28+
29+
self.assertEqual(self.snippet_1.title, "Modified Test Snippet")
30+
for i, block in enumerate(self.snippet_1.body.raw_data):
31+
compare_to = COMPLEX_ORIGINAL_BODY_VALUE[i]
32+
self.assertEqual(block["type"], compare_to["type"])
33+
self.assertEqual(block["value"], compare_to["value"])
34+
35+
def test_modified_original_pages_and_snippets_have_retained_their_modified_body_values(
36+
self,
37+
):
38+
"""
39+
Test that the objects created in `0002_create_test_objects` and had their `body` value
40+
later modified in `0004_modify_body_values` have retained that updated body value after:
41+
42+
- Updating their `title` value in `0007_modify_title_values` and resaving
43+
"""
44+
test_page = self.page_2
45+
test_snippet = self.snippet_2
46+
47+
self.assertEqual(test_page.title, "Modified Test Page Deux")
48+
for i, block in enumerate(test_page.body.raw_data):
49+
compare_to = COMPLEX_MODIFIED_BODY_VALUE[i]
50+
self.assertEqual(block["type"], compare_to["type"])
51+
self.assertEqual(block["value"], compare_to["value"])
52+
53+
self.assertEqual(test_snippet.title, "Modified Test Snippet Deux")
54+
for i, block in enumerate(test_snippet.body.raw_data):
55+
compare_to = COMPLEX_MODIFIED_BODY_VALUE[i]
56+
self.assertEqual(block["type"], compare_to["type"])
57+
self.assertEqual(block["value"], compare_to["value"])
58+
59+
def test_newer_pages_and_snippets_have_retained_their_original_body_values(self):
60+
"""
61+
Test that the objects created in `0005_create_more_test_objects` and DID NOT have their body
62+
value updated in later migrations have retained their original values after:
63+
64+
- Updating their `title` value in `0007_modify_title_values` and resaving
65+
- Updating their `title` value again in `0008_modify_title_values_with_bulk_update` via a bulk update
66+
"""
67+
test_page = self.page_3
68+
test_snippet = self.snippet_3
69+
70+
self.assertEqual(test_page.title, "Bulk Modified Test Page Tres")
71+
for i, block in enumerate(test_page.body.raw_data):
72+
compare_to = COMPLEX_ORIGINAL_BODY_VALUE[i]
73+
self.assertEqual(block["type"], compare_to["type"])
74+
self.assertEqual(block["value"], compare_to["value"])
75+
76+
self.assertEqual(test_snippet.title, "Bulk Modified Test Snippet Tres")
77+
for i, block in enumerate(test_snippet.body.raw_data):
78+
compare_to = COMPLEX_ORIGINAL_BODY_VALUE[i]
79+
self.assertEqual(block["type"], compare_to["type"])
80+
self.assertEqual(block["value"], compare_to["value"])
81+
82+
def test_modified_newer_pages_and_snippets_have_retained_their_modified_body_values(
83+
self,
84+
):
85+
"""
86+
Tests that the objects created in `0005_create_more_test_objects` and had their `body` value
87+
later modified in `0006_modify_body_values_with_bulk_update` have retained that updated `body`
88+
value after:
89+
90+
- Updating their `title` value in `0007_modify_title_values` and resaving
91+
- Updating their `title` value again in `0008_modify_title_values_with_bulk_update` via a bulk update
92+
"""
93+
test_page = self.page_4
94+
test_snippet = self.snippet_4
95+
96+
self.assertEqual(test_page.title, "Bulk Modified Test Page Cuatro")
97+
for i, block in enumerate(test_page.body.raw_data):
98+
compare_to = COMPLEX_MODIFIED_BODY_VALUE[i]
99+
self.assertEqual(block["type"], compare_to["type"])
100+
self.assertEqual(block["value"], compare_to["value"])
101+
102+
self.assertEqual(test_snippet.title, "Bulk Modified Test Snippet Cuatro")
103+
for i, block in enumerate(test_snippet.body.raw_data):
104+
compare_to = COMPLEX_MODIFIED_BODY_VALUE[i]
105+
self.assertEqual(block["type"], compare_to["type"])
106+
self.assertEqual(block["value"], compare_to["value"])

0 commit comments

Comments
 (0)