Test update status via inbox

This commit is contained in:
Mouse Reeve 2021-10-15 08:51:59 -07:00
parent 4002df04fc
commit 20cca69f06
2 changed files with 39 additions and 24 deletions

View file

@ -69,7 +69,8 @@ class Update(Verb):
def action(self):
"""update a model instance from the dataclass"""
if self.object:
if not self.object:
return
self.object.to_model(allow_create=False)

View file

@ -37,9 +37,9 @@ class InboxUpdate(TestCase):
outbox="https://example.com/users/rat/outbox",
)
self.create_json = {
self.update_json = {
"id": "hi",
"type": "Create",
"type": "Update",
"actor": "hi",
"to": ["https://www.w3.org/ns/activitystreams#public"],
"cc": ["https://example.com/user/mouse/followers"],
@ -54,13 +54,8 @@ class InboxUpdate(TestCase):
book_list = models.List.objects.create(
name="hi", remote_id="https://example.com/list/22", user=self.local_user
)
activity = {
"type": "Update",
"to": [],
"cc": [],
"actor": "hi",
"id": "sdkjf",
"object": {
activity = self.update_json
activity["object"] = {
"id": "https://example.com/list/22",
"type": "BookList",
"totalItems": 1,
@ -73,7 +68,6 @@ class InboxUpdate(TestCase):
"summary": "summary text",
"curation": "curated",
"@context": "https://www.w3.org/ns/activitystreams",
},
}
views.inbox.activity_task(activity)
book_list.refresh_from_db()
@ -176,3 +170,23 @@ class InboxUpdate(TestCase):
)
book = models.Work.objects.get(id=book.id)
self.assertEqual(book.title, "Piranesi")
@patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay")
@patch("bookwyrm.activitystreams.add_status_task.delay")
def test_update_status(self, *_):
"""edit a status"""
status = models.Status.objects.create(user=self.remote_user, content="hi")
datafile = pathlib.Path(__file__).parent.joinpath("../../data/ap_note.json")
status_data = json.loads(datafile.read_bytes())
status_data["id"] = status.remote_id
activity = self.update_json
activity["object"] = status_data
with patch("bookwyrm.activitypub.base_activity.set_related_field.delay"):
views.inbox.activity_task(activity)
status.refresh_from_db()
self.assertEqual(status.content, "test content in note")
self.assertTrue(status.edited)