def parse_profile_from_hcard(hcard: str, handle: str): """ Parse all the fields we can from a hCard document to get a Profile. :arg hcard: HTML hcard document (str) :arg handle: User handle in [email protected] format :returns: ``federation.entities.diaspora.entities.DiasporaProfile`` instance """ from federation.entities.diaspora.entities import DiasporaProfile # Circulars doc = html.fromstring(hcard) profile = DiasporaProfile( name=_get_element_text_or_none(doc, ".fn"), image_urls={ "small": _get_element_attr_or_none(doc, ".entity_photo_small .photo", "src"), "medium": _get_element_attr_or_none(doc, ".entity_photo_medium .photo", "src"), "large": _get_element_attr_or_none(doc, ".entity_photo .photo", "src"), }, public=True, id=handle, handle=handle, guid=_get_element_text_or_none(doc, ".uid"), public_key=_get_element_text_or_none(doc, ".key"), username=handle.split('@')[0], _source_protocol="diaspora", ) return profile
def diasporaprofile(): return DiasporaProfile( handle="*****@*****.**", raw_content="foobar", name="Bob Bobertson", public=True, tag_list=["socialfederation", "federation"], image_urls={ "large": "urllarge", "medium": "urlmedium", "small": "urlsmall" } )
def test_already_fine_entities_are_returned_as_is(self): entity = DiasporaPost() assert get_outbound_entity(entity) == entity entity = DiasporaLike() assert get_outbound_entity(entity) == entity entity = DiasporaComment() assert get_outbound_entity(entity) == entity entity = DiasporaRequest() assert get_outbound_entity(entity) == entity entity = DiasporaProfile() assert get_outbound_entity(entity) == entity
def test_already_fine_entities_are_returned_as_is(self, private_key): entity = DiasporaPost() assert get_outbound_entity(entity, private_key) == entity entity = DiasporaLike() assert get_outbound_entity(entity, private_key) == entity entity = DiasporaComment() assert get_outbound_entity(entity, private_key) == entity entity = DiasporaProfile(handle="*****@*****.**", guid="1234") assert get_outbound_entity(entity, private_key) == entity entity = DiasporaContact() assert get_outbound_entity(entity, private_key) == entity entity = DiasporaReshare() assert get_outbound_entity(entity, private_key) == entity
def test_profile_to_xml(self): entity = DiasporaProfile( handle="*****@*****.**", raw_content="foobar", name="Bob Bobertson", public=True, tag_list=["socialfederation", "federation"], image_urls={ "large": "urllarge", "medium": "urlmedium", "small": "urlsmall" } ) result = entity.to_xml() assert result.tag == "profile" converted = b"<profile><diaspora_handle>[email protected]</diaspora_handle>" \ b"<first_name>Bob Bobertson</first_name><last_name></last_name><image_url>urllarge</image_url>" \ b"<image_url_small>urlsmall</image_url_small><image_url_medium>urlmedium</image_url_medium>" \ b"<gender></gender><bio>foobar</bio><location></location><searchable>true</searchable>" \ b"<nsfw>false</nsfw><tag_string>#socialfederation #federation</tag_string></profile>" assert etree.tostring(result) == converted
def diasporaprofile_activitypub_id(): return DiasporaProfile( raw_content="foobar", name="Bob Bobertson", public=True, tag_list=["socialfederation", "federation"], image_urls={ "large": "urllarge", "medium": "urlmedium", "small": "urlsmall" }, id="http://example.com/alice", handle="*****@*****.**", guid="guid", )