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