def handle_create_payload(from_user, to_user, entity): """Create a payload with the correct protocol. Since we don't know the protocol, we need to first query the recipient. However, for a PoC implementation, supporting only Diaspora, we're going to assume that for now. Args: from_user (obj) - User sending the object to_user (obj) - Contact entry to send to entity (obj) - Entity object to send `from_user` must have `private_key` and `handle` attributes. `to_user` must have `key` attribute. """ protocol = Protocol() data = protocol.build_send(from_user=from_user, to_user=to_user, entity=entity) return data
def init_protocol(self): return Protocol()
def test_store_magic_envelope_doc_json_payload(self, mock_store): protocol = Protocol() protocol.store_magic_envelope_doc('{"foo": "bar"}') mock_store.assert_called_once_with({"foo": "bar"}) assert protocol.doc.tag == "foo" assert protocol.doc.text == "bar"
def test_store_magic_envelope_doc_xml_payload(self): protocol = Protocol() protocol.store_magic_envelope_doc("<foo>bar</foo>") assert protocol.doc.tag == "foo" assert protocol.doc.text == "bar"
def test_get_json_payload_magic_envelope(self, mock_decrypt): protocol = Protocol() protocol.user = UserType(id="foobar", private_key=get_dummy_private_key()) protocol.get_json_payload_magic_envelope("payload") mock_decrypt.assert_called_once_with(payload="payload", private_key=get_dummy_private_key())