Skip to content

Commit

Permalink
[PP-2043] Prevent None from displaying when there are no subtitles.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Jan 10, 2025
1 parent 442d177 commit ab87ca8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/palace/manager/feed/serializer/opds.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ def serialize_work_entry(self, feed_entry: WorkEntryData) -> etree._Element:

if feed_entry.title:
entry.append(OPDSFeed.E("title", feed_entry.title.text))
if feed_entry.subtitle:

if feed_entry.subtitle and feed_entry.subtitle.text:
entry.append(
OPDSFeed.E(
f"{{{OPDSFeed.SCHEMA_NS}}}alternativeHeadline",
Expand Down
18 changes: 18 additions & 0 deletions tests/manager/feed/test_opds_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,21 @@ def test_serialize_facets_and_sort_links_v1(self):
"{http://palaceproject.io/terms/properties/}default"
not in facet_link.attrib
)

def test_serialize_work_entry_with_subtitle_equals_none(self):
data = WorkEntryData(
subtitle=FeedEntryType(text=None),
)

element = OPDS1Version1Serializer().serialize_work_entry(data)
child = element.findall(f"{{{OPDSFeed.SCHEMA_NS}}}alternativeHeadline")
assert len(child) == 0

data = WorkEntryData(
subtitle=FeedEntryType(text="test"),
)

element = OPDS1Version1Serializer().serialize_work_entry(data)
child = element.findall(f"{{{OPDSFeed.SCHEMA_NS}}}alternativeHeadline")
assert len(child) == 1
assert child[0].text == "test"

0 comments on commit ab87ca8

Please sign in to comment.