comparison tests/unit/test_ap-gateway.py @ 3808:39fc2e1b3793

tests (unit/ap gateway): fix `onMessage` call following change in the component: the component now uses the normal message workflow, thus the tests had to be updated rel 367
author Goffi <goffi@goffi.org>
date Fri, 17 Jun 2022 15:50:34 +0200
parents 0b54be42d0aa
children 04b57c0b2278
comparison
equal deleted inserted replaced
3807:2032826cfbcf 3808:39fc2e1b3793
821 async def test_xmpp_message_to_ap_direct_message(self, ap_gateway, monkeypatch): 821 async def test_xmpp_message_to_ap_direct_message(self, ap_gateway, monkeypatch):
822 """XMPP message are sent as AP direct message""" 822 """XMPP message are sent as AP direct message"""
823 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) 823 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
824 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) 824 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
825 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) 825 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
826 message_elt = domish.Element((None, "message")) 826 mess_data = {
827 message_elt.addElement("body", content="This is a test message.") 827 "from": TEST_JID,
828 message_elt["from"] = TEST_JID.full() 828 "to": ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT),
829 message_elt["to"] = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT).full() 829 "type": "chat",
830 "message": {"": "This is a test message."},
831 "extra": {
832 "origin-id": "123"
833 }
834 }
830 with patch.object(ap_gateway, "signAndPost") as signAndPost: 835 with patch.object(ap_gateway, "signAndPost") as signAndPost:
831 await ap_gateway.onMessage(message_elt) 836 await ap_gateway.onMessage(ap_gateway.client, mess_data)
832 url, actor_id, doc = signAndPost.call_args[0] 837 url, actor_id, doc = signAndPost.call_args[0]
833 assert url == "https://example.org/users/test_user/inbox" 838 assert url == "https://example.org/users/test_user/inbox"
834 assert actor_id == "https://test.example/_ap/actor/some_user%40test.example" 839 assert actor_id == "https://test.example/_ap/actor/some_user%40test.example"
835 obj = doc["object"] 840 obj = doc["object"]
836 assert doc["@context"] == "https://www.w3.org/ns/activitystreams" 841 assert doc["@context"] == "https://www.w3.org/ns/activitystreams"