mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Add test to assert distinct() clause
Also, tweak other `search_title_author()` tests to verify ordering by edition rank.
This commit is contained in:
parent
e322d3cae1
commit
c997d2d44a
1 changed files with 12 additions and 7 deletions
|
@ -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"""
|
||||
|
|
Loading…
Reference in a new issue