annotate tests/unit/test_ap-gateway.py @ 3891:989df1047c3c

tests (AP gateway): reactions tests: 2 new tests check XMPP <=> AP reactions conversion rel 371
author Goffi <goffi@goffi.org>
date Wed, 31 Aug 2022 17:07:03 +0200
parents c129234a5d0b
children 755920bd30da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
3 # Libervia: an XMPP client
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # Copyright (C) 2009-2022 Jérôme Poisson (goffi@goffi.org)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 from copy import deepcopy
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
20 from functools import partial
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
21 import io
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
22 import json
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
23 from typing import Any, Dict, Optional, Union
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
24 from unittest.mock import AsyncMock, DEFAULT, MagicMock, patch
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from urllib import parse
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 import pytest
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from pytest_twisted import ensureDeferred as ed
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
29 from treq.response import _Response as TReqResponse
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
30 from twisted.internet import defer
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
31 from twisted.web.server import Request
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from twisted.words.protocols.jabber import jid
3826
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
33 from twisted.words.protocols.jabber.error import StanzaError
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
34 from twisted.words.xish import domish
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
35 from wokkel import pubsub, rsm
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 from sat.core import exceptions
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
38 from sat.core.constants import Const as C
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
39 from sat.memory.sqla_mapping import SubscriptionState
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 from sat.plugins import plugin_comp_ap_gateway
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
41 from sat.plugins.plugin_comp_ap_gateway import constants as ap_const
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
42 from sat.plugins.plugin_comp_ap_gateway import TYPE_ACTOR
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 from sat.plugins.plugin_comp_ap_gateway.http_server import HTTPServer
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
44 from sat.plugins.plugin_xep_0277 import NS_ATOM
3809
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
45 from sat.plugins.plugin_xep_0422 import NS_FASTEN
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
46 from sat.plugins.plugin_xep_0424 import NS_MESSAGE_RETRACT
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
47 from sat.plugins.plugin_xep_0465 import NS_PPS
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 from sat.tools import xml_tools
3837
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
49 from sat.tools.common import uri as xmpp_uri
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
50 from sat.tools.utils import xmpp_date
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
51
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
52
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 TEST_BASE_URL = "https://example.org"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 TEST_USER = "test_user"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 TEST_AP_ACCOUNT = f"{TEST_USER}@example.org"
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
56 TEST_AP_ACTOR_ID = f"{TEST_BASE_URL}/users/{TEST_USER}"
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
57 PUBLIC_URL = "test.example"
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
58 TEST_JID = jid.JID(f"some_user@{PUBLIC_URL}")
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
59
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 AP_REQUESTS = {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
61 f"{TEST_BASE_URL}/.well-known/webfinger?"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 f"resource=acct:{parse.quote(TEST_AP_ACCOUNT)}": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 "aliases": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 f"{TEST_BASE_URL}/@{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 f"{TEST_BASE_URL}/users/{TEST_USER}"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 "links": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 "href": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 "rel": "self",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 "type": "application/activity+json"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
74 "subject": f"acct:{TEST_AP_ACCOUNT}"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
76
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 f"{TEST_BASE_URL}/users/{TEST_USER}": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
78 "@context": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "https://www.w3.org/ns/activitystreams",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 "endpoints": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 "sharedInbox": f"{TEST_BASE_URL}/inbox"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 "followers": f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 "following": f"{TEST_BASE_URL}/users/{TEST_USER}/following",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 "id": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 "inbox": f"{TEST_BASE_URL}/users/{TEST_USER}/inbox",
3826
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
88 "name": "test_user nickname",
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
89 "summary": "<p>test account</p>",
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 "outbox": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 "preferredUsername": f"{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 "type": "Person",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 "url": f"{TEST_BASE_URL}/@{TEST_USER}"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 },
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
95 f"{TEST_BASE_URL}/.well-known/webfinger?"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
96 f"resource=acct:{parse.quote('ext_user@example.org')}": {
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
97 "aliases": [
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
98 f"{TEST_BASE_URL}/@ext_user",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
99 f"{TEST_BASE_URL}/users/ext_user"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
100 ],
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
101 "links": [
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
102 {
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
103 "href": f"{TEST_BASE_URL}/users/ext_user",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
104 "rel": "self",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
105 "type": "application/activity+json"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
106 },
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
107 ],
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
108 "subject": f"acct:ext_user@example.org"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
109 },
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
110 f"{TEST_BASE_URL}/users/ext_user": {
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
111 "@context": [
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
112 "https://www.w3.org/ns/activitystreams",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
113 ],
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
114 "endpoints": {
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
115 "sharedInbox": f"{TEST_BASE_URL}/inbox"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
116 },
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
117 "followers": f"{TEST_BASE_URL}/users/ext_user/followers",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
118 "following": f"{TEST_BASE_URL}/users/ext_user/following",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
119 "id": f"{TEST_BASE_URL}/users/ext_user",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
120 "inbox": f"{TEST_BASE_URL}/users/ext_user/inbox",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
121 "name": "",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
122 "outbox": f"{TEST_BASE_URL}/users/ext_user/outbox",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
123 "preferredUsername": f"ext_user",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
124 "type": "Person",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
125 "url": f"{TEST_BASE_URL}/@ext_user"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
126 },
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 "@context": "https://www.w3.org/ns/activitystreams",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 "last": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 "totalItems": 4,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 "type": "OrderedCollection"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 "@context": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 "https://www.w3.org/ns/activitystreams",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 "orderedItems": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1/activity",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 "object": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 "content": "<p>test message 1</p>",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 "contentMap": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
154 "en": "<p>test message 1</p>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
155 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 "inReplyTo": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 "published": "2021-12-16T17:28:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 "sensitive": False,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 "summary": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
161 "tag": [],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 "type": "Note",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 "url": f"{TEST_BASE_URL}/@{TEST_USER}/1"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 "published": "2021-12-16T17:28:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 "type": "Create"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2/activity",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 "object": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 "content": "<p>test message 2</p>",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 "contentMap": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
187 "en": "<p>test message 2</p>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
188 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 "inReplyTo": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 "published": "2021-12-16T17:27:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 "sensitive": False,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 "summary": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
194 "tag": [],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 "type": "Note",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 "url": f"{TEST_BASE_URL}/@{TEST_USER}/2"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 "published": "2021-12-16T17:27:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 "type": "Create"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3/activity",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 "object": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 "content": "<p>test message 3</p>",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 "contentMap": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 "en": "<p>test message 3</p>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 "inReplyTo": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 "published": "2021-12-16T17:26:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 "sensitive": False,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 "summary": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 "tag": [],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 "type": "Note",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
232 "url": f"{TEST_BASE_URL}/@{TEST_USER}/3"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 "published": "2021-12-16T17:26:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 "type": "Create"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4/activity",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 "object": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 "content": "<p>test message 4</p>",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 "contentMap": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 "en": "<p>test message 4</p>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 "inReplyTo": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 "published": "2021-12-16T17:25:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 "sensitive": False,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 "summary": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 "tag": [],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 "type": "Note",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 "url": f"{TEST_BASE_URL}/@{TEST_USER}/4"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 "published": "2021-12-16T17:25:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 "type": "Create"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 "partOf": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 "prev": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 "type": "OrderedCollectionPage"
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
277 },
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
278 f"{TEST_BASE_URL}/users/{TEST_USER}/following": {
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
279 "@context": "https://www.w3.org/ns/activitystreams",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
280 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/following?page=1",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
281 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/following",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
282 "totalItems": 2,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
283 "type": "OrderedCollection"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
284 },
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
285 f"{TEST_BASE_URL}/users/{TEST_USER}/following?page=1": {
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
286 "@context": "https://www.w3.org/ns/activitystreams",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
287 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/following?page=1",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
288 "orderedItems": [
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
289 f"{TEST_BASE_URL}/users/ext_user",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
290 f"https://{PUBLIC_URL}/_ap/{TYPE_ACTOR}/local_user%40{PUBLIC_URL}",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
291 ],
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
292 "partOf": "{TEST_BASE_URL}/users/{TEST_USER}/following",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
293 "totalItems": 2,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
294 "type": "OrderedCollectionPage"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
295 },
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
296 f"{TEST_BASE_URL}/users/{TEST_USER}/followers": {
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
297 "@context": "https://www.w3.org/ns/activitystreams",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
298 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/followers?page=1",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
299 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
300 "totalItems": 2,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
301 "type": "OrderedCollection"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
302 },
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
303 f"{TEST_BASE_URL}/users/{TEST_USER}/followers?page=1": {
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
304 "@context": "https://www.w3.org/ns/activitystreams",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
305 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/followers?page=1",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
306 "orderedItems": [
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
307 f"{TEST_BASE_URL}/users/ext_user",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
308 f"https://{PUBLIC_URL}/_ap/{TYPE_ACTOR}/local_user%40{PUBLIC_URL}",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
309 ],
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
310 "partOf": "{TEST_BASE_URL}/users/{TEST_USER}/followers",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
311 "totalItems": 2,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
312 "type": "OrderedCollectionPage"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
313 },
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
314
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
315 }
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
316
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
317 XMPP_ITEM_TPL = """
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 <item id='{id}' publisher='{publisher_jid}'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 <entry xmlns='http://www.w3.org/2005/Atom' xml:lang='en'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
320 <title type='xhtml'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
321 <div xmlns='http://www.w3.org/1999/xhtml'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
322 <p>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 XMPP item {id}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 </p>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 </div>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 </title>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 <title type='text'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
328 XMPP item {id}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 </title>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 <author>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 <name>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 test_user
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 </name>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
334 <uri>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 xmpp:{publisher_jid}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 </uri>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 </author>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 <updated>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 {updated}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
340 </updated>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 <published>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 {published}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 </published>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 <id>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 xmpp:{publisher_jid}?;node=urn%3Axmpp%3Amicroblog%3A0;item={id}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 </id>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 </entry>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
348 </item>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
349 """
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
350
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 ITEM_BASE_TS = 1643385499
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 XMPP_ITEMS = [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 xml_tools.parse(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 "".join(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 l.strip() for l in XMPP_ITEM_TPL.format(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
356 id=i,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 publisher_jid="some_user@test.example",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 updated=xmpp_date(ITEM_BASE_TS + i * 60),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
359 published=xmpp_date(ITEM_BASE_TS + i * 60),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 ).split("\n")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
361 ),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 namespace=pubsub.NS_PUBSUB
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 for i in range(1, 5)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
365 ]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
366
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
367 TEST_USER_DATA = AP_REQUESTS[f"{TEST_BASE_URL}/users/{TEST_USER}"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
368 OUTBOX_FIRST_PAGE = f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true"
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
369 TEST_AP_ITEMS = AP_REQUESTS[OUTBOX_FIRST_PAGE]["orderedItems"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
370 # request on an item ID must return the ID
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
371 for item in TEST_AP_ITEMS:
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
372 AP_REQUESTS[item["id"]] = item
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
373
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
374
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 async def mock_ap_get(url):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
376 return deepcopy(AP_REQUESTS[url])
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
377
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
378
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 async def mock_treq_json(data):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 return dict(data)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
381
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
382
3826
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
383 async def mock_getItems(client, service, node, *args, **kwargs):
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
384 """Mock getItems
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
385
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
386 special kwargs can be used:
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
387 ret_items (List[Domish.Element]): items to be returned, by default XMPP_ITEMS are
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
388 returned
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
389 tested_node (str): node for which items must be returned. If specified and a
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
390 different node is requested, "item-not-found" StanzaError will be raised
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
391 """
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
392 tested_node = kwargs.pop("tested_node", None)
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
393 if tested_node is not None and node != tested_node:
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
394 raise StanzaError("item-not-found")
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
395 ret_items = kwargs.pop("ret_items", XMPP_ITEMS)
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
396 rsm_resp = rsm.RSMResponse(
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
397 first=ret_items[0]["id"],
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
398 last=ret_items[-1]["id"],
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 index=0,
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
400 count=len(ret_items)
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
401 )
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
402 return ret_items, {"rsm": rsm_resp.toDict(), "complete": True}
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
403
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
404
3837
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
405 async def mock_getPubsubNode(client, service, node, with_subscriptions=False, **kwargs):
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
406 """Mock storage's getPubsubNode
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
407
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
408 return an MagicMock with subscription attribute set to empty list
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
409 """
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
410 fake_cached_node = MagicMock()
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
411 fake_cached_node.subscriptions = []
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
412 return fake_cached_node
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
413
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
414
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
415 def mockClient(jid):
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
416 client = MagicMock()
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
417 client.jid = jid
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
418 client.host = "test.example"
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
419 client._ap_storage.get = AsyncMock()
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
420 client._ap_storage.aset = AsyncMock()
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
421 return client
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
422
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
423
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
424 def getVirtualClient(jid):
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
425 return mockClient(jid)
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
426
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
427
3809
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
428 class FakeTReqPostResponse:
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
429 code = 202
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
430
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
431
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
432 @pytest.fixture(scope="session")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
433 def ap_gateway(host):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
434 gateway = plugin_comp_ap_gateway.APGateway(host)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
435 gateway.initialised = True
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
436 gateway.isPubsub = AsyncMock()
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
437 gateway.isPubsub.return_value = False
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
438 client = mockClient(jid.JID("ap.test.example"))
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
439 client.getVirtualClient = getVirtualClient
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
440 gateway.client = client
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
441 gateway.local_only = True
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
442 gateway.public_url = PUBLIC_URL
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
443 gateway.ap_path = '_ap'
3837
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
444 gateway.auto_mentions = True
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
445 gateway.base_ap_url = parse.urljoin(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
446 f"https://{gateway.public_url}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
447 f"{gateway.ap_path}/"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
448 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
449 gateway.server = HTTPServer(gateway)
3826
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
450 gateway.public_key_pem = None
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
451 return gateway
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
452
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
453
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
454 class TestActivityPubGateway:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
455
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
456 def getTitleXHTML(self, item_elt: domish.Element) -> domish.Element:
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
457 return next(
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
458 t for t in item_elt.entry.elements(NS_ATOM, "title")
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
459 if t.getAttribute("type") == "xhtml"
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
460 )
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
461
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
462
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
463 @ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
464 async def test_jid_and_node_convert_to_ap_handle(self, ap_gateway):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
465 """JID and pubsub node are converted correctly to an AP actor handle"""
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
466 get_account = ap_gateway.getAPAccountFromJidAndNode
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
467
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
468 # local jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
469 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
470 jid_ = jid.JID("simple@test.example"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
471 node = None
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
472 ) == "simple@test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
473
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
474 # non local jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
475 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
476 jid_ = jid.JID("simple@example.org"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
477 node = None
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
478 ) == "___simple.40example.2eorg@ap.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
479
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
480 # local jid with non microblog node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
481 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
482 jid_ = jid.JID("simple@test.example"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
483 node = "some_other_node"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
484 ) == "some_other_node---simple@test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
485
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
486 # local pubsub node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
487 with patch.object(ap_gateway, "isPubsub") as isPubsub:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
488 isPubsub.return_value = True
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
489 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
490 jid_ = jid.JID("pubsub.test.example"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
491 node = "some_node"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
492 ) == "some_node@pubsub.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
493
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
494 # non local pubsub node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
495 with patch.object(ap_gateway, "isPubsub") as isPubsub:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
496 isPubsub.return_value = True
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
497 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
498 jid_ = jid.JID("pubsub.example.org"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
499 node = "some_node"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
500 ) == "___some_node.40pubsub.2eexample.2eorg@ap.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
501
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
502 @ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
503 async def test_ap_handle_convert_to_jid_and_node(self, ap_gateway, monkeypatch):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
504 """AP actor handle convert correctly to JID and pubsub node"""
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
505 get_jid_node = ap_gateway.getJIDAndNode
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
506
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
507 # for following assertion, host is not a pubsub service
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
508 with patch.object(ap_gateway, "isPubsub") as isPubsub:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
509 isPubsub.return_value = False
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
510
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
511 # simple local jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
512 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
513 "toto@test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
514 ) == (jid.JID("toto@test.example"), None)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
515
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
516 # simple external jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
517
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
518 ## with "local_only" set, it should raise an exception
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
519 with pytest.raises(exceptions.PermissionError):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
520 await get_jid_node("toto@example.org")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
521
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
522 ## with "local_only" unset, it should work
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
523 with monkeypatch.context() as m:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
524 m.setattr(ap_gateway, "local_only", False, raising=True)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
525 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
526 "toto@example.org"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
527 ) == (jid.JID("toto@example.org"), None)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
528
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
529 # explicit node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
530 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
531 "tata---toto@test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
532 ) == (jid.JID("toto@test.example"), "tata")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
533
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
534 # for following assertion, host is a pubsub service
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
535 with patch.object(ap_gateway, "isPubsub") as isPubsub:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
536 isPubsub.return_value = True
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
537
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
538 # simple local node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
539 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
540 "toto@pubsub.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
541 ) == (jid.JID("pubsub.test.example"), "toto")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
542
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
543 # encoded local node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
544 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
545 "___urn.3axmpp.3amicroblog.3a0@pubsub.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
546 ) == (jid.JID("pubsub.test.example"), "urn:xmpp:microblog:0")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
547
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
548 @ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
549 async def test_ap_to_pubsub_conversion(self, ap_gateway, monkeypatch):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
550 """AP requests are converted to pubsub"""
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
551 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
552 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
553 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
554
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
555 actor_data = await ap_gateway.getAPActorDataFromAccount(TEST_AP_ACCOUNT)
3735
04ecc8eeb81a tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents: 3733
diff changeset
556 outbox = await ap_gateway.apGetObject(actor_data, "outbox")
04ecc8eeb81a tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents: 3733
diff changeset
557 items, rsm_resp = await ap_gateway.getAPItems(outbox, 2)
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
558
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
559 assert rsm_resp.count == 4
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
560 assert rsm_resp.index == 0
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
561 assert rsm_resp.first == "https://example.org/users/test_user/statuses/4"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
562 assert rsm_resp.last == "https://example.org/users/test_user/statuses/3"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
563
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
564 title_xhtml = self.getTitleXHTML(items[0])
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
565 assert title_xhtml.toXml() == (
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
566 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
567 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 4</p></div>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
568 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
569 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
570 author_uri = str(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
571 [e for e in items[0].entry.author.elements() if e.name == "uri"][0]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
572 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
573 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
574 assert str(items[0].entry.published) == "2021-12-16T17:25:03Z"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
575
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
576 title_xhtml = self.getTitleXHTML(items[1])
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
577 assert title_xhtml.toXml() == (
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
578 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
579 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
580 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
581 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
582 author_uri = str(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
583 [e for e in items[1].entry.author.elements() if e.name == "uri"][0]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
584 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
585 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
586 assert str(items[1].entry.published) == "2021-12-16T17:26:03Z"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
587
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
588 items, rsm_resp = await ap_gateway.getAPItems(
3735
04ecc8eeb81a tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents: 3733
diff changeset
589 outbox,
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
590 max_items=2,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
591 after_id="https://example.org/users/test_user/statuses/3",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
592 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
593
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
594 assert rsm_resp.count == 4
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
595 assert rsm_resp.index == 2
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
596 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
597 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
598
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
599 title_xhtml = self.getTitleXHTML(items[0])
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
600 assert title_xhtml.toXml() == (
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
601 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
602 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
603 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
604 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
605 author_uri = str(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
606 [e for e in items[0].entry.author.elements() if e.name == "uri"][0]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
607 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
608 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
609 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
610
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
611 title_xhtml = self.getTitleXHTML(items[1])
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
612 assert title_xhtml.toXml() == (
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
613 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
614 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
615 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
616 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
617 author_uri = str(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
618 [e for e in items[1].entry.author.elements() if e.name == "uri"][0]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
619 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
620 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
621 assert str(items[1].entry.published) == "2021-12-16T17:28:03Z"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
622
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
623 items, rsm_resp = await ap_gateway.getAPItems(
3735
04ecc8eeb81a tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents: 3733
diff changeset
624 outbox,
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
625 max_items=1,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
626 start_index=2
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
627 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
628
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
629 assert rsm_resp.count == 4
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
630 assert rsm_resp.index == 2
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
631 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
632 assert rsm_resp.last == "https://example.org/users/test_user/statuses/2"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
633 assert len(items) == 1
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
634
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
635 title_xhtml = self.getTitleXHTML(items[0])
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
636 assert title_xhtml.toXml() == (
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
637 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
638 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
639 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
640 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
641 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
642
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
643 items, rsm_resp = await ap_gateway.getAPItems(
3735
04ecc8eeb81a tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents: 3733
diff changeset
644 outbox,
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
645 max_items=3,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
646 chronological_pagination=False
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
647 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
648 assert rsm_resp.count == 4
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
649 assert rsm_resp.index == 1
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
650 assert rsm_resp.first == "https://example.org/users/test_user/statuses/3"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
651 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
652 assert len(items) == 3
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
653 title_xhtml = self.getTitleXHTML(items[0])
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
654 assert title_xhtml.toXml() == (
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
655 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
656 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
657 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
658 )
3783
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
659 title_xhtml = self.getTitleXHTML(items[2])
fedbf7aade11 tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents: 3770
diff changeset
660 assert title_xhtml.toXml() == (
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
661 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
662 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
663 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
664 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
665
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
666 def ap_request_params(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
667 self,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
668 ap_gateway,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
669 type_: Optional[str] = None,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
670 url: Optional[str] = None,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
671 doc: Optional[Any] = None,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
672 query_data: Optional[dict] = None,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
673 signing_actor: Optional[str] = None
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
674 ) -> Dict[str, Any]:
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
675 """Generate parameters for HTTPAPGServer's AP*Request
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
676
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
677 @param type_: one of the AP query type (e.g. "outbox")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
678 @param url: URL to query (mutually exclusif with type_)
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
679 @param doc: if set, a document to embed in content of the request (will be
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
680 converted to JSON)
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
681 @param query_data: query data as returned by parse.parse_qs
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
682 @return dict with kw params to use
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
683 """
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
684 assert type_ and url is None or url and type_ is None
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
685 if type_ is not None:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
686 path = f"_ap/{type_}/some_user%40test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
687 else:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
688 url_parsed = parse.urlparse(url)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
689 path = url_parsed.path.lstrip("/")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
690 type_ = path.split("/")[1]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
691 if query_data is None:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
692 query_data = parse.parse_qs(url_parsed.query)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
693
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
694 if query_data:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
695 uri = f"{path}?{parse.urlencode(query_data, doseq=True)}"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
696 else:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
697 uri = path
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
698
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
699 test_jid = jid.JID("some_user@test.example")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
700 request = Request(MagicMock())
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
701 request.path = path.encode()
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
702 request.uri = uri.encode()
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
703 if doc is not None:
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
704 request.content = io.BytesIO(json.dumps(doc).encode())
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
705
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
706 ap_url = parse.urljoin(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
707 f"https://{ap_gateway.public_url}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
708 path
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
709 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
710 kwargs = {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
711 "request": request,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
712 "account_jid": test_jid,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
713 "node": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
714 "ap_account": test_jid.full(),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
715 "ap_url": ap_url,
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
716 "signing_actor": signing_actor
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
717 }
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
718 if type_ == "outbox" and query_data:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
719 kwargs["query_data"] = query_data
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
720 # signing_actor is not used for page requests
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
721 del kwargs["signing_actor"]
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
722 return kwargs
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
723
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
724 @ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
725 async def test_pubsub_to_ap_conversion(self, ap_gateway, monkeypatch):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
726 """Pubsub nodes are converted to AP collections"""
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
727 monkeypatch.setattr(ap_gateway._p, "getItems", mock_getItems)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
728 outbox = await ap_gateway.server.resource.APOutboxRequest(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
729 **self.ap_request_params(ap_gateway, "outbox")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
730 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
731 assert outbox["@context"] == "https://www.w3.org/ns/activitystreams"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
732 assert outbox["id"] == "https://test.example/_ap/outbox/some_user%40test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
733 assert outbox["totalItems"] == len(XMPP_ITEMS)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
734 assert outbox["type"] == "OrderedCollection"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
735 assert outbox["first"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
736 assert outbox["last"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
737
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
738 first_page = await ap_gateway.server.resource.APOutboxPageRequest(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
739 **self.ap_request_params(ap_gateway, url=outbox["first"])
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
740 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
741 assert first_page["@context"] == "https://www.w3.org/ns/activitystreams"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
742 assert first_page["id"] == "https://test.example/_ap/outbox/some_user%40test.example?page=first"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
743 assert first_page["type"] == "OrderedCollectionPage"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
744 assert first_page["partOf"] == outbox["id"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
745 assert len(first_page["orderedItems"]) == len(XMPP_ITEMS)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
746 first_item = first_page["orderedItems"][0]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
747 assert first_item["@context"] == "https://www.w3.org/ns/activitystreams"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
748 assert first_item["id"] == "https://test.example/_ap/item/some_user%40test.example/4"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
749 assert first_item["actor"] == "https://test.example/_ap/actor/some_user%40test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
750 assert first_item["type"] == "Create"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
751 first_item_obj = first_item["object"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
752 assert first_item_obj["id"] == first_item["id"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
753 assert first_item_obj["type"] == "Note"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
754 assert first_item_obj["published"] == "2022-01-28T16:02:19Z"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
755 assert first_item_obj["attributedTo"] == first_item["actor"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
756 assert first_item_obj["content"] == "<div><p>XMPP item 4</p></div>"
3770
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
757 assert first_item_obj["to"] == ["https://www.w3.org/ns/activitystreams#Public"]
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
758
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
759 @ed
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
760 async def test_following_to_pps(self, ap_gateway, monkeypatch):
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
761 """AP following items are converted to Public Pubsub Subscription subscriptions"""
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
762 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
763 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
764 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
765
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
766 items, __ = await ap_gateway.pubsub_service.items(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
767 jid.JID("toto@example.org"),
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
768 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT),
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
769 ap_gateway._pps.subscriptions_node,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
770 None,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
771 None,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
772 None
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
773 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
774 assert len(items) == 2
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
775 for idx, entity in enumerate((
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
776 "local_user@test.example",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
777 "ext_user\\40example.org@ap.test.example"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
778 )):
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
779 subscription_elt = next(items[idx].elements(NS_PPS, "subscription"), None)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
780 assert subscription_elt is not None
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
781 assert subscription_elt["node"] == ap_gateway._m.namespace
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
782 assert subscription_elt["service"] == entity
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
783
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
784 @ed
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
785 async def test_followers_to_pps(self, ap_gateway, monkeypatch):
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
786 """AP followers items are converted to Public Pubsub Subscription subscribers"""
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
787 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
788 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
789 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
790
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
791 items, __ = await ap_gateway.pubsub_service.items(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
792 jid.JID("toto@example.org"),
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
793 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT),
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
794 ap_gateway._pps.getPublicSubscribersNode(ap_gateway._m.namespace),
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
795 None,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
796 None,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
797 None
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
798 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
799 assert len(items) == 2
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
800 for idx, entity in enumerate((
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
801 "local_user@test.example",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
802 "ext_user\\40example.org@ap.test.example"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
803 )):
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
804 subscriber_elt = next(items[idx].elements(NS_PPS, "subscriber"), None)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
805 assert subscriber_elt is not None
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
806 assert subscriber_elt["jid"] == entity
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
807
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
808 @ed
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
809 async def test_pps_to_following(self, ap_gateway, monkeypatch):
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
810 """Public Pubsub Subscription subscriptions are converted to AP following items"""
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
811 subscriptions = [
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
812 pubsub.Item(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
813 id="subscription_1",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
814 payload = ap_gateway._pps.buildSubscriptionElt(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
815 ap_gateway._m.namespace,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
816 jid.JID("local_user@test.example")
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
817 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
818 ),
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
819 pubsub.Item(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
820 id="subscription_2",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
821 payload = ap_gateway._pps.buildSubscriptionElt(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
822 ap_gateway._m.namespace,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
823 jid.JID("ext_user\\40example.org@ap.test.example")
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
824 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
825 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
826 ]
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
827 monkeypatch.setattr(ap_gateway._p, "getItems", partial(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
828 mock_getItems,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
829 ret_items=subscriptions
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
830 ))
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
831 following = await ap_gateway.server.resource.APFollowingRequest(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
832 **self.ap_request_params(ap_gateway, "following")
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
833 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
834 assert following["@context"] == "https://www.w3.org/ns/activitystreams"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
835 assert following["id"] == "https://test.example/_ap/following/some_user%40test.example"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
836 assert following["totalItems"] == len(subscriptions)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
837 assert following["type"] == "OrderedCollection"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
838 assert following.get("first")
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
839
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
840 first_page = following["first"]
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
841 assert first_page["type"] == "OrderedCollectionPage"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
842 assert len(first_page["orderedItems"]) == len(subscriptions)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
843 items = first_page["orderedItems"]
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
844 assert items == ['local_user@test.example', 'ext_user@example.org']
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
845
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
846 @ed
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
847 async def test_pps_to_followers(self, ap_gateway, monkeypatch):
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
848 """Public Pubsub Subscription subscribers are converted to AP followers"""
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
849 subscribers = [
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
850 pubsub.Item(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
851 id="subscriber_1",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
852 payload = ap_gateway._pps.buildSubscriberElt(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
853 jid.JID("local_user@test.example")
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
854 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
855 ),
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
856 pubsub.Item(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
857 id="subscriber_2",
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
858 payload = ap_gateway._pps.buildSubscriberElt(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
859 jid.JID("ext_user\\40example.org@ap.test.example")
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
860 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
861 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
862 ]
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
863 monkeypatch.setattr(ap_gateway._p, "getItems", partial(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
864 mock_getItems,
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
865 ret_items=subscribers
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
866 ))
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
867 followers = await ap_gateway.server.resource.APFollowersRequest(
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
868 **self.ap_request_params(ap_gateway, "followers")
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
869 )
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
870 assert followers["@context"] == "https://www.w3.org/ns/activitystreams"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
871 assert followers["id"] == "https://test.example/_ap/followers/some_user%40test.example"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
872 assert followers["totalItems"] == len(subscribers)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
873 assert followers["type"] == "OrderedCollection"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
874 assert followers.get("first")
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
875
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
876 first_page = followers["first"]
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
877 assert first_page["type"] == "OrderedCollectionPage"
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
878 assert len(first_page["orderedItems"]) == len(subscribers)
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
879 items = first_page["orderedItems"]
f31113777881 tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents: 3735
diff changeset
880 assert items == ['local_user@test.example', 'ext_user@example.org']
3785
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
881
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
882 @ed
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
883 async def test_xmpp_message_to_ap_direct_message(self, ap_gateway, monkeypatch):
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
884 """XMPP message are sent as AP direct message"""
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
885 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
886 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
887 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
3808
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
888 mess_data = {
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
889 "from": TEST_JID,
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
890 "to": ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT),
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
891 "type": "chat",
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
892 "message": {"": "This is a test message."},
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
893 "extra": {
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
894 "origin-id": "123"
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
895 }
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
896 }
3785
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
897 with patch.object(ap_gateway, "signAndPost") as signAndPost:
3808
39fc2e1b3793 tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents: 3785
diff changeset
898 await ap_gateway.onMessage(ap_gateway.client, mess_data)
3785
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
899 url, actor_id, doc = signAndPost.call_args[0]
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
900 assert url == "https://example.org/users/test_user/inbox"
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
901 assert actor_id == "https://test.example/_ap/actor/some_user%40test.example"
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
902 obj = doc["object"]
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
903 assert doc["@context"] == "https://www.w3.org/ns/activitystreams"
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
904 assert doc["actor"] == "https://test.example/_ap/actor/some_user%40test.example"
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
905 assert obj["type"] == "Note"
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
906 assert obj["content"] == "This is a test message."
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
907 assert obj["attributedTo"] == (
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
908 "https://test.example/_ap/actor/some_user%40test.example"
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
909 )
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
910 # we must have a direct message, thus the item must be only addressed to destinee
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
911 # ("to" attribute of the message), and the "Public" namespace must not be set
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
912 assert doc["to"] == ["https://example.org/users/test_user"]
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
913 assert obj["to"] == ["https://example.org/users/test_user"]
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
914 for field in ("bto", "cc", "bcc", "audience"):
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
915 assert field not in doc
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
916 assert field not in obj
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
917
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
918 @ed
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
919 async def test_ap_direct_message_to_xmpp_message(self, ap_gateway, monkeypatch):
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
920 """AP direct message are sent as XMPP message (not Pubsub)"""
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
921 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
922 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
923 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
924 # we have to patch DeferredList to not wait forever
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
925 monkeypatch.setattr(defer, "DeferredList", AsyncMock())
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
926
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
927 xmpp_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost())
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
928 direct_ap_message = {
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
929 'attributedTo': TEST_AP_ACTOR_ID,
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
930 'cc': [],
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
931 'content': '<p>test direct message</p>',
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
932 'contentMap': {'en': '<p>test direct message</p>'},
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
933 'id': f'{TEST_AP_ACTOR_ID}/statuses/123',
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
934 'published': '2022-05-20T08:14:39Z',
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
935 'to': [xmpp_actor_id],
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
936 'type': 'Note',
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
937 }
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
938 client = ap_gateway.client.getVirtualClient(
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
939 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
940 )
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
941 with patch.object(client, "sendMessage") as sendMessage:
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
942 await ap_gateway.newAPItem(
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
943 client, None, ap_gateway._m.namespace, direct_ap_message
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
944 )
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
945
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
946 # sendMessage must be called for <message> stanza, and the "message" argument must
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
947 # be set to the content of the original AP message
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
948 assert sendMessage.called
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
949 assert sendMessage.call_args.args[0] == TEST_JID
0b54be42d0aa test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents: 3783
diff changeset
950 assert sendMessage.call_args.args[1] == {"": "test direct message"}
3809
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
951
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
952 @ed
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
953 async def test_pubsub_retract_to_ap_delete(self, ap_gateway, monkeypatch):
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
954 """Pubsub retract requests are converted to AP delete activity"""
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
955 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
956 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
957 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
958 retract_id = "retract_123"
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
959 retract_elt = domish.Element((pubsub.NS_PUBSUB_EVENT, "retract"))
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
960 retract_elt["id"] = retract_id
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
961 items_event = pubsub.ItemsEvent(
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
962 sender=TEST_JID,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
963 recipient=ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT),
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
964 nodeIdentifier=ap_gateway._m.namespace,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
965 items=[retract_elt],
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
966 headers={}
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
967 )
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
968 with patch.object(ap_gateway, "signAndPost") as signAndPost:
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
969 signAndPost.return_value = FakeTReqPostResponse()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
970 # we simulate the reception of a retract event
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
971 await ap_gateway._itemsReceived(ap_gateway.client, items_event)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
972 url, actor_id, doc = signAndPost.call_args[0]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
973 jid_account = await ap_gateway.getAPAccountFromJidAndNode(TEST_JID, None)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
974 jid_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, jid_account)
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
975 assert url == f"{TEST_BASE_URL}/inbox"
3809
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
976 assert actor_id == jid_actor_id
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
977 assert doc["type"] == "Delete"
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
978 assert doc["actor"] == jid_actor_id
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
979 obj = doc["object"]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
980 assert obj["type"] == ap_const.TYPE_TOMBSTONE
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
981 url_item_id = ap_gateway.buildAPURL(ap_const.TYPE_ITEM, jid_account, retract_id)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
982 assert obj["id"] == url_item_id
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
983
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
984 @ed
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
985 async def test_ap_delete_to_pubsub_retract(self, ap_gateway):
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
986 """AP delete activity is converted to pubsub retract"""
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
987 client = ap_gateway.client.getVirtualClient(
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
988 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
989 )
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
990
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
991 ap_item = {
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
992 "@context": "https://www.w3.org/ns/activitystreams",
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
993 "actor": TEST_AP_ACTOR_ID,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
994 "id": "https://test.example/retract_123",
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
995 "type": "Delete",
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
996 "object": {"id": f"{TEST_AP_ACTOR_ID}/item/123",
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
997 "type": "Tombstone"},
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
998 "to": ["https://www.w3.org/ns/activitystreams#Public"]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
999 }
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1000 with patch.multiple(
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1001 ap_gateway.host.memory.storage,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1002 get=DEFAULT,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1003 getPubsubNode=DEFAULT,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1004 deletePubsubItems=DEFAULT,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1005 ) as mock_objs:
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1006 mock_objs["get"].return_value=None
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1007 cached_node = MagicMock()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1008 mock_objs["getPubsubNode"].return_value=cached_node
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1009 subscription = MagicMock()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1010 subscription.state = SubscriptionState.SUBSCRIBED
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1011 subscription.subscriber = TEST_JID
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1012 cached_node.subscriptions = [subscription]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1013 with patch.object(
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1014 ap_gateway.pubsub_service, "notifyRetract"
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1015 ) as notifyRetract:
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1016 # we simulate a received Delete activity
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1017 await ap_gateway.newAPDeleteItem(
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1018 client=client,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1019 destinee=None,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1020 node=ap_gateway._m.namespace,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1021 item=ap_item
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1022 )
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1023
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1024 # item is deleted from database
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1025 deletePubsubItems = mock_objs["deletePubsubItems"]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1026 assert deletePubsubItems.call_count == 1
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1027 assert deletePubsubItems.call_args.args[1] == [ap_item["id"]]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1028
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1029 # retraction notification is sent to subscribers
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1030 assert notifyRetract.call_count == 1
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1031 assert notifyRetract.call_args.args[0] == client.jid
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1032 assert notifyRetract.call_args.args[1] == ap_gateway._m.namespace
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1033 notifications = notifyRetract.call_args.args[2]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1034 assert len(notifications) == 1
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1035 subscriber, __, item_elts = notifications[0]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1036 assert subscriber == TEST_JID
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1037 assert len(item_elts) == 1
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1038 item_elt = item_elts[0]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1039 assert isinstance(item_elt, domish.Element)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1040 assert item_elt.name == "item"
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1041 assert item_elt["id"] == ap_item["id"]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1042
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1043 @ed
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1044 async def test_message_retract_to_ap_delete(self, ap_gateway, monkeypatch):
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1045 """Message retract requests are converted to AP delete activity"""
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1046 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1047 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1048 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1049 # origin ID is the ID of the message to retract
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1050 origin_id = "mess_retract_123"
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1051
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1052 # we call retractByOriginId to get the message element of a retraction request
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1053 fake_client = MagicMock()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1054 fake_client.jid = TEST_JID
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1055 dest_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1056 ap_gateway._r.retractByOriginId(fake_client, dest_jid, origin_id)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1057 # message_retract_elt is the message which would be sent for a retraction
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1058 message_retract_elt = fake_client.send.call_args.args[0]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1059 apply_to_elt = next(message_retract_elt.elements(NS_FASTEN, "apply-to"))
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1060 retract_elt = apply_to_elt.retract
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1061
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1062 with patch.object(ap_gateway, "signAndPost") as signAndPost:
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1063 signAndPost.return_value = FakeTReqPostResponse()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1064 fake_fastened_elts = MagicMock()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1065 fake_fastened_elts.id = origin_id
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1066 # we simulate the reception of a retract event using the message element that
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1067 # we generated above
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1068 await ap_gateway._onMessageRetract(
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1069 ap_gateway.client,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1070 message_retract_elt,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1071 retract_elt,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1072 fake_fastened_elts
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1073 )
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1074 url, actor_id, doc = signAndPost.call_args[0]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1075
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1076 # the AP delete activity must have been sent through signAndPost
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1077 # we check its values
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1078 jid_account = await ap_gateway.getAPAccountFromJidAndNode(TEST_JID, None)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1079 jid_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, jid_account)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1080 assert url == f"{TEST_BASE_URL}/users/{TEST_USER}/inbox"
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1081 assert actor_id == jid_actor_id
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1082 assert doc["type"] == "Delete"
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1083 assert doc["actor"] == jid_actor_id
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1084 obj = doc["object"]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1085 assert obj["type"] == ap_const.TYPE_TOMBSTONE
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1086 url_item_id = ap_gateway.buildAPURL(ap_const.TYPE_ITEM, jid_account, origin_id)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1087 assert obj["id"] == url_item_id
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1088
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1089 @ed
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1090 async def test_ap_delete_to_message_retract(self, ap_gateway, monkeypatch):
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1091 """AP delete activity is converted to message retract"""
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1092 # note: a message retract is used when suitable message is found in history,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1093 # otherwise it should be in pubsub cache and it's a pubsub retract (tested above
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1094 # by ``test_ap_delete_to_pubsub_retract``)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1095
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1096 # we don't want actual queries in database
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1097 retractDBHistory = AsyncMock()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1098 monkeypatch.setattr(ap_gateway._r, "retractDBHistory", retractDBHistory)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1099
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1100 client = ap_gateway.client.getVirtualClient(
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1101 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1102 )
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1103 fake_send = MagicMock()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1104 monkeypatch.setattr(client, "send", fake_send)
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1105
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1106 ap_item = {
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1107 "@context": "https://www.w3.org/ns/activitystreams",
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1108 "actor": TEST_AP_ACTOR_ID,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1109 "id": "https://test.example/retract_123",
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1110 "type": "Delete",
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1111 "object": {"id": f"{TEST_AP_ACTOR_ID}/item/123",
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1112 "type": "Tombstone"},
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1113 "to": ["https://www.w3.org/ns/activitystreams#Public"]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1114 }
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1115 with patch.object(ap_gateway.host.memory.storage, "get") as storage_get:
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1116 fake_history = MagicMock()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1117 fake_history.source_jid = client.jid
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1118 fake_history.dest_jid = TEST_JID
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1119 fake_history.origin_id = ap_item["id"]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1120 storage_get.return_value = fake_history
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1121 # we simulate a received Delete activity
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1122 await ap_gateway.newAPDeleteItem(
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1123 client=client,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1124 destinee=None,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1125 node=ap_gateway._m.namespace,
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1126 item=ap_item
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1127 )
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1128
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1129 # item is deleted from database
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1130 assert retractDBHistory.call_count == 1
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1131 assert retractDBHistory.call_args.args[0] == client
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1132 assert retractDBHistory.call_args.args[1] == fake_history
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1133
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1134 # retraction notification is sent to destinee
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1135 assert fake_send.call_count == 1
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1136 sent_elt = fake_send.call_args.args[0]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1137 assert sent_elt.name == "message"
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1138 assert sent_elt["from"] == client.jid.full()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1139 assert sent_elt["to"] == TEST_JID.full()
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1140 apply_to_elt = next(sent_elt.elements(NS_FASTEN, "apply-to"))
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1141 assert apply_to_elt["id"] == ap_item["id"]
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1142 retract_elt = apply_to_elt.retract
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1143 assert retract_elt is not None
04b57c0b2278 tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents: 3808
diff changeset
1144 assert retract_elt.uri == NS_MESSAGE_RETRACT
3826
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1145
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1146 @ed
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1147 async def test_ap_actor_metadata_to_vcard(self, ap_gateway, monkeypatch):
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1148 """AP actor metadata are converted to XMPP/vCard4"""
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1149 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1150 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1151 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1152
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1153 items, __ = await ap_gateway.pubsub_service.items(
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1154 jid.JID("toto@example.org"),
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1155 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT),
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1156 # VCard4 node
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1157 ap_gateway._v.node,
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1158 None,
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1159 None,
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1160 None
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1161 )
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1162 assert len(items) == 1
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1163 vcard_elt = next(items[0].elements(ap_gateway._v.namespace, "vcard"))
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1164 vcard = ap_gateway._v.vcard2Dict(vcard_elt)
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1165 assert "test_user nickname" in vcard["nicknames"]
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1166 assert vcard["description"] == "test account"
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1167
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1168 @ed
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1169 async def test_identity_data_to_ap_actor_metadata(self, ap_gateway):
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1170 """XMPP identity is converted to AP actor metadata"""
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1171 # XXX: XMPP identity is normally an amalgam of metadata from several
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1172 # XEPs/locations (vCard4, vcard-tmp, etc)
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1173 with patch.object(ap_gateway._i, "getIdentity") as getIdentity:
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1174 getIdentity.return_value = {
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1175 "nicknames": ["nick1", "nick2"],
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1176 "description": "test description"
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1177 }
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1178 actor_data = await ap_gateway.server.resource.APActorRequest(
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1179 **self.ap_request_params(ap_gateway, ap_const.TYPE_ACTOR)
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1180 )
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1181
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1182 # only the first nickname should be used
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1183 assert actor_data["name"] == "nick1"
81c79b7cafa7 tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents: 3809
diff changeset
1184 assert actor_data["summary"] == "test description"
3837
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1185
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1186 @ed
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1187 async def test_direct_addressing_mention_to_reference(self, ap_gateway, monkeypatch):
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1188 """AP mentions by direct addressing are converted to XEP-0372 references"""
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1189 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1190 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1191 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1192
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1193 xmpp_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost())
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1194
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1195 direct_addr_mention = {
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1196 'attributedTo': TEST_AP_ACTOR_ID,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1197 'cc': [],
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1198 'content': '<p>test mention by direct addressing</p>',
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1199 'id': f'{TEST_AP_ACTOR_ID}/statuses/direct_addr_123',
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1200 'published': '2022-05-20T08:14:39Z',
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1201 'to': [ap_const.NS_AP_PUBLIC, xmpp_actor_id],
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1202 'type': 'Note'
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1203 }
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1204 client = ap_gateway.client.getVirtualClient(
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1205 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1206 )
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1207 monkeypatch.setattr(client, "sendMessage", MagicMock())
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1208
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1209 with patch.object(ap_gateway._refs, "sendReference") as sendReference:
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1210 await ap_gateway.newAPItem(
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1211 client, None, ap_gateway._m.namespace, direct_addr_mention
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1212 )
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1213
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1214 assert sendReference.call_count == 1
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1215 assert sendReference.call_args.kwargs["to_jid"] == TEST_JID
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1216
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1217 local_actor_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1218 expected_anchor = xmpp_uri.buildXMPPUri(
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1219 "pubsub",
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1220 path=local_actor_jid.full(),
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1221 node=ap_gateway._m.namespace,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1222 item=direct_addr_mention["id"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1223 )
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1224
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1225 assert sendReference.call_args.kwargs["anchor"] == expected_anchor
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1226
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1227 @ed
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1228 async def test_tag_mention_to_reference(self, ap_gateway, monkeypatch):
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1229 """AP mentions in "tag" field are converted to XEP-0372 references"""
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1230 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1231 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1232 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1233
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1234 xmpp_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost())
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1235
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1236 direct_addr_mention = {
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1237 'attributedTo': TEST_AP_ACTOR_ID,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1238 'cc': [],
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1239 'content': '<p>test mention by tag</p>',
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1240 'id': f'{TEST_AP_ACTOR_ID}/statuses/tag_123',
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1241 'published': '2022-05-20T08:14:39Z',
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1242 'to': [ap_const.NS_AP_PUBLIC],
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1243 "tag": [
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1244 {
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1245 "type": "Mention",
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1246 "href": xmpp_actor_id,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1247 "name": f"@{TEST_JID}'"
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1248 }
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1249 ],
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1250 'type': 'Note'
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1251 }
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1252 client = ap_gateway.client.getVirtualClient(
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1253 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1254 )
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1255 monkeypatch.setattr(client, "sendMessage", MagicMock())
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1256
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1257 with patch.object(ap_gateway._refs, "sendReference") as sendReference:
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1258 await ap_gateway.newAPItem(
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1259 client, None, ap_gateway._m.namespace, direct_addr_mention
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1260 )
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1261
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1262 assert sendReference.call_count == 1
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1263 assert sendReference.call_args.kwargs["to_jid"] == TEST_JID
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1264
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1265 local_actor_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1266 expected_anchor = xmpp_uri.buildXMPPUri(
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1267 "pubsub",
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1268 path=local_actor_jid.full(),
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1269 node=ap_gateway._m.namespace,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1270 item=direct_addr_mention["id"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1271 )
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1272
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1273 assert sendReference.call_args.kwargs["anchor"] == expected_anchor
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1274
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1275 @ed
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1276 async def test_auto_mentions(self, ap_gateway, monkeypatch):
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1277 """Check that mentions in body are converted to AP mentions"""
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1278 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1279 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1280 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1281
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1282 mb_data = {
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1283 "author_jid": TEST_JID.full(),
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1284 "content": f"mention of @{TEST_AP_ACCOUNT}",
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1285 "service": TEST_JID.full(),
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1286 "node": ap_gateway._m.namespace
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1287 }
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1288 ap_item = await ap_gateway.mbdata2APitem(ap_gateway.client, mb_data, public=True)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1289
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1290 ap_object = ap_item["object"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1291 assert TEST_AP_ACTOR_ID in ap_object["to"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1292 expected_mention = {
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1293 "type": ap_const.TYPE_MENTION,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1294 "href": TEST_AP_ACTOR_ID,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1295 "name": f"@{TEST_AP_ACCOUNT}"
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1296 }
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1297 assert expected_mention in ap_object["tag"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1298
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1299 @ed
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1300 async def test_no_auto_mentions_when_not_public(self, ap_gateway, monkeypatch):
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1301 """Check that no mention is send when the message is not public"""
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1302 # this is the same test as test_auto_mentions above, except that public is not set
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1303 # in mbdata2APitem
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1304 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1305 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1306 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1307
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1308 mb_data = {
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1309 "author_jid": TEST_JID.full(),
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1310 "content": f"mention of @{TEST_AP_ACCOUNT}",
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1311 "service": TEST_JID.full(),
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1312 "node": ap_gateway._m.namespace
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1313 }
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1314 ap_item = await ap_gateway.mbdata2APitem(ap_gateway.client, mb_data, public=False)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1315
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1316 ap_object = ap_item["object"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1317 assert "to" not in ap_object
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1318 assert "tag" not in ap_object
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1319
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1320 @ed
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1321 async def test_xmpp_reference_to_ap_mention(self, ap_gateway, monkeypatch):
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1322 """Check that XEP-0372 references are converted to AP mention"""
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1323 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1324 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1325 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1326
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1327 local_actor_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1328 item_elt = XMPP_ITEMS[0]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1329 anchor = xmpp_uri.buildXMPPUri(
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1330 "pubsub",
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1331 path=TEST_JID.full(),
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1332 node=ap_gateway._m.namespace,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1333 item=item_elt["id"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1334 )
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1335
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1336 ref_data: Dict[str, Union[str, int, dict]] = {
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1337 "uri": xmpp_uri.buildXMPPUri(None, path=local_actor_jid.full()),
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1338 "type_": "mention",
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1339 "anchor": anchor
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1340 }
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1341 reference_elt = ap_gateway._refs.buildRefElement(**ref_data)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1342
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1343 # we now update ref_data to look like what is received in the trigger
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1344
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1345 ref_data["parsed_uri"] = xmpp_uri.parseXMPPUri(ref_data["uri"])
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1346 ref_data["parsed_anchor"] = xmpp_uri.parseXMPPUri(ref_data["anchor"])
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1347
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1348 # "type" is a builtin function, thus "type_" is used in buildRefElement, but in
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1349 # ref_data is "type" without underscore
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1350 ref_data["type"] = ref_data["type_"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1351 del ref_data["type_"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1352
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1353 message_elt = domish.Element((None, "message"))
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1354 message_elt.addChild(reference_elt)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1355
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1356 with patch.object(ap_gateway.host.memory.storage, "getItems") as getItems:
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1357 # getItems returns a sqla_mapping.PubsubItem, thus we need to fake it and set
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1358 # the item_elt we want to use in its "data" attribute
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1359 mock_pubsub_item = MagicMock
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1360 mock_pubsub_item.data = item_elt
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1361 getItems.return_value = ([mock_pubsub_item], {})
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1362 with patch.object(ap_gateway, "signAndPost") as signAndPost:
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1363 signAndPost.return_value.code = 202
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1364 await ap_gateway._onReferenceReceived(ap_gateway.client, message_elt, ref_data)
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1365
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1366 # when reference is received, the referencing item must be sent to referenced
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1367 # actor, and they must be in "to" field and in "tag"
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1368 assert signAndPost.call_count == 1
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1369 send_ap_item = signAndPost.call_args.args[-1]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1370 ap_object = send_ap_item["object"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1371 assert TEST_AP_ACTOR_ID in ap_object["to"]
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1372 expected_mention = {
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1373 "type": ap_const.TYPE_MENTION,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1374 "href": TEST_AP_ACTOR_ID,
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1375 # we don't have a prefixing "@" here, because it's not needed in referencing
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1376 # item with XMPP
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1377 "name": f"{TEST_AP_ACCOUNT}"
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1378 }
56720561f45f test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents: 3826
diff changeset
1379 assert expected_mention in ap_object["tag"]
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1380
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1381 @ed
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1382 async def test_xmpp_repeat_to_ap_announce(self, ap_gateway, monkeypatch):
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1383 """XEP-0272 post repeat is converted to AP Announce activity"""
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1384 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1385 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1386 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1387
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1388 # JID repeated AP actor (also the recipient of the message)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1389 recipient_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1390 # repeated item
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1391 ap_item = TEST_AP_ITEMS[0]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1392 ap_item_url = xmpp_uri.buildXMPPUri(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1393 "pubsub",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1394 path=recipient_jid.full(),
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1395 node=ap_gateway._m.namespace,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1396 item=ap_item["id"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1397 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1398 item_elt = xml_tools.parse(f"""
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1399 <item id="123" publisher="{TEST_JID}/res.123">
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1400 <entry xmlns="http://www.w3.org/2005/Atom">
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1401 <title type="text">test message 1</title>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1402 <title type="xhtml">
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1403 <div xmlns="http://www.w3.org/1999/xhtml">
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1404 <p>test message 1</p>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1405 </div>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1406 </title>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1407 <author>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1408 <name>test_user</name>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1409 <uri>xmpp:{recipient_jid}</uri>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1410 </author>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1411 <updated>2022-07-21T14:38:53Z</updated>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1412 <published>2022-07-21T14:38:53Z</published>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1413 <id>{ap_item["id"]}</id>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1414 <link href="{ap_item_url}" rel="via"/>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1415 </entry>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1416 </item>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1417 """)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1418 item_elt.uri = pubsub.NS_PUBSUB_EVENT
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1419
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1420 with patch.object(ap_gateway, "signAndPost") as signAndPost:
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1421 signAndPost.return_value.code = 202
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1422 await ap_gateway.convertAndPostItems(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1423 ap_gateway.client,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1424 TEST_AP_ACCOUNT,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1425 TEST_JID,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1426 ap_gateway._m.namespace,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1427 [item_elt]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1428 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1429
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1430 assert signAndPost.called
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1431 url, actor_id, doc = signAndPost.call_args.args
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
1432 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"]
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1433 assert actor_id == ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost())
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1434 assert doc["type"] == "Announce"
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1435 assert ap_const.NS_AP_PUBLIC in doc["to"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1436 assert doc["object"] == ap_item["id"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1437
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1438 @ed
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1439 async def test_ap_announce_to_xmpp_repeat(self, ap_gateway, monkeypatch):
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1440 """AP Announce activity is converted to XEP-0272 post repeat"""
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1441 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1442 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1443 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1444
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1445 xmpp_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost())
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1446 # announced item
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1447 xmpp_item = XMPP_ITEMS[0]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1448 xmpp_item_url = ap_gateway.buildAPURL(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1449 ap_const.TYPE_ITEM, TEST_JID.userhost(), xmpp_item["id"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1450 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1451 announce = {
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1452 "@context": "https://www.w3.org/ns/activitystreams",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1453 "type": "Announce",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1454 "actor": TEST_AP_ACTOR_ID,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1455 "cc": [
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1456 xmpp_actor_id,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1457 TEST_USER_DATA["followers"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1458 ],
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1459 "id": "https://example.org/announce/123",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1460 "object": xmpp_item_url,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1461 "published": "2022-07-22T09:24:12Z",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1462 "to": [ap_const.NS_AP_PUBLIC]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1463 }
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1464 with patch.object(ap_gateway.host.memory.storage, "getItems") as getItems:
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1465 mock_pubsub_item = MagicMock
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1466 mock_pubsub_item.data = xmpp_item
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1467 getItems.return_value = ([mock_pubsub_item], {})
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1468 with patch.object(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1469 ap_gateway.host.memory.storage,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1470 "cachePubsubItems") as cachePubsubItems:
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1471 await ap_gateway.server.resource.handleAnnounceActivity(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1472 Request(MagicMock()),
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1473 announce,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1474 None,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1475 None,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1476 None,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1477 "",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1478 TEST_AP_ACTOR_ID
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1479 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1480
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1481 assert cachePubsubItems.called
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1482 # the microblog data put in cache correspond to the item sent to subscribers
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1483 __, __, __, [mb_data] = cachePubsubItems.call_args.args
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1484 extra = mb_data["extra"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1485 assert "repeated" in extra
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1486 repeated = extra["repeated"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1487 assert repeated["by"] == ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT).full()
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1488 xmpp_item_xmpp_url = xmpp_uri.buildXMPPUri(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1489 "pubsub",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1490 path=TEST_JID.full(),
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1491 node=ap_gateway._m.namespace,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1492 item=xmpp_item["id"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1493 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1494 assert repeated["uri"] == xmpp_item_xmpp_url
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1495
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1496 @ed
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1497 async def test_xmpp_attachment_noticed_to_ap_like(self, ap_gateway, monkeypatch):
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1498 """Pubsub-attachments ``noticed`` is converted to AP Like activity"""
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1499 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1500 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1501 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1502
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1503 recipient_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1504 # noticed item
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1505 ap_item = TEST_AP_ITEMS[0]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1506 attachment_node = ap_gateway._pa.getAttachmentNodeName(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1507 recipient_jid,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1508 ap_gateway._m.namespace,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1509 ap_item["id"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1510 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1511 item_elt = xml_tools.parse(f"""
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1512 <item id="{TEST_JID.userhost()}" published="{TEST_JID.userhostJID()}">
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
1513 <attachments xmlns="urn:xmpp:pubsub-attachments:1">
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1514 <noticed timestamp="2022-07-22T12:29:45Z"/>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1515 </attachments>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1516 </item>
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1517 """)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1518 item_elt.uri = pubsub.NS_PUBSUB_EVENT
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1519 items_event = pubsub.ItemsEvent(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1520 TEST_JID,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1521 recipient_jid,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1522 attachment_node,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1523 [item_elt],
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1524 {}
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1525 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1526
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1527 with patch.object(ap_gateway, "signAndPost") as signAndPost:
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1528 signAndPost.return_value.code = 202
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1529 await ap_gateway._itemsReceived(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1530 ap_gateway.client,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1531 items_event
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1532 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1533
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1534 assert signAndPost.called
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1535 url, actor_id, doc = signAndPost.call_args.args
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
1536 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"]
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1537 assert actor_id == ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost())
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1538 assert doc["type"] == "Like"
3890
c129234a5d0b tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents: 3871
diff changeset
1539 assert ap_const.NS_AP_PUBLIC in doc["cc"]
3871
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1540 assert doc["object"] == ap_item["id"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1541
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1542 @ed
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1543 async def test_ap_like_to_xmpp_noticed_attachment(self, ap_gateway, monkeypatch):
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1544 """AP Like activity is converted to ``noticed`` attachment"""
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1545 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1546 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1547 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1548
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1549 xmpp_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost())
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1550 # liked item
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1551 xmpp_item = XMPP_ITEMS[0]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1552 xmpp_item_url = ap_gateway.buildAPURL(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1553 ap_const.TYPE_ITEM, TEST_JID.userhost(), xmpp_item["id"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1554 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1555 like = {
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1556 "@context": "https://www.w3.org/ns/activitystreams",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1557 "type": "Like",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1558 "actor": TEST_AP_ACTOR_ID,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1559 "cc": [
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1560 xmpp_actor_id,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1561 TEST_USER_DATA["followers"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1562 ],
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1563 "id": "https://example.org/like/123",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1564 "object": xmpp_item_url,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1565 "published": "2022-07-22T09:24:12Z",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1566 "to": [ap_const.NS_AP_PUBLIC]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1567 }
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1568 with patch.object(ap_gateway.host.memory.storage, "getItems") as getItems:
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1569 getItems.return_value = ([], {})
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1570 with patch.object(ap_gateway._p, "sendItems") as sendItems:
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1571 await ap_gateway.server.resource.APInboxRequest(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1572 **self.ap_request_params(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1573 ap_gateway,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1574 "inbox",
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1575 doc=like,
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1576 signing_actor=TEST_AP_ACTOR_ID
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1577 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1578 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1579
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1580 assert sendItems.called
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1581 si_client, si_service, si_node, [si_item] = sendItems.call_args.args
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1582 assert si_client.jid == ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1583 assert si_service == TEST_JID
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1584 assert si_node == ap_gateway._pa.getAttachmentNodeName(
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1585 TEST_JID, ap_gateway._m.namespace, xmpp_item["id"]
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1586 )
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1587 [parsed_item] = ap_gateway._pa.items2attachmentData(si_client, [si_item])
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1588 assert parsed_item["from"] == si_client.jid.full()
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1589 assert "noticed" in parsed_item
8c01d8ab9447 tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents: 3837
diff changeset
1590 assert parsed_item["noticed"]["noticed"] == True
3891
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1591
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1592 @ed
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1593 async def test_xmpp_pubsub_reactions_to_ap(self, ap_gateway, monkeypatch):
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1594 """Pubsub-attachments ``reactions`` is converted to AP EmojiReact activity"""
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1595 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1596 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1597 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1598
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1599 recipient_jid = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1600 # noticed item
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1601 ap_item = TEST_AP_ITEMS[0]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1602 ap_item_url = xmpp_uri.buildXMPPUri(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1603 "pubsub",
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1604 path=recipient_jid.full(),
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1605 node=ap_gateway._m.namespace,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1606 item=ap_item["id"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1607 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1608 attachment_node = ap_gateway._pa.getAttachmentNodeName(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1609 recipient_jid,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1610 ap_gateway._m.namespace,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1611 ap_item["id"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1612 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1613 reactions = ["🦁", "🥜", "🎻"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1614 item_elt = xml_tools.parse(f"""
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1615 <item id="{TEST_JID.userhost()}" published="{TEST_JID.userhostJID()}">
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1616 <attachments xmlns="urn:xmpp:pubsub-attachments:1">
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1617 <reactions timestamp="2022-08-31T12:17:23Z">
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1618 <reaction>{reactions[0]}</reaction>
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1619 <reaction>{reactions[1]}</reaction>
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1620 <reaction>{reactions[2]}</reaction>
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1621 </reactions>
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1622 </attachments>
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1623 </item>
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1624 """)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1625 item_elt.uri = pubsub.NS_PUBSUB_EVENT
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1626 items_event = pubsub.ItemsEvent(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1627 TEST_JID,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1628 recipient_jid,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1629 attachment_node,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1630 [item_elt],
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1631 {}
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1632 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1633
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1634 with patch.object(ap_gateway, "signAndPost") as signAndPost:
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1635 signAndPost.return_value.code = 202
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1636 await ap_gateway._itemsReceived(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1637 ap_gateway.client,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1638 items_event
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1639 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1640
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1641 assert signAndPost.call_count == 3
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1642 for idx, call_args in enumerate(signAndPost.call_args_list):
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1643 url, actor_id, doc = call_args.args
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1644 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1645 assert actor_id == ap_gateway.buildAPURL(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1646 ap_const.TYPE_ACTOR, TEST_JID.userhost()
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1647 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1648 assert doc["type"] == "EmojiReact"
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1649 assert ap_const.NS_AP_PUBLIC in doc["cc"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1650 assert doc["object"] == ap_item["id"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1651 # reactions can be sent in random order (due to the use of set), thus we check
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1652 # if each reaction appear once, and that nothing is left after all calls are
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1653 # checked.
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1654 assert doc["content"] in reactions
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1655 reactions.remove(doc["content"])
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1656 assert len(reactions) == 0
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1657
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1658 @ed
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1659 async def test_ap_reactions_to_xmpp(self, ap_gateway, monkeypatch):
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1660 """AP EmojiReact activity is converted to ``reactions`` attachment"""
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1661 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1662 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1663 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1664
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1665 xmpp_actor_id = ap_gateway.buildAPURL(ap_const.TYPE_ACTOR, TEST_JID.userhost())
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1666 # item on which reaction is attached
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1667 xmpp_item = XMPP_ITEMS[0]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1668 xmpp_item_url = ap_gateway.buildAPURL(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1669 ap_const.TYPE_ITEM, TEST_JID.userhost(), xmpp_item["id"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1670 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1671 like = {
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1672 "@context": "https://www.w3.org/ns/activitystreams",
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1673 "type": "EmojiReact",
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1674 "actor": TEST_AP_ACTOR_ID,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1675 "cc": [
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1676 xmpp_actor_id,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1677 TEST_USER_DATA["followers"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1678 ],
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1679 "id": "https://example.org/like/123",
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1680 "object": xmpp_item_url,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1681 "content": "🐅",
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1682 "published": "2022-07-22T09:24:12Z",
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1683 "to": [ap_const.NS_AP_PUBLIC]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1684 }
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1685 with patch.object(ap_gateway.host.memory.storage, "getItems") as getItems:
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1686 getItems.return_value = ([], {})
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1687 with patch.object(ap_gateway._p, "sendItems") as sendItems:
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1688 await ap_gateway.server.resource.APInboxRequest(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1689 **self.ap_request_params(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1690 ap_gateway,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1691 "inbox",
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1692 doc=like,
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1693 signing_actor=TEST_AP_ACTOR_ID
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1694 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1695 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1696
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1697 assert sendItems.called
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1698 si_client, si_service, si_node, [si_item] = sendItems.call_args.args
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1699 assert si_client.jid == ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT)
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1700 assert si_service == TEST_JID
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1701 assert si_node == ap_gateway._pa.getAttachmentNodeName(
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1702 TEST_JID, ap_gateway._m.namespace, xmpp_item["id"]
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1703 )
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1704 [parsed_item] = ap_gateway._pa.items2attachmentData(si_client, [si_item])
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1705 assert parsed_item["from"] == si_client.jid.full()
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1706 assert "reactions" in parsed_item
989df1047c3c tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents: 3890
diff changeset
1707 assert parsed_item["reactions"]["reactions"] == ["🐅"]