Skip to content

Commit

Permalink
adding test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick Mixell committed Dec 24, 2023
1 parent 00644b1 commit ecadd52
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
34 changes: 34 additions & 0 deletions wagtail_localize/segments/tests/test_segment_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,40 @@ def test_customstructblock(self):
],
)

def test_structblockwithoverrides(self):
block_id = uuid.uuid4()
page = make_test_page_with_streamfield_block(
str(block_id),
"test_structblockwithoverrides",
{"field_a": "Test content", "field_b": "Non-translatable content"},
)

segments = extract_segments(page)

self.assertEqual(
segments,
[
StringSegmentValue(
f"test_streamfield.{block_id}.field_a",
"Test content",
)
],
)

def test_structblockignoreall(self):
block_id = uuid.uuid4()
page = make_test_page_with_streamfield_block(
str(block_id),
"test_structblockignoreall",
{
"field_a": "Non-translatable content",
"field_b": "Non-translatable content",
},
)

segments = extract_segments(page)
self.assertEqual(segments, [])

def test_customblockwithoutextractmethod(self):
block_id = uuid.uuid4()
page = make_test_page_with_streamfield_block(
Expand Down
16 changes: 16 additions & 0 deletions wagtail_localize/test/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,20 @@ class TestNestedStreamBlock(blocks.StreamBlock):
chooser_in_list = blocks.ListBlock(blocks.PageChooserBlock())


class TestStructBlockOverride(blocks.StructBlock):
field_a = blocks.TextBlock()
field_b = blocks.TextBlock()

override_translatable_blocks = ["field_a"]


class TestStructBlockIgnoreAll(blocks.StructBlock):
field_a = blocks.TextBlock()
field_b = blocks.TextBlock()

override_translatable_blocks = []


class TestNestedChooserStructBlock(blocks.StructBlock):
nested_page = TestChooserStructBlock()

Expand Down Expand Up @@ -196,6 +210,8 @@ class TestStreamBlock(blocks.StreamBlock):
test_nestedstreamblock = TestNestedStreamBlock()
test_streamblock_in_structblock = TestStreamBlockInStructBlock()
test_customstructblock = CustomStructBlock()
test_structblockwithoverrides = TestStructBlockOverride()
test_structblockignoreall = TestStructBlockIgnoreAll()
test_customblockwithoutextractmethod = CustomBlockWithoutExtractMethod()
test_pagechooserblock = blocks.PageChooserBlock()
test_pagechooserblock_with_restricted_types = blocks.PageChooserBlock(
Expand Down

0 comments on commit ecadd52

Please sign in to comment.