コード例 #1
0
 def test_message_to_objects_post_with_photos(self):
     entities = message_to_objects(DIASPORA_POST_WITH_PHOTOS)
     assert len(entities) == 1
     post = entities[0]
     assert isinstance(post, DiasporaPost)
     photo = post._children[0]
     assert isinstance(photo, Image)
     assert photo.remote_path == "https://alice.diaspora.example.org/uploads/images/"
     assert photo.remote_name == "1234.jpg"
     assert photo.raw_content == None
     assert photo.linked_type == "Post"
     assert photo.linked_guid == "((guidguidguidguidguidguidguid))"
     assert photo.height == 120
     assert photo.width == 120
     assert photo.guid == "((guidguidguidguidguidguidguif))"
     assert photo.handle == "*****@*****.**"
     assert photo.public == False
     assert photo.created_at == datetime(2011, 7, 20, 1, 36, 7)
     photo = post._children[1]
     assert isinstance(photo, Image)
     assert photo.remote_path == "https://alice.diaspora.example.org/uploads/images/"
     assert photo.remote_name == "12345.jpg"
     assert photo.raw_content == "foobar"
     assert photo.linked_type == "Post"
     assert photo.linked_guid == "((guidguidguidguidguidguidguid))"
     assert photo.height == 120
     assert photo.width == 120
     assert photo.guid == "((guidguidguidguidguidguidguig))"
     assert photo.handle == "*****@*****.**"
     assert photo.public == False
     assert photo.created_at == datetime(2011, 7, 20, 1, 36, 7)
コード例 #2
0
ファイル: test_mappers.py プロジェクト: AdJadeHash/federation
 def test_source_object(self, mock_validate):
     entities = message_to_objects(DIASPORA_POST_COMMENT,
                                   "*****@*****.**",
                                   sender_key_fetcher=Mock())
     entity = entities[0]
     assert entity._source_object == etree.tostring(
         etree.fromstring(DIASPORA_POST_COMMENT))
コード例 #3
0
 def test_message_to_objects_retraction(self):
     entities = message_to_objects(DIASPORA_RETRACTION, "*****@*****.**")
     assert len(entities) == 1
     entity = entities[0]
     assert isinstance(entity, Retraction)
     assert entity.handle == "*****@*****.**"
     assert entity.target_guid == "x" * 16
     assert entity.entity_type == "Post"
コード例 #4
0
 def test_message_to_objects_reshare_extra_properties(self):
     entities = message_to_objects(DIASPORA_RESHARE_WITH_EXTRA_PROPERTIES,
                                   "*****@*****.**")
     assert len(entities) == 1
     entity = entities[0]
     assert isinstance(entity, DiasporaReshare)
     assert entity.raw_content == "Important note here"
     assert entity.entity_type == "Comment"
コード例 #5
0
 def test_message_to_objects_retraction(self):
     entities = message_to_objects(DIASPORA_RETRACTION)
     assert len(entities) == 1
     entity = entities[0]
     assert isinstance(entity, Retraction)
     assert entity.handle == "*****@*****.**"
     assert entity.target_guid == "x" * 16
     assert entity.entity_type == "Post"
コード例 #6
0
 def test_message_to_objects_contact(self):
     entities = message_to_objects(DIASPORA_CONTACT, "*****@*****.**")
     assert len(entities) == 1
     entity = entities[0]
     assert isinstance(entity, DiasporaContact)
     assert entity.handle == "*****@*****.**"
     assert entity.target_handle == "*****@*****.**"
     assert entity.following is True
コード例 #7
0
ファイル: test_mappers.py プロジェクト: trusttri/federation
 def test_message_to_objects_post__with_activitypub_id(self):
     entities = message_to_objects(DIASPORA_POST_ACTIVITYPUB_ID,
                                   "*****@*****.**")
     assert len(entities) == 1
     post = entities[0]
     assert isinstance(post, DiasporaPost)
     assert isinstance(post, Post)
     assert post.guid == "((guidguidguidguidguidguidguid))"
     assert post.handle == "*****@*****.**"
     assert post.id == "https://alice.diaspora.example.org/posts/1"
コード例 #8
0
ファイル: test_mappers.py プロジェクト: trusttri/federation
 def test_message_to_objects_receivers_are_saved__single_receiver(self):
     # noinspection PyTypeChecker
     entities = message_to_objects(DIASPORA_POST_SIMPLE,
                                   "*****@*****.**",
                                   user=Mock(id="*****@*****.**"))
     entity = entities[0]
     assert entity._receivers == [
         UserType(id="*****@*****.**",
                  receiver_variant=ReceiverVariant.ACTOR)
     ]
