forked from mirrors/bookwyrm
Adds inbox test
This commit is contained in:
parent
c08b9e61c4
commit
dedcbda2d8
1 changed files with 41 additions and 0 deletions
|
@ -6,6 +6,7 @@ from unittest.mock import patch
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from bookwyrm import models, views
|
from bookwyrm import models, views
|
||||||
|
from bookwyrm.activitypub.base_activity import set_related_field
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-public-methods
|
# pylint: disable=too-many-public-methods
|
||||||
|
@ -147,6 +148,46 @@ class InboxUpdate(TestCase):
|
||||||
self.assertEqual(book.title, "Piranesi")
|
self.assertEqual(book.title, "Piranesi")
|
||||||
self.assertEqual(book.last_edited_by, self.remote_user)
|
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):
|
def test_update_work(self):
|
||||||
"""update an existing edition"""
|
"""update an existing edition"""
|
||||||
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
|
datafile = pathlib.Path(__file__).parent.joinpath("../../data/bw_work.json")
|
||||||
|
|
Loading…
Reference in a new issue