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
This commit is contained in:
Goffi 2022-08-31 17:07:03 +02:00
commit 85afb52968

View file

@ -412,12 +412,19 @@ async def mock_getPubsubNode(client, service, node, with_subscriptions=False, **
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 @@ def ap_gateway(host):
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 @@ class TestActivityPubGateway:
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 @@ class TestActivityPubGateway:
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 @@ class TestActivityPubGateway:
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 @@ class TestActivityPubGateway:
)
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 @@ class TestActivityPubGateway:
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