Skip to content

Commit

Permalink
Fix more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Oct 29, 2024
1 parent 81b6e14 commit 768e3a0
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
19 changes: 17 additions & 2 deletions tests/manager/feed/test_opds2_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == {
Expand All @@ -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"}],
}
],
}
26 changes: 25 additions & 1 deletion tests/manager/feed/test_opds_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
)

0 comments on commit 768e3a0

Please sign in to comment.