Skip to content

Commit

Permalink
Fix CMS app unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fatbird committed Aug 30, 2024
1 parent 9cb0ed1 commit dbd0c24
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 26 deletions.
6 changes: 4 additions & 2 deletions src/backend/apps/cms/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class Advisory(Page, BaseModel):
body = StreamField(RichContent())

def rendered_body(self):
return wagtailcore_tags.richtext(self.body)
blocks = [wagtailcore_tags.richtext(block.render()) for block in self.body]
return '\n'.join(blocks)

api_fields = [
APIField('rendered_body'),
Expand Down Expand Up @@ -89,7 +90,8 @@ class Bulletin(Page, BaseModel):
image_alt_text = models.CharField(max_length=125, default='', blank=False)

def rendered_body(self):
return wagtailcore_tags.richtext(self.body)
blocks = [wagtailcore_tags.richtext(block.render()) for block in self.body]
return '\n'.join(blocks)

api_fields = [
APIField('rendered_body'),
Expand Down
28 changes: 14 additions & 14 deletions src/backend/apps/cms/tests/test_advisory_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,29 @@ class TestAdvisoryAPI(APITestCase, BaseTest):
def setUp(self):
super().setUp()
advisory = Advisory.objects.create(
title="Advisory title",
body="Advisory body",
geometry=MultiPolygon(Polygon([(-119, 35), (-118, 32), (-117, 31), (-119, 35)])),
path="000100010001",
depth=3,
content_type=ContentType.objects.get(app_label='cms',
model='advisory'),
title = "Advisory title",
body = '[{"id": "1", "type": "rich_text", "value": "Advisory body 1"}]',
geometry = MultiPolygon(Polygon([(-119, 35), (-118, 32), (-117, 31), (-119, 35)])),
path = "000100010001",
depth = 3,
content_type = ContentType.objects.get(app_label='cms',
model='advisory'),
)
advisory.save()

advisory_2 = Advisory.objects.create(
title="Advisory title 2",
body="Advisory body 2",
geometry=MultiPolygon(Polygon([
title = "Advisory title 2",
body = '[{"id": "1", "type": "rich_text", "value": "Advisory body 2"}]',
geometry = MultiPolygon(Polygon([
(-119, 35),
(-118, 32),
(-117, 31),
(-119, 35)
])),
path="000100010002",
depth=3,
content_type=ContentType.objects.get(app_label='cms',
model='advisory'),
path = "000100010002",
depth = 3,
content_type = ContentType.objects.get(app_label='cms',
model='advisory'),
)
advisory_2.save()

Expand Down
8 changes: 4 additions & 4 deletions src/backend/apps/cms/tests/test_advisory_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ def setUp(self):
super().setUp()

self.advisory = Advisory(
title="Advisory title 1",
body="Advisory body 1",
geometry=MultiPolygon(Polygon([
title = "Advisory title 1",
body = '[{"id": "1", "type": "rich_text", "value": "Advisory body 1"}]',
geometry = MultiPolygon(Polygon([
(-123.569743, 48.561231),
(-123.569743, 48.561231),
(-123.569743, 48.561231),
Expand Down Expand Up @@ -45,7 +45,7 @@ def test_serializer_save(self):
valid_data = {
'id': 3,
'title': 'Advisory title 1',
'body': 'Advisory body 1',
'body': '[{"id": "1", "type": "rich_text", "value": "Advisory body 1"}]',
'geometry': MultiPolygon(Polygon([
(-123.569743, 48.561231),
(-123.569743, 48.561231),
Expand Down
4 changes: 2 additions & 2 deletions src/backend/apps/cms/tests/test_bulletin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def setUp(self):

bulletin = Bulletin.objects.create(
title="Bulletin title",
body="Bulletin body",
body='[{"id": "1", "type": "rich_text", "value": "Bulletin body 1"}]',
path="000100010001",
depth=3,
image=img_obj,
Expand All @@ -42,7 +42,7 @@ def setUp(self):

bulletin_2 = Bulletin.objects.create(
title="Bulletin title 2",
body="Bulletin body 2",
body='[{"id": "1", "type": "rich_text", "value": "Bulletin body 1"}]',
path="000100010002",
depth=3,
image=img_obj,
Expand Down
8 changes: 4 additions & 4 deletions src/backend/apps/cms/tests/test_bulletin_serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def setUp(self):

self.bulletin = Bulletin(
title="Bulletin title 1",
body="Bulletin body 1",
body='[{"id": "1", "type": "rich_text", "value": "Bulletin body 1"}]',
path="000100010001",
depth=3,
image=img_obj,
Expand All @@ -41,13 +41,13 @@ def test_serializer_valid_data(self):
assert self.serializer.data["title"] == \
'Bulletin title 1'
assert self.serializer.data["body"] == \
'Bulletin body 1'
'[{"type": "rich_text", "value": "Bulletin body 1", "id": "1"}]'

def test_serializer_invalid_data(self):
# Create a serializer with invalid data
invalid_data = {
'title': '', # bulletin title is required, invalid data
'body': 'Bulletin body 1',
'body': '[{"id": "1", "type": "rich_text", "value": "Bulletin body 1"}]',
}
self.serializer = BulletinSerializer(data=invalid_data)

Expand All @@ -56,7 +56,7 @@ def test_serializer_save(self):
valid_data = {
'id': 3,
'title': 'Bulletin title 1',
'body': 'Bulletin body 1',
'body': '[{"id": "1", "type": "rich_text", "value": "Bulletin body 1"}]',
'content_type': 55,
'image': self.img_obj.id,
'image_alt_text': 'Some Image Alt text',
Expand Down

0 comments on commit dbd0c24

Please sign in to comment.