From 382170d662d71fdd896a889e48d5faecf4d3426f Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 13 Mar 2021 09:27:59 -0800 Subject: [PATCH] Adds get_or_create_author abstract connector test --- .../connectors/test_abstract_connector.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/bookwyrm/tests/connectors/test_abstract_connector.py b/bookwyrm/tests/connectors/test_abstract_connector.py index 9aa78f6a..97190c16 100644 --- a/bookwyrm/tests/connectors/test_abstract_connector.py +++ b/bookwyrm/tests/connectors/test_abstract_connector.py @@ -122,3 +122,27 @@ class AbstractConnector(TestCase): self.assertEqual(result, self.book) self.assertEqual(models.Edition.objects.count(), 1) self.assertEqual(models.Edition.objects.count(), 1) + + @responses.activate + def test_get_or_create_author(self): + """ load an author """ + self.connector.author_mappings = [ + Mapping("id"), + Mapping("name"), + ] + + responses.add( + responses.GET, + "https://www.example.com/author", + json={"id": "https://www.example.com/author", "name": "Test Author"}, + ) + result = self.connector.get_or_create_author("https://www.example.com/author") + self.assertIsInstance(result, models.Author) + self.assertEqual(result.name, "Test Author") + self.assertEqual(result.origin_id, "https://www.example.com/author") + + def test_get_or_create_author_existing(self): + """ get an existing author """ + author = models.Author.objects.create(name="Test Author") + result = self.connector.get_or_create_author(author.remote_id) + self.assertEqual(author, result)