From 76f16432698c4c4067d834ea82b9dfb7be4ef729 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 10:11:13 -0800 Subject: [PATCH] Tests ignore edition openlibrary connector code also removes print statements oops --- bookwyrm/connectors/openlibrary.py | 4 ---- .../tests/connectors/test_openlibrary_connector.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/bookwyrm/connectors/openlibrary.py b/bookwyrm/connectors/openlibrary.py index fb9a4e47..c83a65d6 100644 --- a/bookwyrm/connectors/openlibrary.py +++ b/bookwyrm/connectors/openlibrary.py @@ -161,21 +161,17 @@ def ignore_edition(edition_data): """ don't load a million editions that have no metadata """ # an isbn, we love to see it if edition_data.get("isbn_13") or edition_data.get("isbn_10"): - print(edition_data.get("isbn_10")) return False # grudgingly, oclc can stay if edition_data.get("oclc_numbers"): - print(edition_data.get("oclc_numbers")) return False # if it has a cover it can stay if edition_data.get("covers"): - print(edition_data.get("covers")) return False # keep non-english editions if edition_data.get("languages") and "languages/eng" not in str( edition_data.get("languages") ): - print(edition_data.get("languages")) return False return True diff --git a/bookwyrm/tests/connectors/test_openlibrary_connector.py b/bookwyrm/tests/connectors/test_openlibrary_connector.py index bb018830..3cff4fb0 100644 --- a/bookwyrm/tests/connectors/test_openlibrary_connector.py +++ b/bookwyrm/tests/connectors/test_openlibrary_connector.py @@ -8,6 +8,7 @@ import responses from bookwyrm import models from bookwyrm.connectors.openlibrary import Connector +from bookwyrm.connectors.openlibrary import ignore_edition from bookwyrm.connectors.openlibrary import get_languages, get_description from bookwyrm.connectors.openlibrary import pick_default_edition, get_openlibrary_key from bookwyrm.connectors.abstract_connector import SearchResult @@ -237,3 +238,12 @@ class Openlibrary(TestCase): self.assertEqual(result.pages, 491) self.assertEqual(result.subjects[0], "Fantasy.") self.assertEqual(result.physical_format, "Hardcover") + + def test_ignore_edition(self): + """ skip editions with poor metadata """ + self.assertFalse(ignore_edition({"isbn_13": "hi"})) + self.assertFalse(ignore_edition({"oclc_numbers": "hi"})) + self.assertFalse(ignore_edition({"covers": "hi"})) + self.assertFalse(ignore_edition({"languages": "languages/fr"})) + self.assertTrue(ignore_edition({"languages": "languages/eng"})) + self.assertTrue(ignore_edition({"format": "paperback"}))