mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 10:01:04 +00:00
Adds isbn search test to connector manager
This commit is contained in:
parent
6b22de2075
commit
414dd6bd20
2 changed files with 12 additions and 3 deletions
|
@ -18,7 +18,7 @@ def search(query, min_confidence=0.1):
|
|||
results = []
|
||||
|
||||
# Have we got a ISBN ?
|
||||
isbn = re.sub("[\W_]", "", query)
|
||||
isbn = re.sub(r"[\W_]", "", query)
|
||||
maybe_isbn = len(isbn) in [10, 13] # ISBN10 or ISBN13
|
||||
|
||||
dedup_slug = lambda r: "%s/%s/%s" % (r.title, r.author, r.year)
|
||||
|
@ -36,7 +36,7 @@ def search(query, min_confidence=0.1):
|
|||
pass
|
||||
|
||||
# if no isbn search or results, we fallback to generic search
|
||||
if result_set == None or result_set == []:
|
||||
if result_set in (None, []):
|
||||
try:
|
||||
result_set = connector.search(query, min_confidence=min_confidence)
|
||||
except (HTTPError, ConnectorException):
|
||||
|
|
|
@ -15,7 +15,7 @@ class ConnectorManager(TestCase):
|
|||
self.work = models.Work.objects.create(title="Example Work")
|
||||
|
||||
self.edition = models.Edition.objects.create(
|
||||
title="Example Edition", parent_work=self.work
|
||||
title="Example Edition", parent_work=self.work, isbn_10="0000000000"
|
||||
)
|
||||
self.work.default_edition = self.edition
|
||||
self.work.save()
|
||||
|
@ -28,6 +28,7 @@ class ConnectorManager(TestCase):
|
|||
base_url="http://test.com/",
|
||||
books_url="http://test.com/",
|
||||
covers_url="http://test.com/",
|
||||
isbn_search_url="http://test.com/isbn/",
|
||||
)
|
||||
|
||||
def test_get_or_create_connector(self):
|
||||
|
@ -58,6 +59,14 @@ class ConnectorManager(TestCase):
|
|||
self.assertEqual(len(results[0]["results"]), 1)
|
||||
self.assertEqual(results[0]["results"][0].title, "Example Edition")
|
||||
|
||||
def test_search_isbn(self):
|
||||
""" special handling if a query resembles an isbn """
|
||||
results = connector_manager.search("0000000000")
|
||||
self.assertEqual(len(results), 1)
|
||||
self.assertIsInstance(results[0]["connector"], SelfConnector)
|
||||
self.assertEqual(len(results[0]["results"]), 1)
|
||||
self.assertEqual(results[0]["results"][0].title, "Example Edition")
|
||||
|
||||
def test_local_search(self):
|
||||
""" search only the local database """
|
||||
results = connector_manager.local_search("Example")
|
||||
|
|
Loading…
Reference in a new issue