コード例 #9
0
 def test_message_to_objects_simple_post(self):
     entities = message_to_objects(DIASPORA_POST_SIMPLE)
     assert len(entities) == 1
     post = entities[0]
     assert isinstance(post, Post)
     assert post.raw_content == "((status message))"
     assert post.guid == "((guid))"
     assert post.handle == "*****@*****.**"
     assert post.public == False
     assert post.created_at == datetime(2011, 7, 20, 1, 36, 7)
コード例 #10
0
 def test_message_to_objects_retraction_legacy_request(self):
     entities = message_to_objects(DIASPORA_LEGACY_REQUEST_RETRACTION, "*****@*****.**",
                                   user=Mock(guid="swfeuihiwehuifhiwheiuf"))
     assert len(entities) == 1
     entity = entities[0]
     assert isinstance(entity, Retraction)
     assert entity.handle == "*****@*****.**"
     assert entity.target_guid == "7ed1555bc6ae03db"
     assert entity.entity_type == "Profile"
     assert entity._receiving_guid == "swfeuihiwehuifhiwheiuf"
コード例 #11
0
 def test_message_to_objects_comment(self):
     entities = message_to_objects(DIASPORA_POST_COMMENT)
     assert len(entities) == 1
     comment = entities[0]
     assert isinstance(comment, DiasporaComment)
     assert isinstance(comment, Comment)
     assert comment.target_guid == "((parent_guidparent_guidparent_guidparent_guid))"
     assert comment.guid == "((guidguidguidguidguidguid))"
     assert comment.handle == "*****@*****.**"
     assert comment.participation == "comment"
     assert comment.raw_content == "((text))"
コード例 #12
0
 def test_message_to_objects_comment(self):
     entities = message_to_objects(DIASPORA_POST_COMMENT)
     assert len(entities) == 1
     comment = entities[0]
     assert isinstance(comment, DiasporaComment)
     assert isinstance(comment, Comment)
     assert comment.target_guid == "((parent_guid))"
     assert comment.guid == "((guid))"
     assert comment.handle == "*****@*****.**"
     assert comment.participation == "comment"
     assert comment.raw_content == "((text))"
コード例 #13
0
 def test_message_to_objects_like(self):
     entities = message_to_objects(DIASPORA_POST_LIKE)
     assert len(entities) == 1
     like = entities[0]
     assert isinstance(like, DiasporaLike)
     assert isinstance(like, Reaction)
     assert like.target_guid == "((parent_guid))"
     assert like.guid == "((guid))"
     assert like.handle == "*****@*****.**"
     assert like.participation == "reaction"
     assert like.reaction == "like"
コード例 #14
0
 def test_message_to_objects_like(self):
     entities = message_to_objects(DIASPORA_POST_LIKE)
     assert len(entities) == 1
     like = entities[0]
     assert isinstance(like, DiasporaLike)
     assert isinstance(like, Reaction)
     assert like.target_guid == "((parent_guidparent_guidparent_guidparent_guid))"
     assert like.guid == "((guidguidguidguidguidguid))"
     assert like.handle == "*****@*****.**"
     assert like.participation == "reaction"
     assert like.reaction == "like"
コード例 #15
0
 def test_message_to_objects_reshare_legacy(self):
     entities = message_to_objects(DIASPORA_RESHARE_LEGACY, "*****@*****.**")
     assert len(entities) == 1
     entity = entities[0]
     assert isinstance(entity, DiasporaReshare)
     assert entity.handle == "*****@*****.**"
     assert entity.guid == "a0b53e5029f6013487753131731751e9"
     assert entity.provider_display_name == ""
     assert entity.target_handle == "*****@*****.**"
     assert entity.target_guid == "a0b53bc029f6013487753131731751e9"
     assert entity.public is False
     assert entity.entity_type == "Post"
コード例 #16
0
 def test_message_to_objects_simple_post(self):
     entities = message_to_objects(DIASPORA_POST_SIMPLE, "*****@*****.**")
     assert len(entities) == 1
     post = entities[0]
     assert isinstance(post, DiasporaPost)
     assert isinstance(post, Post)
     assert post.raw_content == "((status message))"
     assert post.guid == "((guidguidguidguidguidguidguid))"
     assert post.handle == "*****@*****.**"
     assert post.public == False
     assert post.created_at == datetime(2011, 7, 20, 1, 36, 7)
     assert post.provider_display_name == "Socialhome"
