From 79aea1b8ba534698397e1985f663b078a7ba9832 Mon Sep 17 00:00:00 2001 From: Humberto Rocha Date: Sat, 18 Feb 2023 12:38:31 -0500 Subject: [PATCH] Add support to update Poll by AP (#514) --- tests/activities/models/test_post.py | 40 ++++++++++++++++++++++++++++ users/models/inbox_message.py | 2 +- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/tests/activities/models/test_post.py b/tests/activities/models/test_post.py index 6ebc766..aec40d9 100644 --- a/tests/activities/models/test_post.py +++ b/tests/activities/models/test_post.py @@ -293,6 +293,46 @@ def test_content_map_question(remote_identity: Identity): ) assert post.content == "Test Question" assert isinstance(post.type_data, QuestionData) + assert post.type_data.voter_count == 10 + + # test the update case + question_id = post.id + + post = Post.by_ap( + data={ + "id": "https://remote.test/posts/1/", + "type": "Question", + "votersCount": 100, + "closed": "2023-01-01T26:04:45Z", + "content": "Test Question", + "attributedTo": "https://remote.test/test-actor/", + "published": "2022-12-23T10:50:54Z", + "endTime": "2023-01-01T20:04:45Z", + "oneOf": [ + { + "type": "Note", + "name": "Option 1", + "replies": { + "type": "Collection", + "totalItems": 60, + }, + }, + { + "type": "Note", + "name": "Option 2", + "replies": { + "type": "Collection", + "totalItems": 40, + }, + }, + ], + }, + create=False, + update=True, + ) + assert isinstance(post.type_data, QuestionData) + assert post.type_data.voter_count == 100 + assert post.id == question_id @pytest.mark.django_db diff --git a/users/models/inbox_message.py b/users/models/inbox_message.py index 4119aab..87d0bb2 100644 --- a/users/models/inbox_message.py +++ b/users/models/inbox_message.py @@ -61,7 +61,7 @@ class InboxMessageStates(StateGraph): case "application": await sync_to_async(Identity.handle_update_ap)(instance.message) case "question": - pass # Drop for now + await sync_to_async(Post.handle_update_ap)(instance.message) case unknown: if unknown in Post.Types.names: await sync_to_async(Post.handle_update_ap)(instance.message)