From d70346a5bd3c93be8f8ad79f42c8fbef1d31c45b Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 30 Jul 2021 15:39:54 +0100 Subject: [PATCH] Replace usage of .stream_data with .raw_data --- .../segments/tests/test_segment_ingestion.py | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/wagtail_localize/segments/tests/test_segment_ingestion.py b/wagtail_localize/segments/tests/test_segment_ingestion.py index 51408b28..cf22f3cb 100644 --- a/wagtail_localize/segments/tests/test_segment_ingestion.py +++ b/wagtail_localize/segments/tests/test_segment_ingestion.py @@ -3,6 +3,7 @@ from django.test import TestCase +from wagtail import VERSION as WAGTAIL_VERSION from wagtail.core.blocks import StreamValue from wagtail.core.models import Page, Locale @@ -18,6 +19,16 @@ from wagtail_localize.test.models import TestPage, TestSnippet, TestChildObject +def streamfield_raw_data(stream_data): + """ + Extracts raw_data from streamfields. The attribute for doing this changed in Wagtail 2.12 + """ + if WAGTAIL_VERSION >= (2, 12): + return stream_data.raw_data + else: + return stream_data.stream_data + + def make_test_page(**kwargs): root_page = Page.objects.get(id=1) kwargs.setdefault("title", "Test page") @@ -279,7 +290,7 @@ def test_charblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -309,7 +320,7 @@ def test_textblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -339,7 +350,7 @@ def test_emailblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -373,7 +384,7 @@ def test_urlblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -407,7 +418,7 @@ def test_embedblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -440,7 +451,7 @@ def test_richtextblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -474,7 +485,7 @@ def test_rawhtmlblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -504,7 +515,7 @@ def test_blockquoteblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -543,7 +554,7 @@ def test_structblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -584,7 +595,7 @@ def test_listblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -622,7 +633,7 @@ def test_nestedstreamblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id), @@ -665,7 +676,7 @@ def test_customstructblock(self): translated_page.refresh_from_db() self.assertEqual( - list(translated_page.test_streamfield.stream_data), + list(streamfield_raw_data(translated_page.test_streamfield)), [ { "id": str(block_id),