Correctly extend entity _children

Certain payloads caused _children for an entity to be written over by an empty list. Correctly do an extend on it.

Closes #89
merge-requests/130/head
Jason Robinson 2017-07-03 22:27:37 +03:00
rodzic 659ba5643d
commit 0363260374
4 zmienionych plików z 34 dodań i 2 usunięć

Wyświetl plik

@ -4,6 +4,7 @@
### Fixed
* Fix getting sender from a combination of legacy Diaspora encrypted payload and new entity names (for example `author`). This combination probably only existed in this library.
* Correctly extend entity `_children`. Certain Diaspora payloads caused `_children` for an entity to be written over by an empty list, causing for example status message photos to not be saved. Correctly do an extend on it.
### Removed
* `Post.photos` entity attribute was never used by any code and has been removed. Child entities of type `Image` are stored in the `Post._children` as before.

Wyświetl plik

@ -99,7 +99,7 @@ def element_to_objects(element, sender_key_fetcher=None, user=None):
return []
# Do child elements
for child in element:
entity._children = element_to_objects(child)
entity._children.extend(element_to_objects(child))
# Add to entities list
entities.append(entity)
if cls == DiasporaRequest:

Wyświetl plik

@ -15,7 +15,7 @@ from federation.tests.fixtures.payloads import (
DIASPORA_POST_SIMPLE, DIASPORA_POST_COMMENT, DIASPORA_POST_LIKE,
DIASPORA_REQUEST, DIASPORA_PROFILE, DIASPORA_POST_INVALID, DIASPORA_RETRACTION,
DIASPORA_POST_WITH_PHOTOS, DIASPORA_POST_LEGACY_TIMESTAMP, DIASPORA_POST_LEGACY, DIASPORA_CONTACT,
DIASPORA_LEGACY_REQUEST_RETRACTION)
DIASPORA_LEGACY_REQUEST_RETRACTION, DIASPORA_POST_WITH_PHOTOS_2)
def mock_fill(attributes):
@ -75,6 +75,13 @@ class TestDiasporaEntityMappersReceive():
assert photo.public == False
assert photo.created_at == datetime(2011, 7, 20, 1, 36, 7)
entities = message_to_objects(DIASPORA_POST_WITH_PHOTOS_2)
assert len(entities) == 1
post = entities[0]
assert isinstance(post, DiasporaPost)
photo = post._children[0]
assert isinstance(photo, Image)
@patch("federation.entities.diaspora.mappers.DiasporaComment._validate_signatures")
def test_message_to_objects_comment(self, mock_validate):
entities = message_to_objects(DIASPORA_POST_COMMENT, sender_key_fetcher=Mock())

Wyświetl plik

@ -109,6 +109,30 @@ DIASPORA_POST_WITH_PHOTOS = """
"""
DIASPORA_POST_WITH_PHOTOS_2 = """
<status_message>
<diaspora_handle>xxxxxxxxxxxxxxx@diasp.org</diaspora_handle>
<guid>fewhefihefifhwihfwehfwehfiuwehfiuwhif</guid>
<created_at>2017-06-10T14:41:47Z</created_at>
<provider_display_name>mobile</provider_display_name>
<raw_message>#foo #bar (fewfefewfwfewfwe)</raw_message>
<photo>
<guid>fjwjewiofjoiwjfiowefewew</guid>
<diaspora_handle>xxxxxxxxxxxxxxxxx@diasp.org</diaspora_handle>
<public>true</public>
<created_at>2017-06-10T14:41:28Z</created_at>
<remote_photo_path>https://diasp.org/uploads/images/</remote_photo_path>
<remote_photo_name>fewhuwehiufhuiefhuiwee.jpg</remote_photo_name>
<text/>
<status_message_guid>fewhefihefifhwihfwehfwehfiuwehfiuwhif</status_message_guid>
<height>4032</height>
<width>3024</width>
</photo>
<public>true</public>
</status_message>
"""
DIASPORA_POST_INVALID = """
<status_message>
<text>((status message))</text>