コード例 #17
0
ファイル: test_mappers.py プロジェクト: trusttri/federation
 def test_message_to_objects_receivers_are_saved__followers_receiver(self):
     # noinspection PyTypeChecker
     entities = message_to_objects(
         DIASPORA_POST_SIMPLE,
         "*****@*****.**",
     )
     entity = entities[0]
     assert entity._receivers == [
         UserType(
             id="*****@*****.**",
             receiver_variant=ReceiverVariant.FOLLOWERS,
         )
     ]
コード例 #18
0
 def test_message_to_objects_post_legacy(self):
     # This is the previous XML schema used before renewal of protocol
     entities = message_to_objects(DIASPORA_POST_LEGACY, "*****@*****.**")
     assert len(entities) == 1
     post = entities[0]
     assert isinstance(post, DiasporaPost)
     assert isinstance(post, Post)
     assert post.raw_content == "((status message))"
     assert post.guid == "((guidguidguidguidguidguidguid))"
     assert post.handle == "*****@*****.**"
     assert post.public is False
     assert post.created_at == datetime(2011, 7, 20, 1, 36, 7)
     assert post.provider_display_name == "Socialhome"
コード例 #19
0
ファイル: test_mappers.py プロジェクト: trusttri/federation
 def test_message_to_objects_comment__activitypub_id(self, mock_validate):
     entities = message_to_objects(DIASPORA_POST_COMMENT_ACTIVITYPUB_ID,
                                   "*****@*****.**",
                                   sender_key_fetcher=Mock())
     assert len(entities) == 1
     comment = entities[0]
     assert isinstance(comment, DiasporaComment)
     assert isinstance(comment, Comment)
     assert comment.target_guid == "((parent_guidparent_guidparent_guidparent_guid))"
     assert comment.root_target_guid == ""
     assert comment.guid == "((guidguidguidguidguidguid))"
     assert comment.handle == "*****@*****.**"
     assert comment.id == "https://alice.diaspora.example.org/comments/1"
     mock_validate.assert_called_once_with()
コード例 #20
0
 def test_message_to_objects_request(self):
     entities = message_to_objects(DIASPORA_REQUEST)
     assert len(entities) == 2
     sharing = entities[0]
     assert isinstance(sharing, DiasporaRequest)
     assert isinstance(sharing, Relationship)
     following = entities[1]
     assert not isinstance(following, DiasporaRequest)
     assert isinstance(following, Relationship)
     assert sharing.handle == "*****@*****.**"
     assert following.handle == "*****@*****.**"
     assert sharing.target_handle == "*****@*****.**"
     assert following.target_handle == "*****@*****.**"
     assert sharing.relationship == "sharing"
     assert following.relationship == "following"
コード例 #21
0
 def test_message_to_objects_request(self):
     entities = message_to_objects(DIASPORA_REQUEST, "*****@*****.**")
     assert len(entities) == 2
     sharing = entities[0]
     assert isinstance(sharing, DiasporaRequest)
     assert isinstance(sharing, Relationship)
     following = entities[1]
     assert not isinstance(following, DiasporaRequest)
     assert isinstance(following, Relationship)
     assert sharing.handle == "*****@*****.**"
     assert following.handle == "*****@*****.**"
     assert sharing.target_handle == "*****@*****.**"
     assert following.target_handle == "*****@*****.**"
     assert sharing.relationship == "sharing"
     assert following.relationship == "following"
コード例 #22
0
ファイル: test_mappers.py プロジェクト: trusttri/federation
 def test_message_to_objects_post_with_photos(self):
     entities = message_to_objects(DIASPORA_POST_WITH_PHOTOS,
                                   "*****@*****.**")
     assert len(entities) == 1
     post = entities[0]
     assert isinstance(post, DiasporaPost)
     photo = post._children[0]
     assert isinstance(photo, DiasporaImage)
     assert photo.url == "https://alice.diaspora.example.org/uploads/images/1234.jpg"
     assert photo.name == ""
     assert photo.raw_content == ""
     assert photo.height == 120
     assert photo.width == 120
     assert photo.guid == "((guidguidguidguidguidguidguif))"
     assert photo.handle == "*****@*****.**"
     assert photo.created_at == datetime(2011, 7, 20, 1, 36, 7)
