kopia lustrzana https://gitlab.com/jaywink/federation
Merge pull request #46 from jaywink/full-xml-repr
Add Diaspora entity utility get_full_xml_representationmerge-requests/130/head
commit
c58d717b78
|
@ -7,6 +7,7 @@
|
|||
## Added
|
||||
- `Post.provider_display_name` is now supported in the entity outbound/inbound mappers. [#44](https://github.com/jaywink/social-federation/pull/44)
|
||||
- Add utility method `federation.utils.network.send_document` which is just a wrapper around `requests.post`. User agent will be added to the headers and exceptions will be silently captured and returned instead. [#45](https://github.com/jaywink/social-federation/pull/45)
|
||||
- Add Diaspora entity utility `federation.entities.diaspora.utils.get_full_xml_representation`. Renders the entity XML document and wraps it in `<XML><post>...</post></XML>`. [#46](https://github.com/jaywink/social-federation/pull/46)
|
||||
|
||||
## [0.4.1] - 2016-09-04
|
||||
|
||||
|
|
|
@ -48,3 +48,16 @@ def get_base_attributes(entity):
|
|||
if not attr.startswith("_"):
|
||||
attributes[attr] = getattr(entity, attr)
|
||||
return attributes
|
||||
|
||||
|
||||
def get_full_xml_representation(entity):
|
||||
"""Get full XML representation of an entity.
|
||||
|
||||
This contains the <XML><post>..</post></XML> wrapper.
|
||||
|
||||
Accepts either a Base entity or a Diaspora entity.
|
||||
"""
|
||||
from federation.entities.diaspora.mappers import get_outbound_entity
|
||||
diaspora_entity = get_outbound_entity(entity)
|
||||
xml = diaspora_entity.to_xml()
|
||||
return "<XML><post>%s</post></XML>" % etree.tostring(xml).decode("utf-8")
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
import re
|
||||
|
||||
from federation.entities.base import Post
|
||||
from federation.entities.diaspora.utils import get_base_attributes
|
||||
from federation.entities.diaspora.utils import get_base_attributes, get_full_xml_representation
|
||||
|
||||
|
||||
class TestGetBaseAttributes(object):
|
||||
|
@ -10,3 +12,13 @@ class TestGetBaseAttributes(object):
|
|||
assert set(attrs) == {
|
||||
'created_at', 'guid', 'handle', 'location', 'photos', 'provider_display_name', 'public', 'raw_content'
|
||||
}
|
||||
|
||||
|
||||
class TestGetFullXMLRepresentation(object):
|
||||
def test_returns_xml_document(self):
|
||||
entity = Post()
|
||||
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>" \
|
||||
"<provider_display_name></provider_display_name></status_message></post></XML>"
|
||||
|
|
Ładowanie…
Reference in New Issue