Mercurial > libervia-backend
changeset 3890:c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
- `shareInbox` is now used when available, thus tests now check for that
- `client._ap_storage` is used, thus is added to the mockClient
`ap_const.NS_AP_PUBLIC` is now in `cc` instead of `to` field
rel 371
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 31 Aug 2022 17:07:03 +0200 |
parents | 1ab5fb468a41 |
children | 989df1047c3c |
files | tests/unit/test_ap-gateway.py |
diffstat | 1 files changed, 14 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/tests/unit/test_ap-gateway.py Wed Aug 31 17:07:03 2022 +0200 +++ b/tests/unit/test_ap-gateway.py Wed Aug 31 17:07:03 2022 +0200 @@ -412,12 +412,19 @@ return fake_cached_node -def getVirtualClient(jid): +def mockClient(jid): client = MagicMock() client.jid = jid + client.host = "test.example" + client._ap_storage.get = AsyncMock() + client._ap_storage.aset = AsyncMock() return client +def getVirtualClient(jid): + return mockClient(jid) + + class FakeTReqPostResponse: code = 202 @@ -428,9 +435,7 @@ gateway.initialised = True gateway.isPubsub = AsyncMock() gateway.isPubsub.return_value = False - client = MagicMock() - client.jid = jid.JID("ap.test.example") - client.host = "test.example" + client = mockClient(jid.JID("ap.test.example")) client.getVirtualClient = getVirtualClient gateway.client = client gateway.local_only = True @@ -967,7 +972,7 @@ url, actor_id, doc = signAndPost.call_args[0] jid_account = await ap_gateway.getAPAccountFromJidAndNode(TEST_JID, None) jid_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, jid_account) - assert url == f"{TEST_BASE_URL}/users/{TEST_USER}/inbox" + assert url == f"{TEST_BASE_URL}/inbox" assert actor_id == jid_actor_id assert doc["type"] == "Delete" assert doc["actor"] == jid_actor_id @@ -1424,7 +1429,7 @@ assert signAndPost.called url, actor_id, doc = signAndPost.call_args.args - assert url == TEST_USER_DATA["inbox"] + assert url == TEST_USER_DATA["endpoints"]["sharedInbox"] assert actor_id == ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost()) assert doc["type"] == "Announce" assert ap_const.NS_AP_PUBLIC in doc["to"] @@ -1498,12 +1503,6 @@ recipient_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT) # noticed item ap_item = TEST_AP_ITEMS[0] - ap_item_url = xmpp_uri.buildXMPPUri( - "pubsub", - path=recipient_jid.full(), - node=ap_gateway._m.namespace, - item=ap_item["id"] - ) attachment_node = ap_gateway._pa.getAttachmentNodeName( recipient_jid, ap_gateway._m.namespace, @@ -1511,7 +1510,7 @@ ) item_elt = xml_tools.parse(f""" <item id="{TEST_JID.userhost()}" published="{TEST_JID.userhostJID()}"> - <attachments xmlns="urn:xmpp:pubsub-attachments:0"> + <attachments xmlns="urn:xmpp:pubsub-attachments:1"> <noticed timestamp="2022-07-22T12:29:45Z"/> </attachments> </item> @@ -1534,10 +1533,10 @@ assert signAndPost.called url, actor_id, doc = signAndPost.call_args.args - assert url == TEST_USER_DATA["inbox"] + assert url == TEST_USER_DATA["endpoints"]["sharedInbox"] assert actor_id == ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost()) assert doc["type"] == "Like" - assert ap_const.NS_AP_PUBLIC in doc["to"] + assert ap_const.NS_AP_PUBLIC in doc["cc"] assert doc["object"] == ap_item["id"] @ed