Add test to assert distinct() clause

Also, tweak other `search_title_author()` tests to verify ordering by
edition rank.
This commit is contained in:
Adeodato Simó 2023-11-24 02:18:18 -03:00
parent e322d3cae1
commit c997d2d44a
No known key found for this signature in database
GPG key ID: CDF447845F1A986F

View file

@ -26,10 +26,10 @@ class BookSearch(TestCase):
parent_work=self.work,
isbn_10="1111111111",
openlibrary_key="hello",
pages=150,
)
self.third_edition = models.Edition.objects.create(
title="Edition with annoying ISBN",
title="Another Edition with annoying ISBN",
parent_work=self.work,
isbn_10="022222222X",
)
@ -76,16 +76,21 @@ class BookSearch(TestCase):
def test_search_title_author(self):
"""search by unique identifiers"""
results = book_search.search_title_author("Another", min_confidence=0)
results = book_search.search_title_author("annoying", min_confidence=0)
self.assertEqual(len(results), 1)
self.assertEqual(results[0], self.second_edition)
self.assertEqual(results[0], self.third_edition)
def test_search_title_author_return_first(self):
"""search by unique identifiers"""
results = book_search.search_title_author(
"""sorts by edition rank"""
result = book_search.search_title_author(
"Another", min_confidence=0, return_first=True
)
self.assertEqual(results, self.second_edition)
self.assertEqual(result, self.second_edition) # highest edition rank
def test_search_title_author_one_edition_per_work(self):
"""at most one edition per work"""
results = book_search.search_title_author("Edition", 0)
self.assertEqual(results, [self.first_edition]) # highest edition rank
def test_format_search_result(self):
"""format a search result"""