From b6071da3fce4255057d6201336d87130391d49a2 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 7 Dec 2021 13:48:22 -0800 Subject: [PATCH] Connector tests --- .../connectors/test_abstract_connector.py | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/bookwyrm/tests/connectors/test_abstract_connector.py b/bookwyrm/tests/connectors/test_abstract_connector.py index 0b46d607..90e77b79 100644 --- a/bookwyrm/tests/connectors/test_abstract_connector.py +++ b/bookwyrm/tests/connectors/test_abstract_connector.py @@ -40,6 +40,8 @@ class AbstractConnector(TestCase): class TestConnector(abstract_connector.AbstractConnector): """nothing added here""" + generated_remote_link_field = "openlibrary_link" + def format_search_result(self, search_result): return search_result @@ -87,9 +89,7 @@ class AbstractConnector(TestCase): def test_get_or_create_book_existing(self): """find an existing book by remote/origin id""" self.assertEqual(models.Book.objects.count(), 1) - self.assertEqual( - self.book.remote_id, f"https://{DOMAIN}/book/{self.book.id}" - ) + self.assertEqual(self.book.remote_id, f"https://{DOMAIN}/book/{self.book.id}") self.assertEqual(self.book.origin_id, "https://example.com/book/1234") # dedupe by origin id @@ -140,3 +140,26 @@ class AbstractConnector(TestCase): author = models.Author.objects.create(name="Test Author") result = self.connector.get_or_create_author(author.remote_id) self.assertEqual(author, result) + + @responses.activate + def test_update_author_from_remote(self): + """trigger the function that looks up the remote data""" + author = models.Author.objects.create(name="Test", openlibrary_key="OL123A") + # pylint: disable=attribute-defined-outside-init + self.connector.author_mappings = [ + Mapping("id"), + Mapping("name"), + Mapping("isni"), + ] + + responses.add( + responses.GET, + "https://openlibrary.org/authors/OL123A", + json={"id": "https://www.example.com/author", "name": "Beep", "isni": "hi"}, + ) + + self.connector.update_author_from_remote(author) + + author.refresh_from_db() + self.assertEqual(author.name, "Test") + self.assertEqual(author.isni, "hi")