Mercurial > libervia-backend
annotate tests/unit/test_ap-gateway.py @ 3787:f8a0f3b65371
plugin XEP-0191: Blocking Command implementation:
rel 367
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 27 May 2022 12:12:16 +0200 |
parents | 0b54be42d0aa |
children | 39fc2e1b3793 |
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 | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
20 from unittest.mock import MagicMock, AsyncMock, patch |
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 |
28 from twisted.web.server import Request | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
29 from twisted.words.xish import domish |
3733 | 30 from wokkel import rsm, pubsub |
31 | |
32 from sat.core import exceptions | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
33 from sat.core.constants import Const as C |
3733 | 34 from sat.plugins import plugin_comp_ap_gateway |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
35 from sat.plugins.plugin_comp_ap_gateway import constants as ap_const |
3733 | 36 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
|
37 from sat.plugins.plugin_xep_0277 import NS_ATOM |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
38 from sat.plugins.plugin_xep_0465 import NS_PPS |
3733 | 39 from sat.tools.utils import xmpp_date |
40 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
|
41 from sat.plugins.plugin_comp_ap_gateway import TYPE_ACTOR |
3733 | 42 |
43 | |
44 TEST_BASE_URL = "https://example.org" | |
45 TEST_USER = "test_user" | |
46 TEST_AP_ACCOUNT = f"{TEST_USER}@example.org" | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
47 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
|
48 PUBLIC_URL = "test.example" |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
49 TEST_JID = jid.JID(f"some_user@{PUBLIC_URL}") |
3733 | 50 |
51 AP_REQUESTS = { | |
52 f"{TEST_BASE_URL}/.well-known/webfinger?" | |
53 f"resource=acct:{parse.quote(TEST_AP_ACCOUNT)}": { | |
54 "aliases": [ | |
55 f"{TEST_BASE_URL}/@{TEST_USER}", | |
56 f"{TEST_BASE_URL}/users/{TEST_USER}" | |
57 ], | |
58 "links": [ | |
59 { | |
60 "href": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
61 "rel": "self", | |
62 "type": "application/activity+json" | |
63 }, | |
64 ], | |
65 "subject": f"acct:{TEST_AP_ACCOUNT}" | |
66 }, | |
67 | |
68 f"{TEST_BASE_URL}/users/{TEST_USER}": { | |
69 "@context": [ | |
70 "https://www.w3.org/ns/activitystreams", | |
71 ], | |
72 "endpoints": { | |
73 "sharedInbox": f"{TEST_BASE_URL}/inbox" | |
74 }, | |
75 "followers": f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
76 "following": f"{TEST_BASE_URL}/users/{TEST_USER}/following", | |
77 "id": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
78 "inbox": f"{TEST_BASE_URL}/users/{TEST_USER}/inbox", | |
79 "name": "", | |
80 "outbox": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
81 "preferredUsername": f"{TEST_USER}", | |
82 "type": "Person", | |
83 "url": f"{TEST_BASE_URL}/@{TEST_USER}" | |
84 }, | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
85 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
|
86 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
|
87 "aliases": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
88 f"{TEST_BASE_URL}/@ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
89 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
|
90 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
91 "links": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
92 { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
93 "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
|
94 "rel": "self", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
95 "type": "application/activity+json" |
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 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
98 "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
|
99 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
100 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
|
101 "@context": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
102 "https://www.w3.org/ns/activitystreams", |
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 "endpoints": { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
105 "sharedInbox": f"{TEST_BASE_URL}/inbox" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
106 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
107 "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
|
108 "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
|
109 "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
|
110 "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
|
111 "name": "", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
112 "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
|
113 "preferredUsername": f"ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
114 "type": "Person", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
115 "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
|
116 }, |
3733 | 117 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox": { |
118 "@context": "https://www.w3.org/ns/activitystreams", | |
119 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
120 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
121 "last": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
122 "totalItems": 4, | |
123 "type": "OrderedCollection" | |
124 }, | |
125 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true": { | |
126 "@context": [ | |
127 "https://www.w3.org/ns/activitystreams", | |
128 ], | |
129 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
130 "orderedItems": [ | |
131 { | |
132 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
133 "cc": [ | |
134 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
135 ], | |
136 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1/activity", | |
137 "object": { | |
138 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
139 "cc": [ | |
140 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
141 ], | |
142 "content": "<p>test message 1</p>", | |
143 "contentMap": { | |
144 "en": "<p>test message 1</p>" | |
145 }, | |
146 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1", | |
147 "inReplyTo": None, | |
148 "published": "2021-12-16T17:28:03Z", | |
149 "sensitive": False, | |
150 "summary": None, | |
151 "tag": [], | |
152 "to": [ | |
153 "https://www.w3.org/ns/activitystreams#Public" | |
154 ], | |
155 "type": "Note", | |
156 "url": f"{TEST_BASE_URL}/@{TEST_USER}/1" | |
157 }, | |
158 "published": "2021-12-16T17:28:03Z", | |
159 "to": [ | |
160 "https://www.w3.org/ns/activitystreams#Public" | |
161 ], | |
162 "type": "Create" | |
163 }, | |
164 { | |
165 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
166 "cc": [ | |
167 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
168 ], | |
169 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2/activity", | |
170 "object": { | |
171 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
172 "cc": [ | |
173 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
174 ], | |
175 "content": "<p>test message 2</p>", | |
176 "contentMap": { | |
177 "en": "<p>test message 2</p>" | |
178 }, | |
179 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2", | |
180 "inReplyTo": None, | |
181 "published": "2021-12-16T17:27:03Z", | |
182 "sensitive": False, | |
183 "summary": None, | |
184 "tag": [], | |
185 "to": [ | |
186 "https://www.w3.org/ns/activitystreams#Public" | |
187 ], | |
188 "type": "Note", | |
189 "url": f"{TEST_BASE_URL}/@{TEST_USER}/2" | |
190 }, | |
191 "published": "2021-12-16T17:27:03Z", | |
192 "to": [ | |
193 "https://www.w3.org/ns/activitystreams#Public" | |
194 ], | |
195 "type": "Create" | |
196 }, | |
197 { | |
198 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
199 "cc": [ | |
200 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
201 ], | |
202 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3/activity", | |
203 "object": { | |
204 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
205 "cc": [ | |
206 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
207 ], | |
208 "content": "<p>test message 3</p>", | |
209 "contentMap": { | |
210 "en": "<p>test message 3</p>" | |
211 }, | |
212 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3", | |
213 "inReplyTo": None, | |
214 "published": "2021-12-16T17:26:03Z", | |
215 "sensitive": False, | |
216 "summary": None, | |
217 "tag": [], | |
218 "to": [ | |
219 "https://www.w3.org/ns/activitystreams#Public" | |
220 ], | |
221 "type": "Note", | |
222 "url": f"{TEST_BASE_URL}/@{TEST_USER}/3" | |
223 }, | |
224 "published": "2021-12-16T17:26:03Z", | |
225 "to": [ | |
226 "https://www.w3.org/ns/activitystreams#Public" | |
227 ], | |
228 "type": "Create" | |
229 }, | |
230 { | |
231 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
232 "cc": [ | |
233 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
234 ], | |
235 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4/activity", | |
236 "object": { | |
237 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
238 "cc": [ | |
239 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
240 ], | |
241 "content": "<p>test message 4</p>", | |
242 "contentMap": { | |
243 "en": "<p>test message 4</p>" | |
244 }, | |
245 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4", | |
246 "inReplyTo": None, | |
247 "published": "2021-12-16T17:25:03Z", | |
248 "sensitive": False, | |
249 "summary": None, | |
250 "tag": [], | |
251 "to": [ | |
252 "https://www.w3.org/ns/activitystreams#Public" | |
253 ], | |
254 "type": "Note", | |
255 "url": f"{TEST_BASE_URL}/@{TEST_USER}/4" | |
256 }, | |
257 "published": "2021-12-16T17:25:03Z", | |
258 "to": [ | |
259 "https://www.w3.org/ns/activitystreams#Public" | |
260 ], | |
261 "type": "Create" | |
262 }, | |
263 ], | |
264 "partOf": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
265 "prev": None, | |
266 "type": "OrderedCollectionPage" | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
267 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
268 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
|
269 "@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
|
270 "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
|
271 "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
|
272 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
273 "type": "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
274 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
275 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
|
276 "@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
|
277 "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
|
278 "orderedItems": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
279 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
|
280 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
|
281 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
282 "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
|
283 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
284 "type": "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
285 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
286 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
|
287 "@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
|
288 "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
|
289 "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
|
290 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
291 "type": "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
292 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
293 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
|
294 "@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
|
295 "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
|
296 "orderedItems": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
297 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
|
298 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
|
299 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
300 "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
|
301 "totalItems": 2, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
302 "type": "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
303 }, |
3733 | 304 |
305 } | |
306 | |
307 XMPP_ITEM_TPL = """ | |
308 <item id='{id}' publisher='{publisher_jid}'> | |
309 <entry xmlns='http://www.w3.org/2005/Atom' xml:lang='en'> | |
310 <title type='xhtml'> | |
311 <div xmlns='http://www.w3.org/1999/xhtml'> | |
312 <p> | |
313 XMPP item {id} | |
314 </p> | |
315 </div> | |
316 </title> | |
317 <title type='text'> | |
318 XMPP item {id} | |
319 </title> | |
320 <author> | |
321 <name> | |
322 test_user | |
323 </name> | |
324 <uri> | |
325 xmpp:{publisher_jid} | |
326 </uri> | |
327 </author> | |
328 <updated> | |
329 {updated} | |
330 </updated> | |
331 <published> | |
332 {published} | |
333 </published> | |
334 <id> | |
335 xmpp:{publisher_jid}?;node=urn%3Axmpp%3Amicroblog%3A0;item={id} | |
336 </id> | |
337 </entry> | |
338 </item> | |
339 """ | |
340 | |
341 ITEM_BASE_TS = 1643385499 | |
342 XMPP_ITEMS = [ | |
343 xml_tools.parse( | |
344 "".join( | |
345 l.strip() for l in XMPP_ITEM_TPL.format( | |
346 id=i, | |
347 publisher_jid="some_user@test.example", | |
348 updated=xmpp_date(ITEM_BASE_TS + i * 60), | |
349 published=xmpp_date(ITEM_BASE_TS + i * 60), | |
350 ).split("\n") | |
351 ), | |
352 namespace=pubsub.NS_PUBSUB | |
353 ) | |
354 for i in range(1, 5) | |
355 ] | |
356 | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
357 |
3733 | 358 async def mock_ap_get(url): |
359 return deepcopy(AP_REQUESTS[url]) | |
360 | |
361 | |
362 async def mock_treq_json(data): | |
363 return dict(data) | |
364 | |
365 | |
366 async def mock_getItems(*args, **kwargs): | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
367 ret_items = kwargs.pop("ret_items", XMPP_ITEMS) |
3733 | 368 rsm_resp = rsm.RSMResponse( |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
369 first=ret_items[0]["id"], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
370 last=ret_items[-1]["id"], |
3733 | 371 index=0, |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
372 count=len(ret_items) |
3733 | 373 ) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
374 return ret_items, {"rsm": rsm_resp.toDict(), "complete": True} |
3733 | 375 |
376 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
377 def getVirtualClient(jid): |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
378 client = MagicMock() |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
379 client.jid = jid |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
380 return client |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
381 |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
382 |
3733 | 383 @pytest.fixture(scope="session") |
384 def ap_gateway(host): | |
385 gateway = plugin_comp_ap_gateway.APGateway(host) | |
386 gateway.initialised = True | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
387 gateway.isPubsub = AsyncMock() |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
388 gateway.isPubsub.return_value = False |
3733 | 389 client = MagicMock() |
390 client.jid = jid.JID("ap.test.example") | |
391 client.host = "test.example" | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
392 client.getVirtualClient = getVirtualClient |
3733 | 393 gateway.client = client |
394 gateway.local_only = True | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
395 gateway.public_url = PUBLIC_URL |
3733 | 396 gateway.ap_path = '_ap' |
397 gateway.base_ap_url = parse.urljoin( | |
398 f"https://{gateway.public_url}", | |
399 f"{gateway.ap_path}/" | |
400 ) | |
401 gateway.server = HTTPServer(gateway) | |
402 return gateway | |
403 | |
404 | |
405 class TestActivityPubGateway: | |
406 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
407 def getTitleXHTML(self, item_elt: domish.Element) -> domish.Element: |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
408 return next( |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
409 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
|
410 if t.getAttribute("type") == "xhtml" |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
411 ) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
412 |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
413 |
3733 | 414 @ed |
415 async def test_jid_and_node_convert_to_ap_handle(self, ap_gateway): | |
416 """JID and pubsub node are converted correctly to an AP actor handle""" | |
417 get_account = ap_gateway.getAPAccountFromJidAndNode | |
418 | |
419 # local jid | |
420 assert await get_account( | |
421 jid_ = jid.JID("simple@test.example"), | |
422 node = None | |
423 ) == "simple@test.example" | |
424 | |
425 # non local jid | |
426 assert await get_account( | |
427 jid_ = jid.JID("simple@example.org"), | |
428 node = None | |
429 ) == "___simple.40example.2eorg@ap.test.example" | |
430 | |
431 # local jid with non microblog node | |
432 assert await get_account( | |
433 jid_ = jid.JID("simple@test.example"), | |
434 node = "some_other_node" | |
435 ) == "some_other_node---simple@test.example" | |
436 | |
437 # local pubsub node | |
438 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
439 isPubsub.return_value = True | |
440 assert await get_account( | |
441 jid_ = jid.JID("pubsub.test.example"), | |
442 node = "some_node" | |
443 ) == "some_node@pubsub.test.example" | |
444 | |
445 # non local pubsub node | |
446 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
447 isPubsub.return_value = True | |
448 assert await get_account( | |
449 jid_ = jid.JID("pubsub.example.org"), | |
450 node = "some_node" | |
451 ) == "___some_node.40pubsub.2eexample.2eorg@ap.test.example" | |
452 | |
453 @ed | |
454 async def test_ap_handle_convert_to_jid_and_node(self, ap_gateway, monkeypatch): | |
455 """AP actor handle convert correctly to JID and pubsub node""" | |
456 get_jid_node = ap_gateway.getJIDAndNode | |
457 | |
458 # for following assertion, host is not a pubsub service | |
459 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
460 isPubsub.return_value = False | |
461 | |
462 # simple local jid | |
463 assert await get_jid_node( | |
464 "toto@test.example" | |
465 ) == (jid.JID("toto@test.example"), None) | |
466 | |
467 # simple external jid | |
468 | |
469 ## with "local_only" set, it should raise an exception | |
470 with pytest.raises(exceptions.PermissionError): | |
471 await get_jid_node("toto@example.org") | |
472 | |
473 ## with "local_only" unset, it should work | |
474 with monkeypatch.context() as m: | |
475 m.setattr(ap_gateway, "local_only", False, raising=True) | |
476 assert await get_jid_node( | |
477 "toto@example.org" | |
478 ) == (jid.JID("toto@example.org"), None) | |
479 | |
480 # explicit node | |
481 assert await get_jid_node( | |
482 "tata---toto@test.example" | |
483 ) == (jid.JID("toto@test.example"), "tata") | |
484 | |
485 # for following assertion, host is a pubsub service | |
486 with patch.object(ap_gateway, "isPubsub") as isPubsub: | |
487 isPubsub.return_value = True | |
488 | |
489 # simple local node | |
490 assert await get_jid_node( | |
491 "toto@pubsub.test.example" | |
492 ) == (jid.JID("pubsub.test.example"), "toto") | |
493 | |
494 # encoded local node | |
495 assert await get_jid_node( | |
496 "___urn.3axmpp.3amicroblog.3a0@pubsub.test.example" | |
497 ) == (jid.JID("pubsub.test.example"), "urn:xmpp:microblog:0") | |
498 | |
499 @ed | |
500 async def test_ap_to_pubsub_conversion(self, ap_gateway, monkeypatch): | |
501 """AP requests are converted to pubsub""" | |
502 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_ap_get) | |
503 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) | |
504 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get) | |
505 | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
506 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
|
507 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
|
508 items, rsm_resp = await ap_gateway.getAPItems(outbox, 2) |
3733 | 509 |
510 assert rsm_resp.count == 4 | |
511 assert rsm_resp.index == 0 | |
512 assert rsm_resp.first == "https://example.org/users/test_user/statuses/4" | |
513 assert rsm_resp.last == "https://example.org/users/test_user/statuses/3" | |
514 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
515 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
516 assert title_xhtml.toXml() == ( |
3733 | 517 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
518 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 4</p></div>" | |
519 "</title>" | |
520 ) | |
521 author_uri = str( | |
522 [e for e in items[0].entry.author.elements() if e.name == "uri"][0] | |
523 ) | |
524 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
525 assert str(items[0].entry.published) == "2021-12-16T17:25:03Z" | |
526 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
527 title_xhtml = self.getTitleXHTML(items[1]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
528 assert title_xhtml.toXml() == ( |
3733 | 529 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
530 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" | |
531 "</title>" | |
532 ) | |
533 author_uri = str( | |
534 [e for e in items[1].entry.author.elements() if e.name == "uri"][0] | |
535 ) | |
536 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
537 assert str(items[1].entry.published) == "2021-12-16T17:26:03Z" | |
538 | |
539 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
|
540 outbox, |
3733 | 541 max_items=2, |
542 after_id="https://example.org/users/test_user/statuses/3", | |
543 ) | |
544 | |
545 assert rsm_resp.count == 4 | |
546 assert rsm_resp.index == 2 | |
547 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" | |
548 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" | |
549 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
550 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
551 assert title_xhtml.toXml() == ( |
3733 | 552 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
553 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" | |
554 "</title>" | |
555 ) | |
556 author_uri = str( | |
557 [e for e in items[0].entry.author.elements() if e.name == "uri"][0] | |
558 ) | |
559 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
560 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" | |
561 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
562 title_xhtml = self.getTitleXHTML(items[1]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
563 assert title_xhtml.toXml() == ( |
3733 | 564 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
565 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" | |
566 "</title>" | |
567 ) | |
568 author_uri = str( | |
569 [e for e in items[1].entry.author.elements() if e.name == "uri"][0] | |
570 ) | |
571 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
572 assert str(items[1].entry.published) == "2021-12-16T17:28:03Z" | |
573 | |
574 items, rsm_resp = await ap_gateway.getAPItems( | |
3735
04ecc8eeb81a
tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents:
3733
diff
changeset
|
575 outbox, |
3733 | 576 max_items=1, |
577 start_index=2 | |
578 ) | |
579 | |
580 assert rsm_resp.count == 4 | |
581 assert rsm_resp.index == 2 | |
582 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" | |
583 assert rsm_resp.last == "https://example.org/users/test_user/statuses/2" | |
584 assert len(items) == 1 | |
585 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
586 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
587 assert title_xhtml.toXml() == ( |
3733 | 588 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
589 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" | |
590 "</title>" | |
591 ) | |
592 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" | |
593 | |
594 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
|
595 outbox, |
3733 | 596 max_items=3, |
597 chronological_pagination=False | |
598 ) | |
599 assert rsm_resp.count == 4 | |
600 assert rsm_resp.index == 1 | |
601 assert rsm_resp.first == "https://example.org/users/test_user/statuses/3" | |
602 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" | |
603 assert len(items) == 3 | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
604 title_xhtml = self.getTitleXHTML(items[0]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
605 assert title_xhtml.toXml() == ( |
3733 | 606 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
607 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" | |
608 "</title>" | |
609 ) | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
610 title_xhtml = self.getTitleXHTML(items[2]) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
611 assert title_xhtml.toXml() == ( |
3733 | 612 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
613 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" | |
614 "</title>" | |
615 ) | |
616 | |
617 def ap_request_params(self, ap_gateway, type_=None, url=None, query_data=None): | |
618 """Generate parameters for HTTPAPGServer's AP*Request | |
619 | |
620 @param type_: one of the AP query type (e.g. "outbox") | |
621 @param url: URL to query (mutually exclusif with type_) | |
622 @param query_data: query data as returned by parse.parse_qs | |
623 @return dict with kw params to use | |
624 """ | |
625 assert type_ and url is None or url and type_ is None | |
626 if type_ is not None: | |
627 path = f"_ap/{type_}/some_user%40test.example" | |
628 else: | |
629 url_parsed = parse.urlparse(url) | |
630 path = url_parsed.path.lstrip("/") | |
631 type_ = path.split("/")[1] | |
632 if query_data is None: | |
633 query_data = parse.parse_qs(url_parsed.query) | |
634 | |
635 if query_data: | |
636 uri = f"{path}?{parse.urlencode(query_data, doseq=True)}" | |
637 else: | |
638 uri = path | |
639 | |
640 test_jid = jid.JID("some_user@test.example") | |
641 request = Request(MagicMock()) | |
642 request.path = path.encode() | |
643 request.uri = uri.encode() | |
644 ap_url = parse.urljoin( | |
645 f"https://{ap_gateway.public_url}", | |
646 path | |
647 ) | |
648 kwargs = { | |
649 "request": request, | |
650 "account_jid": test_jid, | |
651 "node": None, | |
652 "ap_account": test_jid.full(), | |
653 "ap_url": ap_url, | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
654 "signing_actor": None |
3733 | 655 } |
656 if type_ == "outbox" and query_data: | |
657 kwargs["query_data"] = query_data | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
658 # 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
|
659 del kwargs["signing_actor"] |
3733 | 660 return kwargs |
661 | |
662 @ed | |
663 async def test_pubsub_to_ap_conversion(self, ap_gateway, monkeypatch): | |
664 """Pubsub nodes are converted to AP collections""" | |
665 monkeypatch.setattr(ap_gateway._p, "getItems", mock_getItems) | |
666 outbox = await ap_gateway.server.resource.APOutboxRequest( | |
667 **self.ap_request_params(ap_gateway, "outbox") | |
668 ) | |
669 assert outbox["@context"] == "https://www.w3.org/ns/activitystreams" | |
670 assert outbox["id"] == "https://test.example/_ap/outbox/some_user%40test.example" | |
671 assert outbox["totalItems"] == len(XMPP_ITEMS) | |
672 assert outbox["type"] == "OrderedCollection" | |
673 assert outbox["first"] | |
674 assert outbox["last"] | |
675 | |
676 first_page = await ap_gateway.server.resource.APOutboxPageRequest( | |
677 **self.ap_request_params(ap_gateway, url=outbox["first"]) | |
678 ) | |
679 assert first_page["@context"] == "https://www.w3.org/ns/activitystreams" | |
680 assert first_page["id"] == "https://test.example/_ap/outbox/some_user%40test.example?page=first" | |
681 assert first_page["type"] == "OrderedCollectionPage" | |
682 assert first_page["partOf"] == outbox["id"] | |
683 assert len(first_page["orderedItems"]) == len(XMPP_ITEMS) | |
684 first_item = first_page["orderedItems"][0] | |
685 assert first_item["@context"] == "https://www.w3.org/ns/activitystreams" | |
686 assert first_item["id"] == "https://test.example/_ap/item/some_user%40test.example/4" | |
687 assert first_item["actor"] == "https://test.example/_ap/actor/some_user%40test.example" | |
688 assert first_item["type"] == "Create" | |
689 first_item_obj = first_item["object"] | |
690 assert first_item_obj["id"] == first_item["id"] | |
691 assert first_item_obj["type"] == "Note" | |
692 assert first_item_obj["published"] == "2022-01-28T16:02:19Z" | |
693 assert first_item_obj["attributedTo"] == first_item["actor"] | |
694 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
|
695 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
|
696 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
697 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
698 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
|
699 """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
|
700 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
|
701 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
|
702 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
|
703 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
704 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
|
705 jid.JID("toto@example.org"), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
706 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
707 ap_gateway._pps.subscriptions_node, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
708 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
709 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
710 None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
711 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
712 assert len(items) == 2 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
713 for idx, entity in enumerate(( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
714 "local_user@test.example", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
715 "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
|
716 )): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
717 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
|
718 assert subscription_elt is not None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
719 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
|
720 assert subscription_elt["service"] == entity |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
721 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
722 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
723 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
|
724 """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
|
725 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
|
726 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
|
727 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
|
728 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
729 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
|
730 jid.JID("toto@example.org"), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
731 ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
732 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
|
733 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
734 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
735 None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
736 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
737 assert len(items) == 2 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
738 for idx, entity in enumerate(( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
739 "local_user@test.example", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
740 "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
|
741 )): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
742 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
|
743 assert subscriber_elt is not None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
744 assert subscriber_elt["jid"] == entity |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
745 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
746 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
747 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
|
748 """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
|
749 subscriptions = [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
750 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
751 id="subscription_1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
752 payload = ap_gateway._pps.buildSubscriptionElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
753 ap_gateway._m.namespace, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
754 jid.JID("local_user@test.example") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
755 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
756 ), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
757 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
758 id="subscription_2", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
759 payload = ap_gateway._pps.buildSubscriptionElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
760 ap_gateway._m.namespace, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
761 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
|
762 ) |
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 ] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
765 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
|
766 mock_getItems, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
767 ret_items=subscriptions |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
768 )) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
769 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
|
770 **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
|
771 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
772 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
|
773 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
|
774 assert following["totalItems"] == len(subscriptions) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
775 assert following["type"] == "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
776 assert following.get("first") |
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 first_page = following["first"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
779 assert first_page["type"] == "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
780 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
|
781 items = first_page["orderedItems"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
782 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
|
783 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
784 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
785 async def test_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
|
786 """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
|
787 subscribers = [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
788 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
789 id="subscriber_1", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
790 payload = ap_gateway._pps.buildSubscriberElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
791 jid.JID("local_user@test.example") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
792 ) |
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 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
795 id="subscriber_2", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
796 payload = ap_gateway._pps.buildSubscriberElt( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
797 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
|
798 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
799 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
800 ] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
801 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
|
802 mock_getItems, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
803 ret_items=subscribers |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
804 )) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
805 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
|
806 **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
|
807 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
808 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
|
809 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
|
810 assert followers["totalItems"] == len(subscribers) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
811 assert followers["type"] == "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
812 assert followers.get("first") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
813 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
814 first_page = followers["first"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
815 assert first_page["type"] == "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
816 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
|
817 items = first_page["orderedItems"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
818 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
|
819 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
820 @ed |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
821 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
|
822 """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
|
823 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
|
824 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
|
825 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
|
826 message_elt = domish.Element((None, "message")) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
827 message_elt.addElement("body", 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
|
828 message_elt["from"] = TEST_JID.full() |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
829 message_elt["to"] = ap_gateway.getLocalJIDFromAccount(TEST_AP_ACCOUNT).full() |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
830 with patch.object(ap_gateway, "signAndPost") as signAndPost: |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
831 await ap_gateway.onMessage(message_elt) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
832 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
|
833 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
|
834 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
|
835 obj = doc["object"] |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
836 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
|
837 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
|
838 assert obj["type"] == "Note" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
839 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
|
840 assert obj["attributedTo"] == ( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
841 "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
|
842 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
843 # 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
|
844 # ("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
|
845 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
|
846 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
|
847 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
|
848 assert field not in doc |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
849 assert field not in obj |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
850 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
851 @ed |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
852 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
|
853 """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
|
854 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
|
855 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
|
856 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
|
857 # 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
|
858 monkeypatch.setattr(defer, "DeferredList", AsyncMock()) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
859 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
860 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
|
861 direct_ap_message = { |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
862 'attributedTo': TEST_AP_ACTOR_ID, |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
863 'cc': [], |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
864 '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
|
865 '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
|
866 '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
|
867 '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
|
868 'to': [xmpp_actor_id], |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
869 'type': 'Note', |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
870 } |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
871 client = ap_gateway.client.getVirtualClient( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
872 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
|
873 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
874 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
|
875 await ap_gateway.newAPItem( |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
876 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
|
877 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
878 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
879 # 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
|
880 # 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
|
881 assert sendMessage.called |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
882 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
|
883 assert sendMessage.call_args.args[1] == {"": "test direct message"} |