mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-17 21:56:36 +00:00
Test update status via inbox
This commit is contained in:
parent
4002df04fc
commit
20cca69f06
2 changed files with 39 additions and 24 deletions
|
@ -69,7 +69,8 @@ class Update(Verb):
|
||||||
|
|
||||||
def action(self):
|
def action(self):
|
||||||
"""update a model instance from the dataclass"""
|
"""update a model instance from the dataclass"""
|
||||||
if self.object:
|
if not self.object:
|
||||||
|
return
|
||||||
self.object.to_model(allow_create=False)
|
self.object.to_model(allow_create=False)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -37,9 +37,9 @@ class InboxUpdate(TestCase):
|
||||||
outbox="https://example.com/users/rat/outbox",
|
outbox="https://example.com/users/rat/outbox",
|
||||||
)
|
)
|
||||||
|
|
||||||
self.create_json = {
|
self.update_json = {
|
||||||
"id": "hi",
|
"id": "hi",
|
||||||
"type": "Create",
|
"type": "Update",
|
||||||
"actor": "hi",
|
"actor": "hi",
|
||||||
"to": ["https://www.w3.org/ns/activitystreams#public"],
|
"to": ["https://www.w3.org/ns/activitystreams#public"],
|
||||||
"cc": ["https://example.com/user/mouse/followers"],
|
"cc": ["https://example.com/user/mouse/followers"],
|
||||||
|
@ -54,13 +54,8 @@ class InboxUpdate(TestCase):
|
||||||
book_list = models.List.objects.create(
|
book_list = models.List.objects.create(
|
||||||
name="hi", remote_id="https://example.com/list/22", user=self.local_user
|
name="hi", remote_id="https://example.com/list/22", user=self.local_user
|
||||||
)
|
)
|
||||||
activity = {
|
activity = self.update_json
|
||||||
"type": "Update",
|
activity["object"] = {
|
||||||
"to": [],
|
|
||||||
"cc": [],
|
|
||||||
"actor": "hi",
|
|
||||||
"id": "sdkjf",
|
|
||||||
"object": {
|
|
||||||
"id": "https://example.com/list/22",
|
"id": "https://example.com/list/22",
|
||||||
"type": "BookList",
|
"type": "BookList",
|
||||||
"totalItems": 1,
|
"totalItems": 1,
|
||||||
|
@ -73,7 +68,6 @@ class InboxUpdate(TestCase):
|
||||||
"summary": "summary text",
|
"summary": "summary text",
|
||||||
"curation": "curated",
|
"curation": "curated",
|
||||||
"@context": "https://www.w3.org/ns/activitystreams",
|
"@context": "https://www.w3.org/ns/activitystreams",
|
||||||
},
|
|
||||||
}
|
}
|
||||||
views.inbox.activity_task(activity)
|
views.inbox.activity_task(activity)
|
||||||
book_list.refresh_from_db()
|
book_list.refresh_from_db()
|
||||||
|
@ -176,3 +170,23 @@ class InboxUpdate(TestCase):
|
||||||
)
|
)
|
||||||
book = models.Work.objects.get(id=book.id)
|
book = models.Work.objects.get(id=book.id)
|
||||||
self.assertEqual(book.title, "Piranesi")
|
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)
|
||||||
|
|
Loading…
Reference in a new issue