Skip to content

Commit

Permalink
Skip new ListBlock format tests if Wagtail < 2.15
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtoppm authored and gasman committed Jun 9, 2022
1 parent 30251a8 commit dc0a064
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
PageWithStreamField, PageWithParentalManyToMany
)

from .utils import has_new_listblock_format


# We could use settings.MEDIA_ROOT here, but this way we avoid clobbering a real media folder if we
# ever run these tests with non-test settings for any reason
Expand Down Expand Up @@ -302,6 +304,8 @@ def test_rich_text_with_image_embed(self):
))

def test_streamfield_with_page_links_in_new_listblock_format(self):
if not has_new_listblock_format():
self.skipTest("This version of Wagtail does not use the UUID ListBlock format")
page = PageWithStreamField(title="I have a streamfield",
body=json.dumps([
{'type': 'list_of_captioned_pages',
Expand Down
5 changes: 5 additions & 0 deletions tests/tests/test_import.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from ensurepip import version
import importlib
import os.path
import shutil
Expand All @@ -18,6 +19,8 @@
PageWithRichText, PageWithStreamField, RedirectPage, SectionedPage, SimplePage, SponsoredPage
)

from .utils import has_new_listblock_format

# We could use settings.MEDIA_ROOT here, but this way we avoid clobbering a real media folder if we
# ever run these tests with non-test settings for any reason
TEST_MEDIA_DIR = os.path.join(os.path.join(settings.BASE_DIR, 'test-media'))
Expand Down Expand Up @@ -715,6 +718,8 @@ def test_import_page_with_streamfield_rich_text_block(self):

def test_import_page_with_new_list_block_format(self):
# Check that ids in a ListBlock with the uuid format within a StreamField are converted properly
if not has_new_listblock_format():
self.skipTest("This version of Wagtail does not use the UUID ListBlock format")

data = """{"ids_for_import": [["wagtailcore.page", 6]], "mappings": [["wagtailcore.page", 6, "a231303a-1754-11ea-8000-0800278dc04d"], ["wagtailcore.page", 100, "11111111-1111-1111-1111-111111111111"]], "objects": [{"model": "tests.pagewithstreamfield", "pk": 6, "fields": {"title": "My streamfield list block has a link", "slug": "my-streamfield-block-has-a-link", "wagtail_admin_comments": [], "live": true, "seo_title": "", "show_in_menus": false, "search_description": "", "body": "[{\\"type\\": \\"list_of_captioned_pages\\", \\"value\\": [{\\"type\\": \\"item\\", \\"value\\": {\\"page\\": 100, \\"text\\": \\"a caption\\"}, \\"id\\": \\"8c0d7de7-4f77-4477-be67-7d990d0bfb82\\"}], \\"id\\": \\"21ffe52a-c0fc-4ecc-92f1-17b356c9cc94\\"}]"}, "parent_id": 100}]}"""
importer = ImportPlanner(root_page_source_pk=1, destination_parent_id=None)
Expand Down
6 changes: 6 additions & 0 deletions tests/tests/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from wagtail import VERSION as WAGTAIL_VERSION


def has_new_listblock_format():
major, minor, *_ = WAGTAIL_VERSION
return major > 2 or (major == 2 and minor > 15)

0 comments on commit dc0a064

Please sign in to comment.