Skip to content

Commit b63d2b0

Browse files
author
Andy Babic
committed
Improve coverage
1 parent fedec3a commit b63d2b0

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

.github/workflows/test.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ jobs:
7676
run: |
7777
tox --installpkg ./dist/*.whl || (echo "::error::Tests failed" && exit 1)
7878
79+
- name: ⬆️ Upload coverage data
80+
uses: actions/upload-artifact@v4
81+
with:
82+
name: coverage-data-${{ matrix.python-version }}-${{ matrix.django }}-${{ matrix.wagtail }}-${{ matrix.db }}
83+
path: .coverage*
84+
if-no-files-found: error
85+
include-hidden-files: true
86+
7987
test-sqlite:
8088
runs-on: ubuntu-latest
8189
strategy:

tests/test_field.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,35 @@ def test_get_prep_value_with_none(self):
127127
# Should return None
128128
result = self.field.get_prep_value(None)
129129
self.assertIsNone(result)
130+
131+
def test_deconstruct_removes_block_lookup(self):
132+
# Test that block_lookup is removed during deconstruction
133+
field = StreamField(self.block_types)
134+
field.block_lookup = {"some": "value"} # Add block_lookup
135+
name, path, args, kwargs = field.deconstruct()
136+
self.assertNotIn("block_lookup", kwargs)
137+
138+
def test_to_python_with_raw_text_and_child_blocks(self):
139+
# Test that raw_text is properly handled when child_blocks exist
140+
field = StreamField(self.block_types) # Field with child blocks
141+
value = "some raw text"
142+
result = field.to_python(value)
143+
self.assertIsInstance(result, StreamValue)
144+
self.assertEqual(len(result), 0) # Should be empty as text isn't valid JSON
145+
146+
def test_deconstruct_with_block_types_in_kwargs(self):
147+
# Test deconstruct when block_types is in kwargs but no args
148+
field = StreamField()
149+
field.block_types = self.block_types # Add block_types to kwargs
150+
name, path, args, kwargs = field.deconstruct()
151+
self.assertNotIn("block_types", kwargs)
152+
153+
def test_to_python_with_child_blocks(self):
154+
# Test that to_python uses the parent class implementation when child_blocks exist
155+
field = StreamField(self.block_types) # Field with child blocks
156+
value = [{"type": "text", "value": "test"}]
157+
result = field.to_python(value)
158+
# Verify the value was processed by the parent class
159+
self.assertIsInstance(result, StreamValue)
160+
self.assertEqual(len(result), 1)
161+
self.assertEqual(result[0].value, "test")

0 commit comments

Comments
 (0)