Mercurial > libervia-backend
annotate tests/unit/test_ap-gateway.py @ 3847:aaa4e7815ba8
component AP gateway: new `verbose` attribute in AP gateway to activate debug logs:
when verbose is not null, object posted or returned on GET request are logged. Check
comments for vebosity level
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 14 Jul 2022 12:55:30 +0200 |
parents | 56720561f45f |
children | 8c01d8ab9447 |
rev | line source |
---|---|
3733 | 1 #!/usr/bin/env python3 |
2 | |
3 # Libervia: an XMPP client | |
4 # Copyright (C) 2009-2022 Jérôme Poisson (goffi@goffi.org) | |
5 | |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 from copy import deepcopy | |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
20 from unittest.mock import MagicMock, AsyncMock, patch, DEFAULT |
3733 | 21 from urllib import parse |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
22 from functools import partial |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
23 from typing import Dict, Union |
3733 | 24 |
25 import pytest | |
26 from pytest_twisted import ensureDeferred as ed | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
27 from twisted.internet import defer |
3733 | 28 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
|
29 from twisted.words.protocols.jabber.error import StanzaError |
3733 | 30 from twisted.web.server import Request |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
31 from twisted.words.xish import domish |
3733 | 32 from wokkel import rsm, pubsub |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
33 from treq.response import _Response as TReqResponse |
3733 | 34 |
35 from sat.core import exceptions | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
36 from sat.core.constants import Const as C |
3733 | 37 from sat.plugins import plugin_comp_ap_gateway |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
38 from sat.plugins.plugin_comp_ap_gateway import constants as ap_const |
3733 | 39 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
|
40 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
|
41 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
|
42 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
|
43 from sat.plugins.plugin_xep_0465 import NS_PPS |
3733 | 44 from sat.tools.utils import xmpp_date |
45 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
|
46 from sat.tools.common import uri as xmpp_uri |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
47 from sat.plugins.plugin_comp_ap_gateway import TYPE_ACTOR |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
48 from sat.memory.sqla_mapping import SubscriptionState |
3733 | 49 |
50 | |
51 TEST_BASE_URL = "https://example.org" | |
52 TEST_USER = "test_user" | |
53 TEST_AP_ACCOUNT = f"{TEST_USER}@example.org" | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
54 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
|
55 PUBLIC_URL = "test.example" |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
56 TEST_JID = jid.JID(f"some_user@{PUBLIC_URL}") |
3733 | 57 |
58 AP_REQUESTS = { | |
59 f"{TEST_BASE_URL}/.well-known/webfinger?" | |
60 f"resource=acct:{parse.quote(TEST_AP_ACCOUNT)}": { | |
61 "aliases": [ | |
62 f"{TEST_BASE_URL}/@{TEST_USER}", | |
63 f"{TEST_BASE_URL}/users/{TEST_USER}" | |
64 ], | |
65 "links": [ | |
66 { | |
67 "href": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
68 "rel": "self", | |
69 "type": "application/activity+json" | |
70 }, | |
71 ], | |
72 "subject": f"acct:{TEST_AP_ACCOUNT}" | |
73 }, | |
74 | |
75 f"{TEST_BASE_URL}/users/{TEST_USER}": { | |
76 "@context": [ | |
77 "https://www.w3.org/ns/activitystreams", | |
78 ], | |
79 "endpoints": { | |
80 "sharedInbox": f"{TEST_BASE_URL}/inbox" | |
81 }, | |
82 "followers": f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
83 "following": f"{TEST_BASE_URL}/users/{TEST_USER}/following", | |
84 "id": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
85 "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
|
86 "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
|
87 "summary": "<p>test account</p>", |
3733 | 88 "outbox": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", |
89 "preferredUsername": f"{TEST_USER}", | |
90 "type": "Person", | |
91 "url": f"{TEST_BASE_URL}/@{TEST_USER}" | |
92 }, | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
93 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
|
94 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
|
95 "aliases": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
96 f"{TEST_BASE_URL}/@ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
97 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
|
98 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
99 "links": [ |
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 "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
|
102 "rel": "self", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
103 "type": "application/activity+json" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
104 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
105 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
106 "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
|
107 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
108 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
|
109 "@context": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
110 "https://www.w3.org/ns/activitystreams", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
111 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
112 "endpoints": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
113 "sharedInbox": f"{TEST_BASE_URL}/inbox" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
114 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
115 "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
|
116 "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
|
117 "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
|
118 "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
|
119 "name": "", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
120 "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
|
121 "preferredUsername": f"ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
122 "type": "Person", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
123 "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
|
124 }, |
3733 | 125 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox": { |
126 "@context": "https://www.w3.org/ns/activitystreams", | |
127 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
128 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
129 "last": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
130 "totalItems": 4, | |
131 "type": "OrderedCollection" | |
132 }, | |
133 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true": { | |
134 "@context": [ | |
135 "https://www.w3.org/ns/activitystreams", | |
136 ], | |
137 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
138 "orderedItems": [ | |
139 { | |
140 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
141 "cc": [ | |
142 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
143 ], | |
144 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1/activity", | |
145 "object": { | |
146 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
147 "cc": [ | |
148 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
149 ], | |
150 "content": "<p>test message 1</p>", | |
151 "contentMap": { | |
152 "en": "<p>test message 1</p>" | |
153 }, | |
154 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1", | |
155 "inReplyTo": None, | |
156 "published": "2021-12-16T17:28:03Z", | |
157 "sensitive": False, | |
158 "summary": None, | |
159 "tag": [], | |
160 "to": [ | |
161 "https://www.w3.org/ns/activitystreams#Public" | |
162 ], | |
163 "type": "Note", | |
164 "url": f"{TEST_BASE_URL}/@{TEST_USER}/1" | |
165 }, | |
166 "published": "2021-12-16T17:28:03Z", | |
167 "to": [ | |
168 "https://www.w3.org/ns/activitystreams#Public" | |
169 ], | |
170 "type": "Create" | |
171 }, | |
172 { | |
173 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
174 "cc": [ | |
175 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
176 ], | |
177 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2/activity", | |
178 "object": { | |
179 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
180 "cc": [ | |
181 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
182 ], | |
183 "content": "<p>test message 2</p>", | |
184 "contentMap": { | |
185 "en": "<p>test message 2</p>" | |
186 }, | |
187 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2", | |
188 "inReplyTo": None, | |
189 "published": "2021-12-16T17:27:03Z", | |
190 "sensitive": False, | |
191 "summary": None, | |
192 "tag": [], | |
193 "to": [ | |
194 "https://www.w3.org/ns/activitystreams#Public" | |
195 ], | |
196 "type": "Note", | |
197 "url": f"{TEST_BASE_URL}/@{TEST_USER}/2" | |
198 }, | |
199 "published": "2021-12-16T17:27:03Z", | |
200 "to": [ | |
201 "https://www.w3.org/ns/activitystreams#Public" | |
202 ], | |
203 "type": "Create" | |
204 }, | |
205 { | |
206 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
207 "cc": [ | |
208 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
209 ], | |
210 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3/activity", | |
211 "object": { | |
212 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
213 "cc": [ | |
214 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
215 ], | |
216 "content": "<p>test message 3</p>", | |
217 "contentMap": { | |
218 "en": "<p>test message 3</p>" | |
219 }, | |
220 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3", | |
221 "inReplyTo": None, | |
222 "published": "2021-12-16T17:26:03Z", | |
223 "sensitive": False, | |
224 "summary": None, | |
225 "tag": [], | |
226 "to": [ | |
227 "https://www.w3.org/ns/activitystreams#Public" | |
228 ], | |
229 "type": "Note", | |
230 "url": f"{TEST_BASE_URL}/@{TEST_USER}/3" | |
231 }, | |
232 "published": "2021-12-16T17:26:03Z", | |
233 "to": [ | |
234 "https://www.w3.org/ns/activitystreams#Public" | |
235 ], | |
236 "type": "Create" | |
237 }, | |
238 { | |
239 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
240 "cc": [ | |
241 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
242 ], | |
243 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4/activity", | |
244 "object": { | |
245 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
246 "cc": [ | |
247 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
248 ], | |
249 "content": "<p>test message 4</p>", | |
250 "contentMap": { | |
251 "en": "<p>test message 4</p>" | |
252 }, | |
253 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4", | |
254 "inReplyTo": None, | |
255 "published": "2021-12-16T17:25:03Z", | |
256 "sensitive": False, | |
257 "summary": None, | |
258 "tag": [], | |
259 "to": [ | |
260 "https://www.w3.org/ns/activitystreams#Public" | |
261 ], | |
262 "type": "Note", | |
263 "url": f"{TEST_BASE_URL}/@{TEST_USER}/4" | |
264 }, | |
265 "published": "2021-12-16T17:25:03Z", | |
266 "to": [ | |
267 "https://www.w3.org/ns/activitystreams#Public" | |
268 ], | |
269 "type": "Create" | |
270 }, | |
271 ], | |
272 "partOf": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
273 "prev": None, | |
274 "type": "OrderedCollectionPage" | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
275 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
276 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
|
277 "@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
|
278 "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
|
279 "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
|
280 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
281 "type": "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
282 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
283 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
|
284 "@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
|
285 "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
|
286 "orderedItems": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
287 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
|
288 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
|
289 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
290 "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
|
291 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
292 "type": "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
293 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
294 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
|
295 "@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
|
296 "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
|
297 "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
|
298 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
299 "type": "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
300 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
301 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
|
302 "@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
|
303 "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
|
304 "orderedItems": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
305 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
|
306 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
|
307 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
308 "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
|
309 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
310 "type": "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
311 }, |
3733 | 312 |
313 } | |
314 | |
315 XMPP_ITEM_TPL = """ | |
316 <item id='{id}' publisher='{publisher_jid}'> | |
317 <entry xmlns='http://www.w3.org/2005/Atom' xml:lang='en'> | |
318 <title type='xhtml'> | |
319 <div xmlns='http://www.w3.org/1999/xhtml'> | |
320 <p> | |
321 XMPP item {id} | |
322 </p> | |
323 </div> | |
324 </title> | |
325 <title type='text'> | |
326 XMPP item {id} | |
327 </title> | |
328 <author> | |
329 <name> | |
330 test_user | |
331 </name> | |
332 <uri> | |
333 xmpp:{publisher_jid} | |
334 </uri> | |
335 </author> | |
336 <updated> | |
337 {updated} | |
338 </updated> | |
339 <published> | |
340 {published} | |
341 </published> | |
342 <id> | |
343 xmpp:{publisher_jid}?;node=urn%3Axmpp%3Amicroblog%3A0;item={id} | |
344 </id> | |
345 </entry> | |
346 </item> | |
347 """ | |
348 | |
349 ITEM_BASE_TS = 1643385499 | |
350 XMPP_ITEMS = [ | |
351 xml_tools.parse( | |
352 "".join( | |
353 l.strip() for l in XMPP_ITEM_TPL.format( | |
354 id=i, | |
355 publisher_jid="some_user@test.example", | |
356 updated=xmpp_date(ITEM_BASE_TS + i * 60), | |
357 published=xmpp_date(ITEM_BASE_TS + i * 60), | |
358 ).split("\n") | |
359 ), | |
360 namespace=pubsub.NS_PUBSUB | |
361 ) | |
362 for i in range(1, 5) | |
363 ] | |
364 | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
365 |
3733 | 366 async def mock_ap_get(url): |
367 return deepcopy(AP_REQUESTS[url]) | |
368 | |
369 | |
370 async def mock_treq_json(data): | |
371 return dict(data) | |
372 | |
373 | |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
374 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
|
375 """Mock getItems |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
376 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
377 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
|
378 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
|
379 returned |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
380 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
|
381 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
|
382 """ |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
383 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
|
384 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
|
385 raise StanzaError("item-not-found") |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
386 ret_items = kwargs.pop("ret_items", XMPP_ITEMS) |
3733 | 387 rsm_resp = rsm.RSMResponse( |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
388 first=ret_items[0]["id"], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
389 last=ret_items[-1]["id"], |
3733 | 390 index=0, |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
391 count=len(ret_items) |
3733 | 392 ) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
393 return ret_items, {"rsm": rsm_resp.toDict(), "complete": True} |
3733 | 394 |
395 | |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
396 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
|
397 """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
|
398 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
399 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
|
400 """ |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
405 |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
406 def getVirtualClient(jid): |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
407 client = MagicMock() |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
408 client.jid = jid |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
409 return client |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
410 |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
411 |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
412 class FakeTReqPostResponse: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
413 code = 202 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
414 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
415 |
3733 | 416 @pytest.fixture(scope="session") |
417 def ap_gateway(host): | |
418 gateway = plugin_comp_ap_gateway.APGateway(host) | |
419 gateway.initialised = True | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
420 gateway.isPubsub = AsyncMock() |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
421 gateway.isPubsub.return_value = False |
3733 | 422 client = MagicMock() |
423 client.jid = jid.JID("ap.test.example") | |
424 client.host = "test.example" | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
425 client.getVirtualClient = getVirtualClient |
3733 | 426 gateway.client = client |
427 gateway.local_only = True | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
428 gateway.public_url = PUBLIC_URL |
3733 | 429 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
|
430 gateway.auto_mentions = True |
3733 | 431 gateway.base_ap_url = parse.urljoin( |
432 f"https://{gateway.public_url}", | |
433 f"{gateway.ap_path}/" | |
434 ) | |
435 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
|
436 gateway.public_key_pem = None |
3733 | 437 return gateway |
438 | |
439 | |
440 class TestActivityPubGateway: | |
441 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
442 def getTitleXHTML(self, item_elt: domish.Element) -> domish.Element: |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
443 return next( |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
444 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
|
445 if t.getAttribute("type") == "xhtml" |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
446 ) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
447 |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
448 |
3733 | 449 @ed |
450 async def test_jid_and_node_convert_to_ap_handle(self, ap_gateway): | |
451 """JID and pubsub node are converted correctly to an AP actor handle""" | |
452 get_account = ap_gateway.getAPAccountFromJidAndNode | |
453 | |
454 # local jid | |
455 assert await get_account( | |
456 jid_ = jid.JID("simple@test.example"), | |
457 node = None | |
458 ) == "simple@test.example" | |
459 | |
460 # non local jid | |
461 assert await get_account( | |
462 jid_ = jid.JID("simple@example.org"), | |
463 node = None | |
464 ) == "___simple.40example.2eorg@ap.test.example" | |
465 | |
466 # local jid with non microblog node | |
467 assert await get_account( | |
468 jid_ = jid.JID("simple@test.example"), | |
469 node = "some_other_node" | |
470 ) == "some_other_node---simple@test.example" | |
471 | |
472 # local pubsub node | |
473 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
474 isPubsub.return_value = True | |
475 assert await get_account( | |
476 jid_ = jid.JID("pubsub.test.example"), | |
477 node = "some_node" | |
478 ) == "some_node@pubsub.test.example" | |
479 | |
480 # non local pubsub node | |
481 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
482 isPubsub.return_value = True | |
483 assert await get_account( | |
484 jid_ = jid.JID("pubsub.example.org"), | |
485 node = "some_node" | |
486 ) == "___some_node.40pubsub.2eexample.2eorg@ap.test.example" | |
487 | |
488 @ed | |
489 async def test_ap_handle_convert_to_jid_and_node(self, ap_gateway, monkeypatch): | |
490 """AP actor handle convert correctly to JID and pubsub node""" | |
491 get_jid_node = ap_gateway.getJIDAndNode | |
492 | |
493 # for following assertion, host is not a pubsub service | |
494 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
495 isPubsub.return_value = False | |
496 | |
497 # simple local jid | |
498 assert await get_jid_node( | |
499 "toto@test.example" | |
500 ) == (jid.JID("toto@test.example"), None) | |
501 | |
502 # simple external jid | |
503 | |
504 ## with "local_only" set, it should raise an exception | |
505 with pytest.raises(exceptions.PermissionError): | |
506 await get_jid_node("toto@example.org") | |
507 | |
508 ## with "local_only" unset, it should work | |
509 with monkeypatch.context() as m: | |
510 m.setattr(ap_gateway, "local_only", False, raising=True) | |
511 assert await get_jid_node( | |
512 "toto@example.org" | |
513 ) == (jid.JID("toto@example.org"), None) | |
514 | |
515 # explicit node | |
516 assert await get_jid_node( | |
517 "tata---toto@test.example" | |
518 ) == (jid.JID("toto@test.example"), "tata") | |
519 | |
520 # for following assertion, host is a pubsub service | |
521 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
522 isPubsub.return_value = True | |
523 | |
524 # simple local node | |
525 assert await get_jid_node( | |
526 "toto@pubsub.test.example" | |
527 ) == (jid.JID("pubsub.test.example"), "toto") | |
528 | |
529 # encoded local node | |
530 assert await get_jid_node( | |
531 "___urn.3axmpp.3amicroblog.3a0@pubsub.test.example" | |
532 ) == (jid.JID("pubsub.test.example"), "urn:xmpp:microblog:0") | |
533 | |
534 @ed | |
535 async def test_ap_to_pubsub_conversion(self, ap_gateway, monkeypatch): | |
536 """AP requests are converted to pubsub""" | |
537 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) | |
538 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) | |
539 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) | |
540 | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
541 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
|
542 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
|
543 items, rsm_resp = await ap_gateway.getAPItems(outbox, 2) |
3733 | 544 |
545 assert rsm_resp.count == 4 | |
546 assert rsm_resp.index == 0 | |
547 assert rsm_resp.first == "https://example.org/users/test_user/statuses/4" | |
548 assert rsm_resp.last == "https://example.org/users/test_user/statuses/3" | |
549 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
550 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
551 assert title_xhtml.toXml() == ( |
3733 | 552 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
553 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 4</p></div>" | |
554 "</title>" | |
555 ) | |
556 author_uri = str( | |
557 [e for e in items[0].entry.author.elements() if e.name == "uri"][0] | |
558 ) | |
559 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
560 assert str(items[0].entry.published) == "2021-12-16T17:25:03Z" | |
561 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
562 title_xhtml = self.getTitleXHTML(items[1]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
563 assert title_xhtml.toXml() == ( |
3733 | 564 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
565 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" | |
566 "</title>" | |
567 ) | |
568 author_uri = str( | |
569 [e for e in items[1].entry.author.elements() if e.name == "uri"][0] | |
570 ) | |
571 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
572 assert str(items[1].entry.published) == "2021-12-16T17:26:03Z" | |
573 | |
574 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
|
575 outbox, |
3733 | 576 max_items=2, |
577 after_id="https://example.org/users/test_user/statuses/3", | |
578 ) | |
579 | |
580 assert rsm_resp.count == 4 | |
581 assert rsm_resp.index == 2 | |
582 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" | |
583 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" | |
584 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
585 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
586 assert title_xhtml.toXml() == ( |
3733 | 587 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
588 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" | |
589 "</title>" | |
590 ) | |
591 author_uri = str( | |
592 [e for e in items[0].entry.author.elements() if e.name == "uri"][0] | |
593 ) | |
594 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
595 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" | |
596 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
597 title_xhtml = self.getTitleXHTML(items[1]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
598 assert title_xhtml.toXml() == ( |
3733 | 599 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
600 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" | |
601 "</title>" | |
602 ) | |
603 author_uri = str( | |
604 [e for e in items[1].entry.author.elements() if e.name == "uri"][0] | |
605 ) | |
606 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
607 assert str(items[1].entry.published) == "2021-12-16T17:28:03Z" | |
608 | |
609 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
|
610 outbox, |
3733 | 611 max_items=1, |
612 start_index=2 | |
613 ) | |
614 | |
615 assert rsm_resp.count == 4 | |
616 assert rsm_resp.index == 2 | |
617 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" | |
618 assert rsm_resp.last == "https://example.org/users/test_user/statuses/2" | |
619 assert len(items) == 1 | |
620 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
621 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
622 assert title_xhtml.toXml() == ( |
3733 | 623 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
624 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" | |
625 "</title>" | |
626 ) | |
627 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" | |
628 | |
629 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
|
630 outbox, |
3733 | 631 max_items=3, |
632 chronological_pagination=False | |
633 ) | |
634 assert rsm_resp.count == 4 | |
635 assert rsm_resp.index == 1 | |
636 assert rsm_resp.first == "https://example.org/users/test_user/statuses/3" | |
637 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" | |
638 assert len(items) == 3 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
639 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
640 assert title_xhtml.toXml() == ( |
3733 | 641 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
642 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" | |
643 "</title>" | |
644 ) | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
645 title_xhtml = self.getTitleXHTML(items[2]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
646 assert title_xhtml.toXml() == ( |
3733 | 647 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
648 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" | |
649 "</title>" | |
650 ) | |
651 | |
652 def ap_request_params(self, ap_gateway, type_=None, url=None, query_data=None): | |
653 """Generate parameters for HTTPAPGServer's AP*Request | |
654 | |
655 @param type_: one of the AP query type (e.g. "outbox") | |
656 @param url: URL to query (mutually exclusif with type_) | |
657 @param query_data: query data as returned by parse.parse_qs | |
658 @return dict with kw params to use | |
659 """ | |
660 assert type_ and url is None or url and type_ is None | |
661 if type_ is not None: | |
662 path = f"_ap/{type_}/some_user%40test.example" | |
663 else: | |
664 url_parsed = parse.urlparse(url) | |
665 path = url_parsed.path.lstrip("/") | |
666 type_ = path.split("/")[1] | |
667 if query_data is None: | |
668 query_data = parse.parse_qs(url_parsed.query) | |
669 | |
670 if query_data: | |
671 uri = f"{path}?{parse.urlencode(query_data, doseq=True)}" | |
672 else: | |
673 uri = path | |
674 | |
675 test_jid = jid.JID("some_user@test.example") | |
676 request = Request(MagicMock()) | |
677 request.path = path.encode() | |
678 request.uri = uri.encode() | |
679 ap_url = parse.urljoin( | |
680 f"https://{ap_gateway.public_url}", | |
681 path | |
682 ) | |
683 kwargs = { | |
684 "request": request, | |
685 "account_jid": test_jid, | |
686 "node": None, | |
687 "ap_account": test_jid.full(), | |
688 "ap_url": ap_url, | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
689 "signing_actor": None |
3733 | 690 } |
691 if type_ == "outbox" and query_data: | |
692 kwargs["query_data"] = query_data | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
693 # 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
|
694 del kwargs["signing_actor"] |
3733 | 695 return kwargs |
696 | |
697 @ed | |
698 async def test_pubsub_to_ap_conversion(self, ap_gateway, monkeypatch): | |
699 """Pubsub nodes are converted to AP collections""" | |
700 monkeypatch.setattr(ap_gateway._p, "getItems", mock_getItems) | |
701 outbox = await ap_gateway.server.resource.APOutboxRequest( | |
702 **self.ap_request_params(ap_gateway, "outbox") | |
703 ) | |
704 assert outbox["@context"] == "https://www.w3.org/ns/activitystreams" | |
705 assert outbox["id"] == "https://test.example/_ap/outbox/some_user%40test.example" | |
706 assert outbox["totalItems"] == len(XMPP_ITEMS) | |
707 assert outbox["type"] == "OrderedCollection" | |
708 assert outbox["first"] | |
709 assert outbox["last"] | |
710 | |
711 first_page = await ap_gateway.server.resource.APOutboxPageRequest( | |
712 **self.ap_request_params(ap_gateway, url=outbox["first"]) | |
713 ) | |
714 assert first_page["@context"] == "https://www.w3.org/ns/activitystreams" | |
715 assert first_page["id"] == "https://test.example/_ap/outbox/some_user%40test.example?page=first" | |
716 assert first_page["type"] == "OrderedCollectionPage" | |
717 assert first_page["partOf"] == outbox["id"] | |
718 assert len(first_page["orderedItems"]) == len(XMPP_ITEMS) | |
719 first_item = first_page["orderedItems"][0] | |
720 assert first_item["@context"] == "https://www.w3.org/ns/activitystreams" | |
721 assert first_item["id"] == "https://test.example/_ap/item/some_user%40test.example/4" | |
722 assert first_item["actor"] == "https://test.example/_ap/actor/some_user%40test.example" | |
723 assert first_item["type"] == "Create" | |
724 first_item_obj = first_item["object"] | |
725 assert first_item_obj["id"] == first_item["id"] | |
726 assert first_item_obj["type"] == "Note" | |
727 assert first_item_obj["published"] == "2022-01-28T16:02:19Z" | |
728 assert first_item_obj["attributedTo"] == first_item["actor"] | |
729 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
|
730 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
|
731 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
732 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
733 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
|
734 """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
|
735 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
|
736 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
|
737 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
|
738 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
739 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
|
740 jid.JID("toto@example.org"), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
741 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
742 ap_gateway._pps.subscriptions_node, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
743 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
744 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
745 None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
746 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
747 assert len(items) == 2 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
748 for idx, entity in enumerate(( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
749 "local_user@test.example", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
750 "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
|
751 )): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
752 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
|
753 assert subscription_elt is not None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
754 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
|
755 assert subscription_elt["service"] == entity |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
756 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
757 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
758 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
|
759 """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
|
760 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
|
761 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
|
762 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
|
763 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
764 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
|
765 jid.JID("toto@example.org"), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
766 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
767 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
|
768 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
769 None, |
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 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
772 assert len(items) == 2 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
773 for idx, entity in enumerate(( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
774 "local_user@test.example", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
775 "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
|
776 )): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
777 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
|
778 assert subscriber_elt is not None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
779 assert subscriber_elt["jid"] == entity |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
780 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
781 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
782 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
|
783 """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
|
784 subscriptions = [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
785 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
786 id="subscription_1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
787 payload = ap_gateway._pps.buildSubscriptionElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
788 ap_gateway._m.namespace, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
789 jid.JID("local_user@test.example") |
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 ), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
792 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
793 id="subscription_2", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
794 payload = ap_gateway._pps.buildSubscriptionElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
795 ap_gateway._m.namespace, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
796 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
|
797 ) |
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 ] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
800 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
|
801 mock_getItems, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
802 ret_items=subscriptions |
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 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
|
805 **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
|
806 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
807 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
|
808 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
|
809 assert following["totalItems"] == len(subscriptions) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
810 assert following["type"] == "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
811 assert following.get("first") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
812 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
813 first_page = following["first"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
814 assert first_page["type"] == "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
815 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
|
816 items = first_page["orderedItems"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
817 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
|
818 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
819 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
820 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
|
821 """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
|
822 subscribers = [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
823 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
824 id="subscriber_1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
825 payload = ap_gateway._pps.buildSubscriberElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
826 jid.JID("local_user@test.example") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
827 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
828 ), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
829 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
830 id="subscriber_2", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
831 payload = ap_gateway._pps.buildSubscriberElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
832 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
|
833 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
834 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
835 ] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
836 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
|
837 mock_getItems, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
838 ret_items=subscribers |
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 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
|
841 **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
|
842 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
843 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
|
844 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
|
845 assert followers["totalItems"] == len(subscribers) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
846 assert followers["type"] == "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
847 assert followers.get("first") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
848 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
849 first_page = followers["first"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
850 assert first_page["type"] == "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
851 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
|
852 items = first_page["orderedItems"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
853 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
|
854 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
855 @ed |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
856 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
|
857 """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
|
858 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
|
859 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
|
860 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
|
861 mess_data = { |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
862 "from": TEST_JID, |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
863 "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
|
864 "type": "chat", |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
865 "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
|
866 "extra": { |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
867 "origin-id": "123" |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
868 } |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
869 } |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
870 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
|
871 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
|
872 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
|
873 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
|
874 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
|
875 obj = doc["object"] |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
876 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
|
877 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
|
878 assert obj["type"] == "Note" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
879 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
|
880 assert obj["attributedTo"] == ( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
881 "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
|
882 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
883 # 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
|
884 # ("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
|
885 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
|
886 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
|
887 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
|
888 assert field not in doc |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
889 assert field not in obj |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
890 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
891 @ed |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
892 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
|
893 """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
|
894 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
|
895 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
|
896 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
|
897 # 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
|
898 monkeypatch.setattr(defer, "DeferredList", AsyncMock()) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
899 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
900 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
|
901 direct_ap_message = { |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
902 'attributedTo': TEST_AP_ACTOR_ID, |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
903 'cc': [], |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
904 '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
|
905 '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
|
906 '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
|
907 '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
|
908 'to': [xmpp_actor_id], |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
909 'type': 'Note', |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
910 } |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
911 client = ap_gateway.client.getVirtualClient( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
912 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
|
913 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
914 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
|
915 await ap_gateway.newAPItem( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
916 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
|
917 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
918 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
919 # 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
|
920 # 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
|
921 assert sendMessage.called |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
922 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
|
923 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
|
924 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
925 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
926 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
|
927 """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
|
928 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
|
929 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
|
930 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
|
931 retract_id = "retract_123" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
932 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
|
933 retract_elt["id"] = retract_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
934 items_event = pubsub.ItemsEvent( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
935 sender=TEST_JID, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
936 recipient=ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
937 nodeIdentifier=ap_gateway._m.namespace, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
938 items=[retract_elt], |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
939 headers={} |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
940 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
941 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
|
942 signAndPost.return_value = FakeTReqPostResponse() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
943 # 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
|
944 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
|
945 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
|
946 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
|
947 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
|
948 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
|
949 assert actor_id == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
950 assert doc["type"] == "Delete" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
951 assert doc["actor"] == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
952 obj = doc["object"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
953 assert obj["type"] == ap_const.TYPE_TOMBSTONE |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
954 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
|
955 assert obj["id"] == url_item_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
956 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
957 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
958 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
|
959 """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
|
960 client = ap_gateway.client.getVirtualClient( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
961 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
962 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
963 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
964 ap_item = { |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
965 "@context": "https://www.w3.org/ns/activitystreams", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
966 "actor": TEST_AP_ACTOR_ID, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
967 "id": "https://test.example/retract_123", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
968 "type": "Delete", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
969 "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
|
970 "type": "Tombstone"}, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
971 "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
|
972 } |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
973 with patch.multiple( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
974 ap_gateway.host.memory.storage, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
975 get=DEFAULT, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
976 getPubsubNode=DEFAULT, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
977 deletePubsubItems=DEFAULT, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
978 ) as mock_objs: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
979 mock_objs["get"].return_value=None |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
980 cached_node = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
981 mock_objs["getPubsubNode"].return_value=cached_node |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
982 subscription = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
983 subscription.state = SubscriptionState.SUBSCRIBED |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
984 subscription.subscriber = TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
985 cached_node.subscriptions = [subscription] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
986 with patch.object( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
987 ap_gateway.pubsub_service, "notifyRetract" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
988 ) as notifyRetract: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
989 # we simulate a received Delete activity |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
990 await ap_gateway.newAPDeleteItem( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
991 client=client, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
992 destinee=None, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
993 node=ap_gateway._m.namespace, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
994 item=ap_item |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
995 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
996 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
997 # item is deleted from database |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
998 deletePubsubItems = mock_objs["deletePubsubItems"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
999 assert deletePubsubItems.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1000 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
|
1001 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1002 # retraction notification is sent to subscribers |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1003 assert notifyRetract.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1004 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
|
1005 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
|
1006 notifications = notifyRetract.call_args.args[2] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1007 assert len(notifications) == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1008 subscriber, __, item_elts = notifications[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1009 assert subscriber == TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1010 assert len(item_elts) == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1011 item_elt = item_elts[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1012 assert isinstance(item_elt, domish.Element) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1013 assert item_elt.name == "item" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1014 assert item_elt["id"] == ap_item["id"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1015 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1016 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1017 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
|
1018 """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
|
1019 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
|
1020 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
|
1021 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
|
1022 # 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
|
1023 origin_id = "mess_retract_123" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1024 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1025 # 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
|
1026 fake_client = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1027 fake_client.jid = TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1028 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
|
1029 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
|
1030 # 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
|
1031 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
|
1032 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
|
1033 retract_elt = apply_to_elt.retract |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1034 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1035 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
|
1036 signAndPost.return_value = FakeTReqPostResponse() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1037 fake_fastened_elts = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1038 fake_fastened_elts.id = origin_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1039 # 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
|
1040 # we generated above |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1041 await ap_gateway._onMessageRetract( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1042 ap_gateway.client, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1043 message_retract_elt, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1044 retract_elt, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1045 fake_fastened_elts |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1046 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1047 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
|
1048 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1049 # 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
|
1050 # we check its values |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1051 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
|
1052 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
|
1053 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
|
1054 assert actor_id == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1055 assert doc["type"] == "Delete" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1056 assert doc["actor"] == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1057 obj = doc["object"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1058 assert obj["type"] == ap_const.TYPE_TOMBSTONE |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1059 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
|
1060 assert obj["id"] == url_item_id |
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 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1063 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
|
1064 """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
|
1065 # 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
|
1066 # 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
|
1067 # by ``test_ap_delete_to_pubsub_retract``) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1068 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1069 # 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
|
1070 retractDBHistory = AsyncMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1071 monkeypatch.setattr(ap_gateway._r, "retractDBHistory", retractDBHistory) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1072 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1073 client = ap_gateway.client.getVirtualClient( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1074 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT) |
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 fake_send = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1077 monkeypatch.setattr(client, "send", fake_send) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1078 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1079 ap_item = { |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1080 "@context": "https://www.w3.org/ns/activitystreams", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1081 "actor": TEST_AP_ACTOR_ID, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1082 "id": "https://test.example/retract_123", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1083 "type": "Delete", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1084 "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
|
1085 "type": "Tombstone"}, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1086 "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
|
1087 } |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1088 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
|
1089 fake_history = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1090 fake_history.source_jid = client.jid |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1091 fake_history.dest_jid = TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1092 fake_history.origin_id = ap_item["id"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1093 storage_get.return_value = fake_history |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1094 # we simulate a received Delete activity |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1095 await ap_gateway.newAPDeleteItem( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1096 client=client, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1097 destinee=None, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1098 node=ap_gateway._m.namespace, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1099 item=ap_item |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1100 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1101 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1102 # item is deleted from database |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1103 assert retractDBHistory.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1104 assert retractDBHistory.call_args.args[0] == client |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1105 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
|
1106 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1107 # retraction notification is sent to destinee |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1108 assert fake_send.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1109 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
|
1110 assert sent_elt.name == "message" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1111 assert sent_elt["from"] == client.jid.full() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1112 assert sent_elt["to"] == TEST_JID.full() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1113 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
|
1114 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
|
1115 retract_elt = apply_to_elt.retract |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1116 assert retract_elt is not None |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1117 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
|
1118 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1119 @ed |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1120 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
|
1121 """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
|
1122 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
|
1123 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
|
1124 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
|
1125 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1126 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
|
1127 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
|
1128 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
|
1129 # VCard4 node |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1130 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
|
1131 None, |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1132 None, |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1133 None |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1134 ) |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1135 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
|
1136 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
|
1137 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
|
1138 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
|
1139 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
|
1140 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1141 @ed |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1142 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
|
1143 """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
|
1144 # 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
|
1145 # 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
|
1146 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
|
1147 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
|
1148 "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
|
1149 "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
|
1150 } |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1151 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
|
1152 **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
|
1153 ) |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1154 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1155 # 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
|
1156 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
|
1157 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
|
1158 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1159 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1160 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
|
1161 """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
|
1162 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
|
1163 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
|
1164 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
|
1165 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1166 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
|
1167 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1168 direct_addr_mention = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1169 '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
|
1170 'cc': [], |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1171 '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
|
1172 '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
|
1173 '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
|
1174 '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
|
1175 'type': 'Note' |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1176 } |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1177 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
|
1178 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
|
1179 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1180 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
|
1181 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1182 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
|
1183 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
|
1184 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
|
1185 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1186 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1187 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
|
1188 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
|
1189 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1190 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
|
1191 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
|
1192 "pubsub", |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1193 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
|
1194 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
|
1195 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
|
1196 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1197 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1198 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
|
1199 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1200 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1201 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
|
1202 """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
|
1203 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
|
1204 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
|
1205 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
|
1206 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1207 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
|
1208 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1209 direct_addr_mention = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1210 '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
|
1211 'cc': [], |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1212 '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
|
1213 '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
|
1214 '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
|
1215 '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
|
1216 "tag": [ |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1217 { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1218 "type": "Mention", |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1219 "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
|
1220 "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
|
1221 } |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1222 ], |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1223 'type': 'Note' |
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 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
|
1226 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
|
1227 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1228 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
|
1229 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1230 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
|
1231 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
|
1232 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
|
1233 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1234 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1235 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
|
1236 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
|
1237 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1238 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
|
1239 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
|
1240 "pubsub", |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1241 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
|
1242 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
|
1243 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
|
1244 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1245 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1246 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
|
1247 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1248 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1249 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
|
1250 """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
|
1251 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
|
1252 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
|
1253 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
|
1254 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1255 mb_data = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1256 "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
|
1257 "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
|
1258 "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
|
1259 "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
|
1260 } |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1261 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
|
1262 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1263 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
|
1264 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
|
1265 expected_mention = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1266 "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
|
1267 "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
|
1268 "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
|
1269 } |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1270 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
|
1271 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1272 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1273 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
|
1274 """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
|
1275 # 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
|
1276 # in mbdata2APitem |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1277 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
|
1278 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
|
1279 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
|
1280 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1281 mb_data = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1282 "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
|
1283 "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
|
1284 "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
|
1285 "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
|
1286 } |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1287 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
|
1288 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1289 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
|
1290 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
|
1291 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
|
1292 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1293 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1294 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
|
1295 """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
|
1296 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
|
1297 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
|
1298 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
|
1299 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1300 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
|
1301 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
|
1302 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
|
1303 "pubsub", |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1304 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
|
1305 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
|
1306 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
|
1307 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1308 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1309 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
|
1310 "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
|
1311 "type_": "mention", |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1312 "anchor": anchor |
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 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
|
1315 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1316 # 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
|
1317 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1318 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
|
1319 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
|
1320 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1321 # "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
|
1322 # 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
|
1323 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
|
1324 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
|
1325 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1326 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
|
1327 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
|
1328 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1329 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
|
1330 # 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
|
1331 # 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
|
1332 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
|
1333 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
|
1334 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
|
1335 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
|
1336 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
|
1337 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
|
1338 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1339 # 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
|
1340 # 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
|
1341 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
|
1342 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
|
1343 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
|
1344 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
|
1345 expected_mention = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1346 "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
|
1347 "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
|
1348 # 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
|
1349 # item with XMPP |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1350 "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
|
1351 } |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1352 assert expected_mention in ap_object["tag"] |