Make Diaspora get_full_xml_representation take in private key as param instead of user

merge-requests/130/head
Jason Robinson 2017-05-01 17:32:46 +03:00
rodzic 2a3700b518
commit e06509af19
2 zmienionych plików z 4 dodań i 5 usunięć

Wyświetl plik

@ -49,16 +49,16 @@ def get_base_attributes(entity):
return attributes
def get_full_xml_representation(entity, author):
def get_full_xml_representation(entity, private_key):
"""Get full XML representation of an entity.
This contains the <XML><post>..</post></XML> wrapper.
Accepts either a Base entity or a Diaspora entity.
Author must have `private_key` that is used in signing certain entities.
Author `private_key` must be given so that certain entities can be signed.
"""
from federation.entities.diaspora.mappers import get_outbound_entity
diaspora_entity = get_outbound_entity(entity, author.private_key)
diaspora_entity = get_outbound_entity(entity, private_key)
xml = diaspora_entity.to_xml()
return "<XML><post>%s</post></XML>" % etree.tostring(xml).decode("utf-8")

Wyświetl plik

@ -1,6 +1,5 @@
import datetime
import re
from unittest.mock import Mock
import arrow
@ -21,7 +20,7 @@ class TestGetBaseAttributes():
class TestGetFullXMLRepresentation():
def test_returns_xml_document(self):
entity = Post()
document = get_full_xml_representation(entity, Mock(private_key=""))
document = get_full_xml_representation(entity, "")
document = re.sub(r"<created_at>.*</created_at>", "", document) # Dates are annoying to compare
assert document == "<XML><post><status_message><raw_message></raw_message><guid></guid>" \
"<diaspora_handle></diaspora_handle><public>false</public>" \