Save Diaspora author_signature to entity

merge-requests/130/head
Jason Robinson 2017-04-23 22:09:04 +03:00
rodzic be329a5fe7
commit ba1365f009
5 zmienionych plików z 19 dodań i 13 usunięć

Wyświetl plik

@ -28,14 +28,12 @@ class DiasporaEntityMixin(object):
class DiasporaComment(DiasporaEntityMixin, Comment):
"""Diaspora comment."""
author_signature = ""
def to_xml(self):
element = etree.Element("comment")
struct_to_xml(element, [
{'guid': self.guid},
{'parent_guid': self.target_guid},
{'author_signature': self.author_signature},
{'author_signature': self.signature},
{'text': self.raw_content},
{'diaspora_handle': self.handle},
])
@ -60,7 +58,6 @@ class DiasporaPost(DiasporaEntityMixin, Post):
class DiasporaLike(DiasporaEntityMixin, Reaction):
"""Diaspora like."""
author_signature = ""
reaction = "like"
def to_xml(self):
@ -70,7 +67,7 @@ class DiasporaLike(DiasporaEntityMixin, Reaction):
{"target_type": "Post"},
{'guid': self.guid},
{'parent_guid': self.target_guid},
{'author_signature': self.author_signature},
{'author_signature': self.signature},
{"positive": "true"},
{'diaspora_handle': self.handle},
])

Wyświetl plik

@ -138,6 +138,8 @@ def transform_attributes(attrs):
elif key == "status_message_guid":
transformed["linked_guid"] = value
transformed["linked_type"] = "Post"
elif key == "author_signature":
transformed["signature"] = value
elif key in BOOLEAN_KEYS:
transformed[key] = True if value == "true" else False
elif key in DATETIME_KEYS:

Wyświetl plik

@ -1,15 +1,15 @@
# -*- coding: utf-8 -*-
from unittest.mock import patch
import pytest
from lxml import etree
from federation.entities.base import Profile
from federation.entities.diaspora.entities import DiasporaComment, DiasporaPost, DiasporaLike, DiasporaRequest, \
DiasporaProfile, DiasporaRetraction
from federation.entities.diaspora.entities import (
DiasporaComment, DiasporaPost, DiasporaLike, DiasporaRequest, DiasporaProfile, DiasporaRetraction,
)
class TestEntitiesConvertToXML(object):
class TestEntitiesConvertToXML():
def test_post_to_xml(self):
entity = DiasporaPost(
raw_content="raw_content", guid="guid", handle="handle", public=True,
@ -25,20 +25,23 @@ class TestEntitiesConvertToXML(object):
assert etree.tostring(result) == converted
def test_comment_to_xml(self):
entity = DiasporaComment(raw_content="raw_content", guid="guid", target_guid="target_guid", handle="handle")
entity = DiasporaComment(
raw_content="raw_content", guid="guid", target_guid="target_guid", handle="handle",
signature="signature"
)
result = entity.to_xml()
assert result.tag == "comment"
converted = b"<comment><guid>guid</guid><parent_guid>target_guid</parent_guid>" \
b"<author_signature></author_signature><text>raw_content</text>" \
b"<author_signature>signature</author_signature><text>raw_content</text>" \
b"<diaspora_handle>handle</diaspora_handle></comment>"
assert etree.tostring(result) == converted
def test_like_to_xml(self):
entity = DiasporaLike(guid="guid", target_guid="target_guid", handle="handle")
entity = DiasporaLike(guid="guid", target_guid="target_guid", handle="handle", signature="signature")
result = entity.to_xml()
assert result.tag == "like"
converted = b"<like><target_type>Post</target_type><guid>guid</guid><parent_guid>target_guid</parent_guid>" \
b"<author_signature></author_signature><positive>true</positive>" \
b"<author_signature>signature</author_signature><positive>true</positive>" \
b"<diaspora_handle>handle</diaspora_handle></like>"
assert etree.tostring(result) == converted

Wyświetl plik

@ -84,6 +84,7 @@ class TestDiasporaEntityMappersReceive(object):
assert comment.handle == "alice@alice.diaspora.example.org"
assert comment.participation == "comment"
assert comment.raw_content == "((text))"
assert comment.signature == "((signature))"
def test_message_to_objects_like(self):
entities = message_to_objects(DIASPORA_POST_LIKE)
@ -96,6 +97,7 @@ class TestDiasporaEntityMappersReceive(object):
assert like.handle == "alice@alice.diaspora.example.org"
assert like.participation == "reaction"
assert like.reaction == "like"
assert like.signature == "((signature))"
def test_message_to_objects_request(self):
entities = message_to_objects(DIASPORA_REQUEST)

Wyświetl plik

@ -118,6 +118,7 @@ DIASPORA_POST_COMMENT = """<XML>
<author_signature>((base64-encoded data))</author_signature>
<text>((text))</text>
<diaspora_handle>alice@alice.diaspora.example.org</diaspora_handle>
<author_signature>((signature))</author_signature>
</comment>
</post>
</XML>
@ -132,6 +133,7 @@ DIASPORA_POST_LIKE = """<XML>
<author_signature>((base64-encoded data))</author_signature>
<positive>true</positive>
<diaspora_handle>alice@alice.diaspora.example.org</diaspora_handle>
<author_signature>((signature))</author_signature>
</like>
</post>
</XML>