From dedcbda2d808cfa9495760373fdd03a0931b57c2 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 12 Jan 2022 15:40:42 -0800 Subject: [PATCH] Adds inbox test --- .../tests/views/inbox/test_inbox_update.py | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/bookwyrm/tests/views/inbox/test_inbox_update.py b/bookwyrm/tests/views/inbox/test_inbox_update.py index 052b47c4..43b18946 100644 --- a/bookwyrm/tests/views/inbox/test_inbox_update.py +++ b/bookwyrm/tests/views/inbox/test_inbox_update.py @@ -6,6 +6,7 @@ from unittest.mock import patch from django.test import TestCase from bookwyrm import models, views +from bookwyrm.activitypub.base_activity import set_related_field # pylint: disable=too-many-public-methods @@ -147,6 +148,46 @@ class InboxUpdate(TestCase): self.assertEqual(book.title, "Piranesi") self.assertEqual(book.last_edited_by, self.remote_user) + def test_update_edition_links(self): + """add links to edition""" + datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_edition.json") + bookdata = json.loads(datafile.read_bytes()) + del bookdata["authors"] + # pylint: disable=line-too-long + link_data = { + "href": "https://openlibrary.org/books/OL11645413M/Queen_Victoria/daisy", + "mediaType": "Daisy", + "attributedTo": self.remote_user.remote_id + } + bookdata["fileLinks"] = [link_data] + + models.Work.objects.create( + title="Test Work", remote_id="https://bookwyrm.social/book/5988" + ) + book = models.Edition.objects.create( + title="Test Book", remote_id="https://bookwyrm.social/book/5989" + ) + self.assertFalse(book.file_links.exists()) + + with patch("bookwyrm.activitypub.base_activity.set_related_field.delay") as mock: + views.inbox.activity_task( + { + "type": "Update", + "to": [], + "cc": [], + "actor": "hi", + "id": "sdkjf", + "object": bookdata, + } + ) + args = mock.call_args[0] + self.assertEqual(args[0], "FileLink") + self.assertEqual(args[1], "Edition") + self.assertEqual(args[2], "book") + self.assertEqual(args[3], book.remote_id) + self.assertEqual(args[4], link_data) + # idk how to test that related name works, because of the transaction + def test_update_work(self): """update an existing edition""" datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")