diff --git a/tests/unit/test_ap-gateway.py b/tests/unit/test_ap-gateway.py index 8241e206..e8cc3d3b 100644 --- a/tests/unit/test_ap-gateway.py +++ b/tests/unit/test_ap-gateway.py @@ -23,13 +23,18 @@ from functools import partial import pytest from pytest_twisted import ensureDeferred as ed +from twisted.internet import defer from twisted.words.protocols.jabber import jid from twisted.web.server import Request +from twisted.words.xish import domish from wokkel import rsm, pubsub from sat.core import exceptions +from sat.core.constants import Const as C from sat.plugins import plugin_comp_ap_gateway +from sat.plugins.plugin_comp_ap_gateway import constants as ap_const from sat.plugins.plugin_comp_ap_gateway.http_server import HTTPServer +from sat.plugins.plugin_xep_0277 import NS_ATOM from sat.plugins.plugin_xep_0465 import NS_PPS from sat.tools.utils import xmpp_date from sat.tools import xml_tools @@ -39,7 +44,9 @@ from sat.plugins.plugin_comp_ap_gateway import TYPE_ACTOR TEST_BASE_URL = "https://example.org" TEST_USER = "test_user" TEST_AP_ACCOUNT = f"{TEST_USER}@example.org" +TEST_AP_ACTOR_ID = f"{TEST_BASE_URL}/users/{TEST_USER}" PUBLIC_URL = "test.example" +TEST_JID = jid.JID(f"some_user@{PUBLIC_URL}") AP_REQUESTS = { f"{TEST_BASE_URL}/.well-known/webfinger?" @@ -367,6 +374,12 @@ async def mock_getItems(*args, **kwargs): return ret_items, {"rsm": rsm_resp.toDict(), "complete": True} +def getVirtualClient(jid): + client = MagicMock() + client.jid = jid + return client + + @pytest.fixture(scope="session") def ap_gateway(host): gateway = plugin_comp_ap_gateway.APGateway(host) @@ -376,6 +389,7 @@ def ap_gateway(host): client = MagicMock() client.jid = jid.JID("ap.test.example") client.host = "test.example" + client.getVirtualClient = getVirtualClient gateway.client = client gateway.local_only = True gateway.public_url = PUBLIC_URL @@ -390,6 +404,13 @@ def ap_gateway(host): class TestActivityPubGateway: + def getTitleXHTML(self, item_elt: domish.Element) -> domish.Element: + return next( + t for t in item_elt.entry.elements(NS_ATOM, "title") + if t.getAttribute("type") == "xhtml" + ) + + @ed async def test_jid_and_node_convert_to_ap_handle(self, ap_gateway): """JID and pubsub node are converted correctly to an AP actor handle""" @@ -491,7 +512,8 @@ class TestActivityPubGateway: assert rsm_resp.first == "https://example.org/users/test_user/statuses/4" assert rsm_resp.last == "https://example.org/users/test_user/statuses/3" - assert items[0].entry.title.toXml() == ( + title_xhtml = self.getTitleXHTML(items[0]) + assert title_xhtml.toXml() == ( "
test message 4
test message 3
test message 2
test message 1
test message 2
test message 3
test message 1