diff --git a/bookwyrm/connectors/connector_manager.py b/bookwyrm/connectors/connector_manager.py index 3891d02a..3ed25ceb 100644 --- a/bookwyrm/connectors/connector_manager.py +++ b/bookwyrm/connectors/connector_manager.py @@ -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): diff --git a/bookwyrm/tests/connectors/test_connector_manager.py b/bookwyrm/tests/connectors/test_connector_manager.py index 4410e011..52589323 100644 --- a/bookwyrm/tests/connectors/test_connector_manager.py +++ b/bookwyrm/tests/connectors/test_connector_manager.py @@ -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")