diff --git a/tests/manager/feed/test_opds2_serializer.py b/tests/manager/feed/test_opds2_serializer.py index bad53e98b..5d112613e 100644 --- a/tests/manager/feed/test_opds2_serializer.py +++ b/tests/manager/feed/test_opds2_serializer.py @@ -234,13 +234,23 @@ def test_serialize_opds_message(self): OPDSMessage("URN", 200, "Description") ) == dict(urn="URN", description="Description") - def test_serialize_v2_sort_links(self): + def test_serialize_v2_feed_links(self): feed_data = FeedData() + + # specify a sort link link = Link(href="test", rel="test_rel", title="text1") link.add_attributes( dict(facetGroup="Sort by", activeFacet="true", defaultFacet="true") ) + + # include a non-sort facet + link2 = Link(href="test2", rel="test_rel", title="text1") + link2.add_attributes( + dict(facetGroup="test_group", activeFacet="false", defaultFacet="false") + ) + feed_data.facet_links.append(link) + feed_data.facet_links.append(link2) links = OPDS2Version2Serializer()._serialize_feed_links(feed=feed_data) assert links == { @@ -255,5 +265,10 @@ def test_serialize_v2_sort_links(self): }, } ], - "facets": [], + "facets": [ + { + "metadata": {"title": "test_group"}, + "links": [{"href": "test2", "rel": "test_rel", "title": "text1"}], + } + ], } diff --git a/tests/manager/feed/test_opds_serializer.py b/tests/manager/feed/test_opds_serializer.py index df5f9409c..685be17ea 100644 --- a/tests/manager/feed/test_opds_serializer.py +++ b/tests/manager/feed/test_opds_serializer.py @@ -268,7 +268,9 @@ def test_serialize_sort_link(self): ) serializer = OPDS1Version2Serializer() assert is_sort_link(link) - sort_link = serializer._serialize_sort_link(link) + sort_links = serializer._serialize_sort_links(list([link])) + assert len(sort_links) == 1 + sort_link = sort_links[0] assert sort_link.attrib["title"] == "text1" assert sort_link.attrib["href"] == "test" assert sort_link.attrib["rel"] == PALACE_REL_SORT @@ -280,3 +282,25 @@ def test_serialize_sort_link(self): sort_link.attrib["{http://palaceproject.io/terms/properties/}default"] == "true" ) + + def test_serialize_non_sort_facetgroup_link(self): + link = Link(href="test", rel="test_rel", title="text1") + link.add_attributes( + dict(facetGroup="non_sort_group", activeFacet="true", defaultFacet="true") + ) + assert not is_sort_link(link) + serializer = OPDS1Version2Serializer() + facet_links = serializer._serialize_facet_links(list([link])) + assert len(facet_links) == 1 + facet_link = facet_links[0] + assert facet_link.attrib["title"] == "text1" + assert facet_link.attrib["href"] == "test" + assert facet_link.attrib["rel"] == "test_rel" + assert ( + facet_link.attrib["{http://opds-spec.org/2010/catalog}activeFacet"] + == "true" + ) + assert ( + facet_link.attrib["{http://palaceproject.io/terms/properties/}default"] + == "true" + )