コード例 #23
0
 def test_message_to_objects_like(self, mock_validate):
     entities = message_to_objects(DIASPORA_POST_LIKE, "*****@*****.**", sender_key_fetcher=Mock())
     assert len(entities) == 1
     like = entities[0]
     assert isinstance(like, DiasporaLike)
     assert isinstance(like, Reaction)
     assert like.target_guid == "((parent_guidparent_guidparent_guidparent_guid))"
     assert like.guid == "((guidguidguidguidguidguid))"
     assert like.handle == "*****@*****.**"
     assert like.participation == "reaction"
     assert like.reaction == "like"
     assert like.signature == "((signature))"
     assert like._xml_tags == [
         "parent_type", "guid", "parent_guid", "positive", "author",
     ]
     mock_validate.assert_called_once_with()
コード例 #24
0
 def test_message_to_objects_profile(self):
     entities = message_to_objects(DIASPORA_PROFILE)
     assert len(entities) == 1
     profile = entities[0]
     assert profile.handle == "*****@*****.**"
     assert profile.name == "Bob Bobertson"
     assert profile.image_urls == {
         "large": "https://example.com/uploads/images/thumb_large_c833747578b5.jpg",
         "medium": "https://example.com/uploads/images/thumb_medium_c8b1aab04f3.jpg",
         "small": "https://example.com/uploads/images/thumb_small_c8b147578b5.jpg",
     }
     assert profile.gender == ""
     assert profile.raw_content == "A cool bio"
     assert profile.location == "Helsinki"
     assert profile.public == True
     assert profile.nsfw == False
     assert profile.tag_list == ["socialfederation", "federation"]
コード例 #25
0
 def test_message_to_objects_profile(self):
     entities = message_to_objects(DIASPORA_PROFILE, "*****@*****.**")
     assert len(entities) == 1
     profile = entities[0]
     assert profile.handle == "*****@*****.**"
     assert profile.name == "Bob Bobertson"
     assert profile.image_urls == {
         "large": "https://example.com/uploads/images/thumb_large_c833747578b5.jpg",
         "medium": "https://example.com/uploads/images/thumb_medium_c8b1aab04f3.jpg",
         "small": "https://example.com/uploads/images/thumb_small_c8b147578b5.jpg",
     }
     assert profile.gender == ""
     assert profile.raw_content == "A cool bio"
     assert profile.location == "Helsinki"
     assert profile.public == True
     assert profile.nsfw == False
     assert profile.tag_list == ["socialfederation", "federation"]
コード例 #26
0
 def test_message_to_objects_comment(self, mock_validate):
     entities = message_to_objects(DIASPORA_POST_COMMENT, "*****@*****.**",
                                   sender_key_fetcher=Mock())
     assert len(entities) == 1
     comment = entities[0]
     assert isinstance(comment, DiasporaComment)
     assert isinstance(comment, Comment)
     assert comment.target_guid == "((parent_guidparent_guidparent_guidparent_guid))"
     assert comment.guid == "((guidguidguidguidguidguid))"
     assert comment.handle == "*****@*****.**"
     assert comment.participation == "comment"
     assert comment.raw_content == "((text))"
     assert comment.signature == "((signature))"
     assert comment._xml_tags == [
         "guid", "parent_guid", "text", "author",
     ]
     mock_validate.assert_called_once_with()
