From e995ab20740e05187703bee9222d17526dd05005 Mon Sep 17 00:00:00 2001 From: dbernstein Date: Mon, 13 Jan 2025 07:07:11 -0800 Subject: [PATCH] [PP-2043] Prevent None from displaying when there are no subtitles. (#2243) --- src/palace/manager/feed/serializer/opds.py | 3 ++- tests/manager/feed/test_opds_serializer.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/palace/manager/feed/serializer/opds.py b/src/palace/manager/feed/serializer/opds.py index 8a8573d37..a4363cd57 100644 --- a/src/palace/manager/feed/serializer/opds.py +++ b/src/palace/manager/feed/serializer/opds.py @@ -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", diff --git a/tests/manager/feed/test_opds_serializer.py b/tests/manager/feed/test_opds_serializer.py index 5c1a4fa8b..14d75c69a 100644 --- a/tests/manager/feed/test_opds_serializer.py +++ b/tests/manager/feed/test_opds_serializer.py @@ -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"