def test_comment_to_xml(self):
     entity = DiasporaComment(raw_content="raw_content", guid="guid", target_guid="target_guid", handle="handle")
     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>" \
     assert etree.tostring(result) == converted
def get_outbound_entity(entity):
    """Get the correct outbound entity for this protocol.

    We might have to look at entity values to decide the correct outbound entity.
    If we cannot find one, we should raise as conversion cannot be guaranteed to the given protocol.

    :arg entity: An entity instance which can be of a base or protocol entity class.
    :returns: Protocol specific entity class instance.
    :raises ValueError: If conversion cannot be done.
    cls = entity.__class__
    if cls in [DiasporaPost, DiasporaRequest, DiasporaComment, DiasporaLike, DiasporaProfile, DiasporaRetraction]:
        # Already fine
        return entity
    elif cls == Post:
        return DiasporaPost.from_base(entity)
    elif cls == Comment:
        return DiasporaComment.from_base(entity)
    elif cls == Reaction:
        if entity.reaction == "like":
            return DiasporaLike.from_base(entity)
    elif cls == Relationship:
        if entity.relationship in ["sharing", "following"]:
            # Unfortunately we must send out in both cases since in Diaspora they are the same thing
            return DiasporaRequest.from_base(entity)
    elif cls == Profile:
        return DiasporaProfile.from_base(entity)
    elif cls == Retraction:
        return DiasporaRetraction.from_base(entity)
    raise ValueError("Don't know how to convert this base entity to Diaspora protocol entities.")