# HG changeset patch # User Goffi # Date 1653407354 -7200 # Node ID fedbf7aade11038c477ea6aaf145406fbb4572d4 # Parent 580df5b557bef1cdf6d3a6d38abbc76eb2d03ea7 tests (unit/ap_gateway): fix tests diff -r 580df5b557be -r fedbf7aade11 tests/unit/test_ap-gateway.py --- a/tests/unit/test_ap-gateway.py Mon May 16 14:37:58 2022 +0200 +++ b/tests/unit/test_ap-gateway.py Tue May 24 17:49:14 2022 +0200 @@ -23,13 +23,18 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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() == ( "" "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 4</p></div>" "" @@ -502,7 +524,8 @@ assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" assert str(items[0].entry.published) == "2021-12-16T17:25:03Z" - assert items[1].entry.title.toXml() == ( + title_xhtml = self.getTitleXHTML(items[1]) + assert title_xhtml.toXml() == ( "" "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" "" @@ -524,7 +547,8 @@ assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" - assert items[0].entry.title.toXml() == ( + title_xhtml = self.getTitleXHTML(items[0]) + assert title_xhtml.toXml() == ( "" "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" "" @@ -535,7 +559,8 @@ assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" - assert items[1].entry.title.toXml() == ( + title_xhtml = self.getTitleXHTML(items[1]) + assert title_xhtml.toXml() == ( "" "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" "" @@ -558,7 +583,8 @@ assert rsm_resp.last == "https://example.org/users/test_user/statuses/2" assert len(items) == 1 - assert items[0].entry.title.toXml() == ( + title_xhtml = self.getTitleXHTML(items[0]) + assert title_xhtml.toXml() == ( "" "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" "" @@ -575,12 +601,14 @@ assert rsm_resp.first == "https://example.org/users/test_user/statuses/3" assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" assert len(items) == 3 - assert items[0].entry.title.toXml() == ( + title_xhtml = self.getTitleXHTML(items[0]) + assert title_xhtml.toXml() == ( "" "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" "" ) - assert items[2].entry.title.toXml() == ( + title_xhtml = self.getTitleXHTML(items[2]) + assert title_xhtml.toXml() == ( "" "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" ""