Skip to content

Commit

Permalink
Replace usage of .stream_data with .raw_data
Browse files Browse the repository at this point in the history
  • Loading branch information
kaedroho committed Aug 2, 2021
1 parent 11850f0 commit d70346a
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions wagtail_localize/segments/tests/test_segment_ingestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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")
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit d70346a

Please sign in to comment.