コード例 #27
0
 def test_sign_with_parent(self, mock_validate):
     entities = message_to_objects(DIASPORA_POST_COMMENT, "*****@*****.**",
                                   sender_key_fetcher=Mock())
     entity = entities[0]
     entity.sign_with_parent(get_dummy_private_key())
     assert entity.parent_signature == "UTIDiFZqjxfU6ssVlmjz2RwOD/WPmMTFv57qOm0BZvBhF8Ef49Ynse1c2XTtx3rs8DyRMn54" \
                                       "Uw4E0T+3t0Q5SHEQTLtRnOdRXrgNGAnlJ2xRmBWqe6xvvgc4nJ8OnffXhVgI8DBx6YUFRDjJ" \
                                       "fnVQhnqbWr4ZAcpywCyL9IDkap3cTyn6wHo2WFRtq5syTCtMS8RZLXgpVLCeMfHhrXlePIA/" \
                                       "YwMNn0GGi+9qSWXYVFG75cPjcWeY4t5q8EHCQReSSxG4a3HGbc7MigLvHzuhdOWOV8563dYo" \
                                       "/5xS3zlQUt8I3AwXOzHr+57r1egMBHYyXTXsS8gFisj7mH4TsLM+Yw=="
     assert etree.tostring(entity.outbound_doc) == b'<comment>\n      <guid>((guidguidguidguidguidguid))</guid>\n' \
                                                   b'      <parent_guid>((parent_guidparent_guidparent_guidparent' \
                                                   b'_guid))</parent_guid>\n      <author_signature>((base64-enco' \
                                                   b'ded data))</author_signature>\n      <text>((text))</text>\n' \
                                                   b'      <author>[email protected]</author>\n   ' \
                                                   b'   <author_signature>((signature))</author_signature>\n    ' \
                                                   b'<parent_author_signature>UTIDiFZqjxfU6ssVlmjz2RwOD/WPmMTFv57' \
                                                   b'qOm0BZvBhF8Ef49Ynse1c2XTtx3rs8DyRMn54Uw4E0T+3t0Q5SHEQTLtRnOd' \
                                                   b'RXrgNGAnlJ2xRmBWqe6xvvgc4nJ8OnffXhVgI8DBx6YUFRDjJfnVQhnqbWr4' \
                                                   b'ZAcpywCyL9IDkap3cTyn6wHo2WFRtq5syTCtMS8RZLXgpVLCeMfHhrXlePIA' \
                                                   b'/YwMNn0GGi+9qSWXYVFG75cPjcWeY4t5q8EHCQReSSxG4a3HGbc7MigLvHzu' \
                                                   b'hdOWOV8563dYo/5xS3zlQUt8I3AwXOzHr+57r1egMBHYyXTXsS8gFisj7mH4' \
                                                   b'TsLM+Yw==</parent_author_signature></comment>'
コード例 #28
0
 def test_element_to_objects_calls_sender_key_fetcher(self, mock_validate):
     mock_fetcher = Mock()
     message_to_objects(DIASPORA_POST_COMMENT,
                        "*****@*****.**", mock_fetcher)
     mock_fetcher.assert_called_once_with(
         "*****@*****.**")
コード例 #29
0
 def test_adds_source_protocol_to_entity(self):
     entities = message_to_objects(DIASPORA_POST_SIMPLE,
                                   "*****@*****.**")
     assert entities[0]._source_protocol == "diaspora"
コード例 #30
0
 def test_invalid_entity_logs_an_error(self, mock_logger):
     entities = message_to_objects(DIASPORA_POST_INVALID,
                                   "*****@*****.**")
     assert len(entities) == 0
     assert mock_logger.called
コード例 #31
0
 def test_message_to_objects_profile__first_name_only(self):
     entities = message_to_objects(DIASPORA_PROFILE_FIRST_NAME_ONLY, "*****@*****.**")
     assert len(entities) == 1
     profile = entities[0]
     assert profile.name == "Bob"
コード例 #32
0
 def test_element_to_objects_returns_no_entity_if_handles_are_different(
         self):
     entities = message_to_objects(DIASPORA_POST_SIMPLE, "*****@*****.**")
     assert not entities
コード例 #33
0
 def test_element_to_objects_calls_retrieve_remote_profile(
         self, mock_retrieve, mock_validate):
     message_to_objects(DIASPORA_POST_COMMENT,
                        "*****@*****.**")
     mock_retrieve.assert_called_once_with(
         "*****@*****.**")
コード例 #34
0
 def test_message_to_objects_profile_survives_empty_tag_string(self):
     entities = message_to_objects(DIASPORA_PROFILE_EMPTY_TAGS,
                                   "*****@*****.**")
     assert len(entities) == 1
コード例 #35
0
 def test_element_to_objects_verifies_handles_are_the_same(
         self, mock_check):
     message_to_objects(DIASPORA_POST_SIMPLE, "*****@*****.**")
     mock_check.assert_called_once_with("*****@*****.**",
                                        "*****@*****.**")
コード例 #36
0
 def test_invalid_entity_logs_an_error(self, mock_logger):
     entities = message_to_objects(DIASPORA_POST_INVALID)
     assert len(entities) == 0
     assert mock_logger.called
コード例 #37
0
 def test_message_to_objects_legact_timestamp(self):
     entities = message_to_objects(DIASPORA_POST_LEGACY_TIMESTAMP,
                                   "*****@*****.**")
     post = entities[0]
     assert post.created_at == datetime(2011, 7, 20, 1, 36, 7)
コード例 #38
0
 def test_message_to_objects_mentions_are_extracted(self):
     entities = message_to_objects(DIASPORA_POST_SIMPLE_WITH_MENTION, "*****@*****.**")
     assert len(entities) == 1
     post = entities[0]
     assert post._mentions == {'diaspora://[email protected]/profile/'}