Exemplo n.º 1
0
 def test_post_to_xml(self):
     entity = DiasporaPost(raw_content="raw_content", guid="guid", handle="handle", public=True)
     result = entity.to_xml()
     assert result.tag == "status_message"
     assert len(result.find("created_at").text) > 0
     result.find("created_at").text = ""  # timestamp makes testing painful
     converted = b"<status_message><raw_message>raw_content</raw_message><guid>guid</guid>" \
                 b"<diaspora_handle>handle</diaspora_handle><public>true</public><created_at>" \
                 b"</created_at></status_message>"
     assert etree.tostring(result) == converted
Exemplo n.º 2
0
 def test_post_to_xml(self):
     entity = DiasporaPost(
         raw_content="raw_content", guid="guid", handle="handle", public=True,
         provider_display_name="Socialhome"
     )
     result = entity.to_xml()
     assert result.tag == "status_message"
     assert len(result.find("created_at").text) > 0
     result.find("created_at").text = ""  # timestamp makes testing painful
     converted = b"<status_message><raw_message>raw_content</raw_message><guid>guid</guid>" \
                 b"<diaspora_handle>handle</diaspora_handle><public>true</public><created_at>" \
                 b"</created_at><provider_display_name>Socialhome</provider_display_name></status_message>"
     assert etree.tostring(result) == converted
Exemplo n.º 3
0
 def test_build_send_does_right_calls(self, mock_me):
     mock_render = Mock(return_value="rendered")
     mock_me_instance = Mock(render=mock_render)
     mock_me.return_value = mock_me_instance
     protocol = Protocol()
     entity = DiasporaPost()
     private_key = get_dummy_private_key()
     outbound_entity = get_outbound_entity(entity, private_key)
     data = protocol.build_send(outbound_entity, from_user=Mock(
         private_key=private_key, handle="johnny@localhost",
     ))
     mock_me.assert_called_once_with(
         etree.tostring(entity.to_xml()), private_key=private_key, author_handle="johnny@localhost",
     )
     mock_render.assert_called_once_with()
     assert data == "rendered"
Exemplo n.º 4
0
 def test_build_send_does_right_calls__private_payload(self, mock_encrypt, mock_me):
     mock_render = Mock(return_value="rendered")
     mock_me_instance = Mock(render=mock_render)
     mock_me.return_value = mock_me_instance
     protocol = Protocol()
     entity = DiasporaPost()
     entity.validate = Mock()
     private_key = get_dummy_private_key()
     outbound_entity = get_outbound_entity(entity, private_key)
     data = protocol.build_send(outbound_entity, to_user_key="public key", from_user=UserType(
         private_key=private_key, id="johnny@localhost",
         handle="johnny@localhost",
     ))
     mock_me.assert_called_once_with(
         etree.tostring(entity.to_xml()), private_key=private_key, author_handle="johnny@localhost",
     )
     mock_render.assert_called_once_with()
     mock_encrypt.assert_called_once_with(
         "rendered", "public key",
     )
     assert data == "encrypted"