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