From 98ed03b6b45701d526b48add7931121683723169 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Mon, 30 May 2022 17:00:34 -0700 Subject: [PATCH] Python formatting and test update --- bookwyrm/connectors/connector_manager.py | 4 +++- .../connectors/test_bookwyrm_connector.py | 2 +- .../connectors/test_inventaire_connector.py | 2 +- .../connectors/test_openlibrary_connector.py | 24 +++---------------- 4 files changed, 8 insertions(+), 24 deletions(-) diff --git a/bookwyrm/connectors/connector_manager.py b/bookwyrm/connectors/connector_manager.py index 0488421e..fc784924 100644 --- a/bookwyrm/connectors/connector_manager.py +++ b/bookwyrm/connectors/connector_manager.py @@ -46,7 +46,9 @@ async def get_results(session, url, min_confidence, query, connector): return { "connector": connector, - "results": connector.process_search_response(query, raw_data, min_confidence), + "results": connector.process_search_response( + query, raw_data, min_confidence + ), } except asyncio.TimeoutError: logger.info("Connection timed out for url: %s", url) diff --git a/bookwyrm/tests/connectors/test_bookwyrm_connector.py b/bookwyrm/tests/connectors/test_bookwyrm_connector.py index b9642a50..1e369ca0 100644 --- a/bookwyrm/tests/connectors/test_bookwyrm_connector.py +++ b/bookwyrm/tests/connectors/test_bookwyrm_connector.py @@ -34,7 +34,7 @@ class BookWyrmConnector(TestCase): """create a SearchResult object from search response json""" datafile = pathlib.Path(__file__).parent.joinpath("../data/bw_search.json") search_data = json.loads(datafile.read_bytes()) - result = list(self.connector.parse_search_data(search_data))[0] + result = list(self.connector.parse_search_data(search_data, 0))[0] self.assertIsInstance(result, SearchResult) self.assertEqual(result.title, "Jonathan Strange and Mr Norrell") self.assertEqual(result.key, "https://example.com/book/122") diff --git a/bookwyrm/tests/connectors/test_inventaire_connector.py b/bookwyrm/tests/connectors/test_inventaire_connector.py index 7b526f22..3bba9ece 100644 --- a/bookwyrm/tests/connectors/test_inventaire_connector.py +++ b/bookwyrm/tests/connectors/test_inventaire_connector.py @@ -73,7 +73,7 @@ class Inventaire(TestCase): ) search_results = json.loads(search_file.read_bytes()) - formatted = list(self.connector.parse_search_data(search_results))[0] + formatted = list(self.connector.parse_search_data(search_results, 0))[0] self.assertEqual(formatted.title, "The Stories of Vladimir Nabokov") self.assertEqual( diff --git a/bookwyrm/tests/connectors/test_openlibrary_connector.py b/bookwyrm/tests/connectors/test_openlibrary_connector.py index c05eb1a9..69e4f847 100644 --- a/bookwyrm/tests/connectors/test_openlibrary_connector.py +++ b/bookwyrm/tests/connectors/test_openlibrary_connector.py @@ -122,21 +122,11 @@ class Openlibrary(TestCase): self.assertEqual(result, "https://covers.openlibrary.org/b/id/image-L.jpg") def test_parse_search_result(self): - """extract the results from the search json response""" - datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_search.json") - search_data = json.loads(datafile.read_bytes()) - result = self.connector.parse_search_data(search_data) - self.assertIsInstance(result, list) - self.assertEqual(len(result), 2) - - def test_format_search_result(self): """translate json from openlibrary into SearchResult""" datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_search.json") search_data = json.loads(datafile.read_bytes()) - results = self.connector.parse_search_data(search_data) - self.assertIsInstance(results, list) + result = list(self.connector.parse_search_data(search_data, 0))[0] - result = self.connector.format_search_result(results[0]) self.assertIsInstance(result, SearchResult) self.assertEqual(result.title, "This Is How You Lose the Time War") self.assertEqual(result.key, "https://openlibrary.org/works/OL20639540W") @@ -148,18 +138,10 @@ class Openlibrary(TestCase): """extract the results from the search json response""" datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_isbn_search.json") search_data = json.loads(datafile.read_bytes()) - result = self.connector.parse_isbn_search_data(search_data) - self.assertIsInstance(result, list) + result = list(self.connector.parse_isbn_search_data(search_data)) self.assertEqual(len(result), 1) - def test_format_isbn_search_result(self): - """translate json from openlibrary into SearchResult""" - datafile = pathlib.Path(__file__).parent.joinpath("../data/ol_isbn_search.json") - search_data = json.loads(datafile.read_bytes()) - results = self.connector.parse_isbn_search_data(search_data) - self.assertIsInstance(results, list) - - result = self.connector.format_isbn_search_result(results[0]) + result = result[0] self.assertIsInstance(result, SearchResult) self.assertEqual(result.title, "Les ombres errantes") self.assertEqual(result.key, "https://openlibrary.org/books/OL16262504M")