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