test_quotation_page_serialization: add test with no position

This commit is contained in:
Adeodato Simó 2024-04-08 16:15:50 -03:00
parent df78cc64a6
commit 8733369605
No known key found for this signature in database
GPG key ID: 98EF291323013F6E
2 changed files with 7 additions and 5 deletions

View file

@ -392,7 +392,7 @@ class Quotation(BookStatus):
def _format_position(self) -> Optional[str]: def _format_position(self) -> Optional[str]:
"""serialize page position""" """serialize page position"""
beg = self.position beg = self.position
end = self.endposition or 0 end = self.endposition
if self.position_mode != "PG" or not beg: if self.position_mode != "PG" or not beg:
return None return None
return f"pp. {beg}-{end}" if end else f"p. {beg}" return f"pp. {beg}-{end}" if end else f"p. {beg}"

View file

@ -341,6 +341,7 @@ class Status(TestCase):
"""serialization of quotation page position""" """serialization of quotation page position"""
tests = [ tests = [
("single pos", "7", "", "p. 7"), ("single pos", "7", "", "p. 7"),
("missing beg", "", "10", None),
("page range", "7", "10", "pp. 7-10"), ("page range", "7", "10", "pp. 7-10"),
("page range roman", "xv", "xvi", "pp. xv-xvi"), ("page range roman", "xv", "xvi", "pp. xv-xvi"),
("page range reverse", "14", "10", "pp. 14-10"), ("page range reverse", "14", "10", "pp. 14-10"),
@ -357,10 +358,11 @@ class Status(TestCase):
position_mode="PG", position_mode="PG",
) )
activity = status.to_activity(pure=True) activity = status.to_activity(pure=True)
self.assertRegex( if pages:
activity["content"], expect_re = f'^<p>"my quote"</p> <p>— <a .+</a>, {pages}</p>$'
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, *_): def test_review_to_activity(self, *_):
"""subclass of the base model version with a "pure" serializer""" """subclass of the base model version with a "pure" serializer"""