Skip to content

Commit

Permalink
test_quotation_page_serialization: add test with no position
Browse files Browse the repository at this point in the history
  • Loading branch information
dato committed Apr 8, 2024
1 parent 48beee6 commit a6296dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion bookwyrm/models/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ class Quotation(BookStatus):
def _format_position(self) -> Optional[str]:
"""serialize page position"""
beg = self.position
end = self.endposition or 0
end = self.endposition
if self.position_mode != "PG" or not beg:
return None
return f"pp. {beg}-{end}" if end else f"p. {beg}"
Expand Down
10 changes: 6 additions & 4 deletions bookwyrm/tests/models/test_status_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ def test_quotation_page_serialization(self, *_):
"""serialization of quotation page position"""
tests = [
("single pos", "7", "", "p. 7"),
("missing beg", "", "10", None),
("page range", "7", "10", "pp. 7-10"),
("page range roman", "xv", "xvi", "pp. xv-xvi"),
("page range reverse", "14", "10", "pp. 14-10"),
Expand All @@ -357,10 +358,11 @@ def test_quotation_page_serialization(self, *_):
position_mode="PG",
)
activity = status.to_activity(pure=True)
self.assertRegex(
activity["content"],
f'^<p>"my quote"</p> <p>— <a .+</a>, {pages}</p>$',
)
if pages:
expect_re = f'^<p>"my quote"</p> <p>— <a .+</a>, {pages}</p>$'
else:
expect_re = '^<p>"my quote"</p> <p>— <a .+</a></p>$'
self.assertRegex(activity["content"], expect_re)

def test_review_to_activity(self, *_):
"""subclass of the base model version with a "pure" serializer"""
Expand Down

0 comments on commit a6296dc

Please sign in to comment.