kopia lustrzana https://gitlab.com/jaywink/federation
Fix parsing AP Note's with inReplyTo
rodzic
14116923be
commit
471d40f05e
|
@ -28,11 +28,7 @@ def element_to_objects(payload: Dict) -> List:
|
|||
"""
|
||||
entities = []
|
||||
if isinstance(payload.get('object'), dict) and payload["object"].get('type'):
|
||||
if payload["object"].get("inReplyTo"):
|
||||
# TODO this should be comment
|
||||
as2_type = ActivitypubPost
|
||||
else:
|
||||
as2_type = payload["object"]["type"]
|
||||
as2_type = payload["object"]["type"]
|
||||
else:
|
||||
as2_type = payload.get('type')
|
||||
cls = MAPPINGS.get(as2_type)
|
||||
|
|
|
@ -2,11 +2,12 @@ from unittest.mock import patch
|
|||
|
||||
import pytest
|
||||
|
||||
from federation.entities.activitypub.entities import ActivitypubFollow, ActivitypubAccept, ActivitypubProfile
|
||||
from federation.entities.activitypub.entities import (
|
||||
ActivitypubFollow, ActivitypubAccept, ActivitypubProfile, ActivitypubPost)
|
||||
from federation.entities.activitypub.mappers import message_to_objects, get_outbound_entity
|
||||
from federation.entities.base import Accept, Follow, Profile
|
||||
from federation.entities.base import Accept, Follow, Profile, Post
|
||||
from federation.tests.fixtures.payloads import (
|
||||
ACTIVITYPUB_FOLLOW, ACTIVITYPUB_PROFILE, ACTIVITYPUB_PROFILE_INVALID, ACTIVITYPUB_UNDO_FOLLOW)
|
||||
ACTIVITYPUB_FOLLOW, ACTIVITYPUB_PROFILE, ACTIVITYPUB_PROFILE_INVALID, ACTIVITYPUB_UNDO_FOLLOW, ACTIVITYPUB_POST)
|
||||
|
||||
|
||||
class TestActivitypubEntityMappersReceive:
|
||||
|
@ -42,19 +43,17 @@ class TestActivitypubEntityMappersReceive:
|
|||
post = entities[0]
|
||||
assert post._mentions == {'jaywink@jasonrobinson.me'}
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_message_to_objects_simple_post(self):
|
||||
entities = message_to_objects(DIASPORA_POST_SIMPLE, "alice@alice.diaspora.example.org")
|
||||
entities = message_to_objects(ACTIVITYPUB_POST, "https://diaspodon.fr/users/jaywink")
|
||||
assert len(entities) == 1
|
||||
post = entities[0]
|
||||
assert isinstance(post, DiasporaPost)
|
||||
assert isinstance(post, ActivitypubPost)
|
||||
assert isinstance(post, Post)
|
||||
assert post.raw_content == "((status message))"
|
||||
assert post.guid == "((guidguidguidguidguidguidguid))"
|
||||
assert post.handle == "alice@alice.diaspora.example.org"
|
||||
assert post.public == False
|
||||
assert post.created_at == datetime(2011, 7, 20, 1, 36, 7)
|
||||
assert post.provider_display_name == "Socialhome"
|
||||
assert post.raw_content == '<p><span class="h-card"><a href="https://dev.jasonrobinson.me/u/jaywink/" ' \
|
||||
'class="u-url mention">@<span>jaywink</span></a></span> boom</p>'
|
||||
assert post.id == "https://diaspodon.fr/users/jaywink/statuses/102356911717767237"
|
||||
assert post.actor_id == "https://diaspodon.fr/users/jaywink"
|
||||
assert post.public == True
|
||||
|
||||
@pytest.mark.skip
|
||||
def test_message_to_objects_post_with_photos(self):
|
||||
|
|
|
@ -109,3 +109,53 @@ ACTIVITYPUB_UNDO_FOLLOW = {
|
|||
"object": "https://example.org/actor",
|
||||
},
|
||||
}
|
||||
|
||||
ACTIVITYPUB_POST = {
|
||||
'@context': ['https://www.w3.org/ns/activitystreams',
|
||||
{'ostatus': 'http://ostatus.org#',
|
||||
'atomUri': 'ostatus:atomUri',
|
||||
'inReplyToAtomUri': 'ostatus:inReplyToAtomUri',
|
||||
'conversation': 'ostatus:conversation',
|
||||
'sensitive': 'as:sensitive',
|
||||
'Hashtag': 'as:Hashtag',
|
||||
'toot': 'http://joinmastodon.org/ns#',
|
||||
'Emoji': 'toot:Emoji',
|
||||
'focalPoint': {'@container': '@list', '@id': 'toot:focalPoint'},
|
||||
'blurhash': 'toot:blurhash'}],
|
||||
'id': 'https://diaspodon.fr/users/jaywink/statuses/102356911717767237/activity',
|
||||
'type': 'Create',
|
||||
'actor': 'https://diaspodon.fr/users/jaywink',
|
||||
'published': '2019-06-29T21:08:45Z',
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'cc': ['https://diaspodon.fr/users/jaywink/followers',
|
||||
'https://dev.jasonrobinson.me/p/d4574854-a5d7-42be-bfac-f70c16fcaa97/'],
|
||||
'object': {'id': 'https://diaspodon.fr/users/jaywink/statuses/102356911717767237',
|
||||
'type': 'Note',
|
||||
'summary': None,
|
||||
'inReplyTo': 'https://dev.jasonrobinson.me/content/653bad70-41b3-42c9-89cb-c4ee587e68e4/',
|
||||
'published': '2019-06-29T21:08:45Z',
|
||||
'url': 'https://diaspodon.fr/@jaywink/102356911717767237',
|
||||
'attributedTo': 'https://diaspodon.fr/users/jaywink',
|
||||
'to': ['https://www.w3.org/ns/activitystreams#Public'],
|
||||
'cc': ['https://diaspodon.fr/users/jaywink/followers',
|
||||
'https://dev.jasonrobinson.me/p/d4574854-a5d7-42be-bfac-f70c16fcaa97/'],
|
||||
'sensitive': False,
|
||||
'atomUri': 'https://diaspodon.fr/users/jaywink/statuses/102356911717767237',
|
||||
'inReplyToAtomUri': 'https://dev.jasonrobinson.me/content/653bad70-41b3-42c9-89cb-c4ee587e68e4/',
|
||||
'conversation': 'tag:diaspodon.fr,2019-06-28:objectId=2347687:objectType=Conversation',
|
||||
'content': '<p><span class="h-card"><a href="https://dev.jasonrobinson.me/u/jaywink/" class="u-url mention">@<span>jaywink</span></a></span> boom</p>',
|
||||
'contentMap': {'en': '<p><span class="h-card"><a href="https://dev.jasonrobinson.me/u/jaywink/" class="u-url mention">@<span>jaywink</span></a></span> boom</p>'},
|
||||
'attachment': [],
|
||||
'tag': [{'type': 'Mention',
|
||||
'href': 'https://dev.jasonrobinson.me/p/d4574854-a5d7-42be-bfac-f70c16fcaa97/',
|
||||
'name': '@jaywink@dev.jasonrobinson.me'}],
|
||||
'replies': {'id': 'https://diaspodon.fr/users/jaywink/statuses/102356911717767237/replies',
|
||||
'type': 'Collection',
|
||||
'first': {'type': 'CollectionPage',
|
||||
'partOf': 'https://diaspodon.fr/users/jaywink/statuses/102356911717767237/replies',
|
||||
'items': []}}},
|
||||
'signature': {'type': 'RsaSignature2017',
|
||||
'creator': 'https://diaspodon.fr/users/jaywink#main-key',
|
||||
'created': '2019-06-29T21:08:45Z',
|
||||
'signatureValue': 'SjDACS7Z/Cb1SEC3AtxEokID5SHAYl7kpys/hhmaRbpXuFKCxfj2P9BmH8QhLnuam3sENZlrnBOcB5NlcBhIfwo/Xh242RZBmPQf+edTVYVCe1j19dihcftNCHtnqAcKwp/51dNM/OlKu2730FrwvOUXVIPtB7iVqkseO9TRzDYIDj+zBTksnR/NAYtq6SUpmefXfON0uW3N3Uq6PGfExJaS+aeqRf8cPGkZFSIUQZwOLXbIpb7BFjJ1+y1OMOAJueqvikUprAit3v6BiNWurAvSQpC7WWMFUKyA79/xtkO9kIPA/Q4C9ryqdzxZJ0jDhXiaIIQj2JZfIADdjLZHJA=='}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue