Mercurial > libervia-backend
annotate tests/unit/test_ap-gateway.py @ 4309:b56b1eae7994
component email gateway: add multicasting:
XEP-0033 multicasting is now supported both for incoming and outgoing messages. XEP-0033
metadata are converted to suitable Email headers and vice versa.
Email address and JID are both supported, and delivery is done by the gateway when
suitable on incoming messages.
rel 450
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 26 Sep 2024 16:12:01 +0200 |
parents | f1d0cde61af7 |
children | 2246eeeccc74 |
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 |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
37 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
38 from libervia.backend.core.constants import Const as C |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
39 from libervia.backend.memory.sqla_mapping import SubscriptionState |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
40 from libervia.backend.plugins import plugin_comp_ap_gateway |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
41 from libervia.backend.plugins.plugin_comp_ap_gateway import constants as ap_const |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
42 from libervia.backend.plugins.plugin_comp_ap_gateway import TYPE_ACTOR |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
43 from libervia.backend.plugins.plugin_comp_ap_gateway.http_server import HTTPServer |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
44 from libervia.backend.plugins.plugin_xep_0277 import NS_ATOM |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
45 from libervia.backend.plugins.plugin_xep_0424 import NS_MESSAGE_RETRACT |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
46 from libervia.backend.plugins.plugin_xep_0465 import NS_PPS |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
47 from libervia.backend.tools import xml_tools |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
48 from libervia.backend.tools.common import uri as xmpp_uri |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
49 from libervia.backend.tools.utils import xmpp_date |
3733 | 50 |
51 | |
52 TEST_BASE_URL = "https://example.org" | |
53 TEST_USER = "test_user" | |
54 TEST_AP_ACCOUNT = f"{TEST_USER}@example.org" | |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
55 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
|
56 PUBLIC_URL = "test.example" |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
57 TEST_JID = jid.JID(f"some_user@{PUBLIC_URL}") |
3733 | 58 |
59 AP_REQUESTS = { | |
60 f"{TEST_BASE_URL}/.well-known/webfinger?" | |
61 f"resource=acct:{parse.quote(TEST_AP_ACCOUNT)}": { | |
62 "aliases": [ | |
63 f"{TEST_BASE_URL}/@{TEST_USER}", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
64 f"{TEST_BASE_URL}/users/{TEST_USER}", |
3733 | 65 ], |
66 "links": [ | |
67 { | |
68 "href": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
69 "rel": "self", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
70 "type": "application/activity+json", |
3733 | 71 }, |
72 ], | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
73 "subject": f"acct:{TEST_AP_ACCOUNT}", |
3733 | 74 }, |
75 f"{TEST_BASE_URL}/users/{TEST_USER}": { | |
76 "@context": [ | |
77 "https://www.w3.org/ns/activitystreams", | |
78 ], | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
79 "endpoints": {"sharedInbox": f"{TEST_BASE_URL}/inbox"}, |
3733 | 80 "followers": f"{TEST_BASE_URL}/users/{TEST_USER}/followers", |
81 "following": f"{TEST_BASE_URL}/users/{TEST_USER}/following", | |
82 "id": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
83 "inbox": f"{TEST_BASE_URL}/users/{TEST_USER}/inbox", | |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
84 "name": "test_user nickname", |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
85 "summary": "<p>test account</p>", |
3733 | 86 "outbox": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", |
87 "preferredUsername": f"{TEST_USER}", | |
88 "type": "Person", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
89 "url": f"{TEST_BASE_URL}/@{TEST_USER}", |
3733 | 90 }, |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
91 f"{TEST_BASE_URL}/.well-known/webfinger?" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
92 f"resource=acct:{parse.quote('ext_user@example.org')}": { |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
93 "aliases": [f"{TEST_BASE_URL}/@ext_user", f"{TEST_BASE_URL}/users/ext_user"], |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
94 "links": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
95 { |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
96 "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
|
97 "rel": "self", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
98 "type": "application/activity+json", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
99 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
100 ], |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
101 "subject": f"acct:ext_user@example.org", |
3770
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 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 "@context": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
105 "https://www.w3.org/ns/activitystreams", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
106 ], |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
107 "endpoints": {"sharedInbox": f"{TEST_BASE_URL}/inbox"}, |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
108 "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
|
109 "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
|
110 "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
|
111 "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
|
112 "name": "", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
113 "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
|
114 "preferredUsername": f"ext_user", |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
115 "type": "Person", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
116 "url": f"{TEST_BASE_URL}/@ext_user", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
117 }, |
3733 | 118 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox": { |
119 "@context": "https://www.w3.org/ns/activitystreams", | |
120 "first": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
121 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", | |
122 "last": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
123 "totalItems": 4, | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
124 "type": "OrderedCollection", |
3733 | 125 }, |
126 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true": { | |
127 "@context": [ | |
128 "https://www.w3.org/ns/activitystreams", | |
129 ], | |
130 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true", | |
131 "orderedItems": [ | |
132 { | |
133 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
134 "cc": [ | |
135 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
136 ], | |
137 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1/activity", | |
138 "object": { | |
139 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
140 "cc": [ | |
141 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
142 ], | |
143 "content": "<p>test message 1</p>", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
144 "contentMap": {"en": "<p>test message 1</p>"}, |
3733 | 145 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1", |
146 "inReplyTo": None, | |
147 "published": "2021-12-16T17:28:03Z", | |
148 "sensitive": False, | |
149 "summary": None, | |
150 "tag": [], | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
151 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
3733 | 152 "type": "Note", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
153 "url": f"{TEST_BASE_URL}/@{TEST_USER}/1", |
3733 | 154 }, |
155 "published": "2021-12-16T17:28:03Z", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
156 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
157 "type": "Create", |
3733 | 158 }, |
159 { | |
160 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
161 "cc": [ | |
162 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
163 ], | |
164 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2/activity", | |
165 "object": { | |
166 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
167 "cc": [ | |
168 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
169 ], | |
170 "content": "<p>test message 2</p>", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
171 "contentMap": {"en": "<p>test message 2</p>"}, |
3733 | 172 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2", |
173 "inReplyTo": None, | |
174 "published": "2021-12-16T17:27:03Z", | |
175 "sensitive": False, | |
176 "summary": None, | |
177 "tag": [], | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
178 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
3733 | 179 "type": "Note", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
180 "url": f"{TEST_BASE_URL}/@{TEST_USER}/2", |
3733 | 181 }, |
182 "published": "2021-12-16T17:27:03Z", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
183 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
184 "type": "Create", |
3733 | 185 }, |
186 { | |
187 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
188 "cc": [ | |
189 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
190 ], | |
191 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3/activity", | |
192 "object": { | |
193 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
194 "cc": [ | |
195 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
196 ], | |
197 "content": "<p>test message 3</p>", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
198 "contentMap": {"en": "<p>test message 3</p>"}, |
3733 | 199 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3", |
200 "inReplyTo": None, | |
201 "published": "2021-12-16T17:26:03Z", | |
202 "sensitive": False, | |
203 "summary": None, | |
204 "tag": [], | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
205 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
3733 | 206 "type": "Note", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
207 "url": f"{TEST_BASE_URL}/@{TEST_USER}/3", |
3733 | 208 }, |
209 "published": "2021-12-16T17:26:03Z", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
210 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
211 "type": "Create", |
3733 | 212 }, |
213 { | |
214 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
215 "cc": [ | |
216 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
217 ], | |
218 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4/activity", | |
219 "object": { | |
220 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}", | |
221 "cc": [ | |
222 f"{TEST_BASE_URL}/users/{TEST_USER}/followers", | |
223 ], | |
224 "content": "<p>test message 4</p>", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
225 "contentMap": {"en": "<p>test message 4</p>"}, |
3733 | 226 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4", |
227 "inReplyTo": None, | |
228 "published": "2021-12-16T17:25:03Z", | |
229 "sensitive": False, | |
230 "summary": None, | |
231 "tag": [], | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
232 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
3733 | 233 "type": "Note", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
234 "url": f"{TEST_BASE_URL}/@{TEST_USER}/4", |
3733 | 235 }, |
236 "published": "2021-12-16T17:25:03Z", | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
237 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
238 "type": "Create", |
3733 | 239 }, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
240 ], |
3733 | 241 "partOf": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox", |
242 "prev": None, | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
243 "type": "OrderedCollectionPage", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
244 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
245 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
|
246 "@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
|
247 "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
|
248 "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
|
249 "totalItems": 2, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
250 "type": "OrderedCollection", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
251 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
252 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
|
253 "@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
|
254 "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
|
255 "orderedItems": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
256 f"{TEST_BASE_URL}/users/ext_user", |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
257 f"https://{PUBLIC_URL}/_ap/{TYPE_ACTOR}/local_user@{PUBLIC_URL}", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
258 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
259 "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
|
260 "totalItems": 2, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
261 "type": "OrderedCollectionPage", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
262 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
263 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
|
264 "@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
|
265 "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
|
266 "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
|
267 "totalItems": 2, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
268 "type": "OrderedCollection", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
269 }, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
270 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
|
271 "@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
|
272 "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
|
273 "orderedItems": [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
274 f"{TEST_BASE_URL}/users/ext_user", |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
275 f"https://{PUBLIC_URL}/_ap/{TYPE_ACTOR}/local_user@{PUBLIC_URL}", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
276 ], |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
277 "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
|
278 "totalItems": 2, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
279 "type": "OrderedCollectionPage", |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
280 }, |
3733 | 281 } |
282 | |
283 XMPP_ITEM_TPL = """ | |
284 <item id='{id}' publisher='{publisher_jid}'> | |
285 <entry xmlns='http://www.w3.org/2005/Atom' xml:lang='en'> | |
286 <title type='xhtml'> | |
287 <div xmlns='http://www.w3.org/1999/xhtml'> | |
288 <p> | |
289 XMPP item {id} | |
290 </p> | |
291 </div> | |
292 </title> | |
293 <title type='text'> | |
294 XMPP item {id} | |
295 </title> | |
296 <author> | |
297 <name> | |
298 test_user | |
299 </name> | |
300 <uri> | |
301 xmpp:{publisher_jid} | |
302 </uri> | |
303 </author> | |
304 <updated> | |
305 {updated} | |
306 </updated> | |
307 <published> | |
308 {published} | |
309 </published> | |
310 <id> | |
311 xmpp:{publisher_jid}?;node=urn%3Axmpp%3Amicroblog%3A0;item={id} | |
312 </id> | |
313 </entry> | |
314 </item> | |
315 """ | |
316 | |
317 ITEM_BASE_TS = 1643385499 | |
318 XMPP_ITEMS = [ | |
319 xml_tools.parse( | |
320 "".join( | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
321 l.strip() |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
322 for l in XMPP_ITEM_TPL.format( |
3733 | 323 id=i, |
324 publisher_jid="some_user@test.example", | |
325 updated=xmpp_date(ITEM_BASE_TS + i * 60), | |
326 published=xmpp_date(ITEM_BASE_TS + i * 60), | |
327 ).split("\n") | |
328 ), | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
329 namespace=pubsub.NS_PUBSUB, |
3733 | 330 ) |
331 for i in range(1, 5) | |
332 ] | |
333 | |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
334 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
|
335 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
|
336 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
|
337 # 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
|
338 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
|
339 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
|
340 |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
341 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
342 async def mock_treq_get(url): |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
343 return deepcopy(AP_REQUESTS[url]) |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
344 |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
345 |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
346 async def mock_ap_get(url, requestor_actor_id): |
3733 | 347 return deepcopy(AP_REQUESTS[url]) |
348 | |
349 | |
350 async def mock_treq_json(data): | |
351 return dict(data) | |
352 | |
353 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
354 async def mock_get_items(client, service, node, *args, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
355 """Mock get_items |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
356 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
357 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
|
358 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
|
359 returned |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
360 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
|
361 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
|
362 """ |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
363 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
|
364 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
|
365 raise StanzaError("item-not-found") |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
366 ret_items = kwargs.pop("ret_items", XMPP_ITEMS) |
3733 | 367 rsm_resp = rsm.RSMResponse( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
368 first=ret_items[0]["id"], last=ret_items[-1]["id"], index=0, count=len(ret_items) |
3733 | 369 ) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
370 return ret_items, {"rsm": rsm_resp.toDict(), "complete": True} |
3733 | 371 |
372 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
373 async def mock_get_pubsub_node(client, service, node, with_subscriptions=False, **kwargs): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
374 """Mock storage's get_pubsub_node |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
375 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
376 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
|
377 """ |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
378 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
|
379 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
|
380 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
|
381 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
382 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
383 def mock_client(jid): |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
384 client = MagicMock() |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
385 client.jid = jid |
3890
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
386 client.host = "test.example" |
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
387 client._ap_storage.get = AsyncMock() |
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
388 client._ap_storage.aset = AsyncMock() |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
389 return client |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
390 |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
391 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
392 def get_virtual_client(jid): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
393 return mock_client(jid) |
3890
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
394 |
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
395 |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
396 class FakeTReqPostResponse: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
397 code = 202 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
398 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
399 |
3733 | 400 @pytest.fixture(scope="session") |
401 def ap_gateway(host): | |
402 gateway = plugin_comp_ap_gateway.APGateway(host) | |
403 gateway.initialised = True | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
404 gateway.is_pubsub = AsyncMock() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
405 gateway.is_pubsub.return_value = False |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
406 client = mock_client(jid.JID("ap.test.example")) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
407 client.get_virtual_client = get_virtual_client |
3733 | 408 gateway.client = client |
409 gateway.local_only = True | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
410 gateway.public_url = PUBLIC_URL |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
411 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
|
412 gateway.auto_mentions = True |
3733 | 413 gateway.base_ap_url = parse.urljoin( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
414 f"https://{gateway.public_url}", f"{gateway.ap_path}/" |
3733 | 415 ) |
416 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
|
417 gateway.public_key_pem = None |
3733 | 418 return gateway |
419 | |
420 | |
421 class TestActivityPubGateway: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
422 def get_title_xhtml(self, item_elt: domish.Element) -> domish.Element: |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
423 return next( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
424 t |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
425 for t in item_elt.entry.elements(NS_ATOM, "title") |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
426 if t.getAttribute("type") == "xhtml" |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
427 ) |
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
428 |
3733 | 429 @ed |
430 async def test_jid_and_node_convert_to_ap_handle(self, ap_gateway): | |
431 """JID and pubsub node are converted correctly to an AP actor handle""" | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
432 get_account = ap_gateway.get_ap_account_from_jid_and_node |
3733 | 433 |
434 # local jid | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
435 assert ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
436 await get_account(jid_=jid.JID("simple@test.example"), node=None) |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
437 == "simple@test.example" |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
438 ) |
3733 | 439 |
440 # non local jid | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
441 assert ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
442 await get_account(jid_=jid.JID("simple@example.org"), node=None) |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
443 == "___simple.40example.2eorg@ap.test.example" |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
444 ) |
3733 | 445 |
446 # local jid with non microblog node | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
447 assert ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
448 await get_account(jid_=jid.JID("simple@test.example"), node="some_other_node") |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
449 == "some_other_node---simple@test.example" |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
450 ) |
3733 | 451 |
452 # local pubsub node | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
453 with patch.object(ap_gateway, "is_pubsub") as is_pubsub: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
454 is_pubsub.return_value = True |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
455 assert ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
456 await get_account(jid_=jid.JID("pubsub.test.example"), node="some_node") |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
457 == "some_node@pubsub.test.example" |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
458 ) |
3733 | 459 |
460 # non local pubsub node | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
461 with patch.object(ap_gateway, "is_pubsub") as is_pubsub: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
462 is_pubsub.return_value = True |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
463 assert ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
464 await get_account(jid_=jid.JID("pubsub.example.org"), node="some_node") |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
465 == "___some_node.40pubsub.2eexample.2eorg@ap.test.example" |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
466 ) |
3733 | 467 |
468 @ed | |
469 async def test_ap_handle_convert_to_jid_and_node(self, ap_gateway, monkeypatch): | |
470 """AP actor handle convert correctly to JID and pubsub node""" | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
471 get_jid_node = ap_gateway.get_jid_and_node |
3733 | 472 |
473 # for following assertion, host is not a pubsub service | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
474 with patch.object(ap_gateway, "is_pubsub") as is_pubsub: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
475 is_pubsub.return_value = False |
3733 | 476 |
477 # simple local jid | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
478 assert await get_jid_node("toto@test.example") == ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
479 jid.JID("toto@test.example"), |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
480 None, |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
481 ) |
3733 | 482 |
483 # simple external jid | |
484 | |
485 ## with "local_only" set, it should raise an exception | |
486 with pytest.raises(exceptions.PermissionError): | |
487 await get_jid_node("toto@example.org") | |
488 | |
489 ## with "local_only" unset, it should work | |
490 with monkeypatch.context() as m: | |
491 m.setattr(ap_gateway, "local_only", False, raising=True) | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
492 assert await get_jid_node("toto@example.org") == ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
493 jid.JID("toto@example.org"), |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
494 None, |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
495 ) |
3733 | 496 |
497 # explicit node | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
498 assert await get_jid_node("tata---toto@test.example") == ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
499 jid.JID("toto@test.example"), |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
500 "tata", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
501 ) |
3733 | 502 |
503 # for following assertion, host is a pubsub service | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
504 with patch.object(ap_gateway, "is_pubsub") as is_pubsub: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
505 is_pubsub.return_value = True |
3733 | 506 |
507 # simple local node | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
508 assert await get_jid_node("toto@pubsub.test.example") == ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
509 jid.JID("pubsub.test.example"), |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
510 "toto", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
511 ) |
3733 | 512 |
513 # encoded local node | |
514 assert await get_jid_node( | |
515 "___urn.3axmpp.3amicroblog.3a0@pubsub.test.example" | |
516 ) == (jid.JID("pubsub.test.example"), "urn:xmpp:microblog:0") | |
517 | |
518 @ed | |
519 async def test_ap_to_pubsub_conversion(self, ap_gateway, monkeypatch): | |
520 """AP requests are converted to pubsub""" | |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
521 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3733 | 522 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
523 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3733 | 524 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
525 actor_data = await ap_gateway.get_ap_actor_data_from_account( |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
526 TEST_AP_ACTOR_ID, TEST_AP_ACCOUNT |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
527 ) |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
528 outbox = await ap_gateway.ap_get_object(TEST_AP_ACTOR_ID, actor_data, "outbox") |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
529 items, rsm_resp = await ap_gateway.get_ap_items(TEST_AP_ACTOR_ID, outbox, 2) |
3733 | 530 |
531 assert rsm_resp.count == 4 | |
532 assert rsm_resp.index == 0 | |
533 assert rsm_resp.first == "https://example.org/users/test_user/statuses/4" | |
534 assert rsm_resp.last == "https://example.org/users/test_user/statuses/3" | |
535 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
536 title_xhtml = self.get_title_xhtml(items[0]) |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
537 assert title_xhtml.toXml() == ( |
3733 | 538 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
539 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 4</p></div>" | |
540 "</title>" | |
541 ) | |
542 author_uri = str( | |
543 [e for e in items[0].entry.author.elements() if e.name == "uri"][0] | |
544 ) | |
545 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
546 assert str(items[0].entry.published) == "2021-12-16T17:25:03Z" | |
547 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
548 title_xhtml = self.get_title_xhtml(items[1]) |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
549 assert title_xhtml.toXml() == ( |
3733 | 550 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
551 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" | |
552 "</title>" | |
553 ) | |
554 author_uri = str( | |
555 [e for e in items[1].entry.author.elements() if e.name == "uri"][0] | |
556 ) | |
557 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
558 assert str(items[1].entry.published) == "2021-12-16T17:26:03Z" | |
559 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
560 items, rsm_resp = await ap_gateway.get_ap_items( |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
561 TEST_AP_ACTOR_ID, |
3735
04ecc8eeb81a
tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents:
3733
diff
changeset
|
562 outbox, |
3733 | 563 max_items=2, |
564 after_id="https://example.org/users/test_user/statuses/3", | |
565 ) | |
566 | |
567 assert rsm_resp.count == 4 | |
568 assert rsm_resp.index == 2 | |
569 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" | |
570 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" | |
571 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
572 title_xhtml = self.get_title_xhtml(items[0]) |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
573 assert title_xhtml.toXml() == ( |
3733 | 574 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
575 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 2</p></div>" | |
576 "</title>" | |
577 ) | |
578 author_uri = str( | |
579 [e for e in items[0].entry.author.elements() if e.name == "uri"][0] | |
580 ) | |
581 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
582 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" | |
583 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
584 title_xhtml = self.get_title_xhtml(items[1]) |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
585 assert title_xhtml.toXml() == ( |
3733 | 586 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
587 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" | |
588 "</title>" | |
589 ) | |
590 author_uri = str( | |
591 [e for e in items[1].entry.author.elements() if e.name == "uri"][0] | |
592 ) | |
593 assert author_uri == "xmpp:test_user\\40example.org@ap.test.example" | |
594 assert str(items[1].entry.published) == "2021-12-16T17:28:03Z" | |
595 | |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
596 items, rsm_resp = await ap_gateway.get_ap_items( |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
597 TEST_AP_ACTOR_ID, outbox, max_items=1, start_index=2 |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
598 ) |
3733 | 599 |
600 assert rsm_resp.count == 4 | |
601 assert rsm_resp.index == 2 | |
602 assert rsm_resp.first == "https://example.org/users/test_user/statuses/2" | |
603 assert rsm_resp.last == "https://example.org/users/test_user/statuses/2" | |
604 assert len(items) == 1 | |
605 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
606 title_xhtml = self.get_title_xhtml(items[0]) |
3783
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 2</p></div>" | |
610 "</title>" | |
611 ) | |
612 assert str(items[0].entry.published) == "2021-12-16T17:27:03Z" | |
613 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
614 items, rsm_resp = await ap_gateway.get_ap_items( |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
615 TEST_AP_ACTOR_ID, outbox, max_items=3, chronological_pagination=False |
3733 | 616 ) |
617 assert rsm_resp.count == 4 | |
618 assert rsm_resp.index == 1 | |
619 assert rsm_resp.first == "https://example.org/users/test_user/statuses/3" | |
620 assert rsm_resp.last == "https://example.org/users/test_user/statuses/1" | |
621 assert len(items) == 3 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
622 title_xhtml = self.get_title_xhtml(items[0]) |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
623 assert title_xhtml.toXml() == ( |
3733 | 624 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
625 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 3</p></div>" | |
626 "</title>" | |
627 ) | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
628 title_xhtml = self.get_title_xhtml(items[2]) |
3783
fedbf7aade11
tests (unit/ap_gateway): fix tests
Goffi <goffi@goffi.org>
parents:
3770
diff
changeset
|
629 assert title_xhtml.toXml() == ( |
3733 | 630 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>" |
631 "<div xmlns='http://www.w3.org/1999/xhtml'><p>test message 1</p></div>" | |
632 "</title>" | |
633 ) | |
634 | |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
635 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
|
636 self, |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
637 ap_gateway, |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
638 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
|
639 url: Optional[str] = None, |
3981
acc9dfc8ba8d
component AP gateway: parse body immediately on `POST` request:
Goffi <goffi@goffi.org>
parents:
3908
diff
changeset
|
640 data: Optional[dict] = None, |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
641 query_data: Optional[dict] = None, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
642 signing_actor: Optional[str] = None, |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
643 ) -> Dict[str, Any]: |
3733 | 644 """Generate parameters for HTTPAPGServer's AP*Request |
645 | |
646 @param type_: one of the AP query type (e.g. "outbox") | |
647 @param url: URL to query (mutually exclusif with type_) | |
3981
acc9dfc8ba8d
component AP gateway: parse body immediately on `POST` request:
Goffi <goffi@goffi.org>
parents:
3908
diff
changeset
|
648 @param data: object used as body of the request |
3733 | 649 @param query_data: query data as returned by parse.parse_qs |
650 @return dict with kw params to use | |
651 """ | |
652 assert type_ and url is None or url and type_ is None | |
653 if type_ is not None: | |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
654 path = f"_ap/{type_}/some_user@test.example" |
3733 | 655 else: |
656 url_parsed = parse.urlparse(url) | |
657 path = url_parsed.path.lstrip("/") | |
658 type_ = path.split("/")[1] | |
659 if query_data is None: | |
660 query_data = parse.parse_qs(url_parsed.query) | |
661 | |
662 if query_data: | |
663 uri = f"{path}?{parse.urlencode(query_data, doseq=True)}" | |
664 else: | |
665 uri = path | |
666 | |
667 test_jid = jid.JID("some_user@test.example") | |
668 request = Request(MagicMock()) | |
669 request.path = path.encode() | |
670 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
|
671 |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
672 ap_url = parse.urljoin(f"https://{ap_gateway.public_url}", path) |
3733 | 673 kwargs = { |
674 "request": request, | |
3981
acc9dfc8ba8d
component AP gateway: parse body immediately on `POST` request:
Goffi <goffi@goffi.org>
parents:
3908
diff
changeset
|
675 "data": data, |
3733 | 676 "account_jid": test_jid, |
677 "node": None, | |
678 "ap_account": test_jid.full(), | |
679 "ap_url": ap_url, | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
680 "signing_actor": signing_actor, |
3733 | 681 } |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
682 if type_ not in (ap_const.TYPE_ACTOR, "outbox", "following", "followers"): |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
683 kwargs["requestor_actor_id"] = TEST_AP_ACTOR_ID |
3733 | 684 if type_ == "outbox" and query_data: |
685 kwargs["query_data"] = query_data | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
686 # 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
|
687 del kwargs["signing_actor"] |
3733 | 688 return kwargs |
689 | |
690 @ed | |
691 async def test_pubsub_to_ap_conversion(self, ap_gateway, monkeypatch): | |
692 """Pubsub nodes are converted to AP collections""" | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
693 monkeypatch.setattr(ap_gateway._p, "get_items", mock_get_items) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
694 outbox = await ap_gateway.server.resource.ap_outbox_request( |
3733 | 695 **self.ap_request_params(ap_gateway, "outbox") |
696 ) | |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
697 assert outbox["@context"] == ["https://www.w3.org/ns/activitystreams"] |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
698 assert outbox["id"] == "https://test.example/_ap/outbox/some_user@test.example" |
3733 | 699 assert outbox["totalItems"] == len(XMPP_ITEMS) |
700 assert outbox["type"] == "OrderedCollection" | |
701 assert outbox["first"] | |
702 assert outbox["last"] | |
703 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
704 first_page = await ap_gateway.server.resource.ap_outbox_page_request( |
3733 | 705 **self.ap_request_params(ap_gateway, url=outbox["first"]) |
706 ) | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
707 assert first_page["@context"] == ["https://www.w3.org/ns/activitystreams"] |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
708 assert ( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
709 first_page["id"] |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
710 == "https://test.example/_ap/outbox/some_user@test.example?page=first" |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
711 ) |
3733 | 712 assert first_page["type"] == "OrderedCollectionPage" |
713 assert first_page["partOf"] == outbox["id"] | |
714 assert len(first_page["orderedItems"]) == len(XMPP_ITEMS) | |
715 first_item = first_page["orderedItems"][0] | |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
716 assert first_item["@context"] == ["https://www.w3.org/ns/activitystreams"] |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
717 assert ( |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
718 first_item["id"] == "https://test.example/_ap/item/some_user@test.example/4" |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
719 ) |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
720 assert ( |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
721 first_item["actor"] == "https://test.example/_ap/actor/some_user@test.example" |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
722 ) |
3733 | 723 assert first_item["type"] == "Create" |
724 first_item_obj = first_item["object"] | |
725 assert first_item_obj["id"] == first_item["id"] | |
726 assert first_item_obj["type"] == "Note" | |
727 assert first_item_obj["published"] == "2022-01-28T16:02:19Z" | |
728 assert first_item_obj["attributedTo"] == first_item["actor"] | |
729 assert first_item_obj["content"] == "<div><p>XMPP item 4</p></div>" | |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
730 assert first_item_obj["to"] == ["https://www.w3.org/ns/activitystreams#Public"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
731 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
732 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
733 async def test_following_to_pps(self, ap_gateway, monkeypatch): |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
734 """AP following items are converted to Public Pubsub Subscription subscriptions""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
735 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
736 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
737 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
738 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
739 items, __ = await ap_gateway.pubsub_service.items( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
740 jid.JID("toto@example.org"), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
741 ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT), |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
742 ap_gateway._pps.subscriptions_node, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
743 None, |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
744 None, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
745 None, |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
746 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
747 assert len(items) == 2 |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
748 for idx, entity in enumerate( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
749 ("local_user@test.example", "ext_user\\40example.org@ap.test.example") |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
750 ): |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
751 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
|
752 assert subscription_elt is not None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
753 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
|
754 assert subscription_elt["service"] == entity |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
755 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
756 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
757 async def test_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
|
758 """AP followers items are converted to Public Pubsub Subscription subscribers""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
759 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
760 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
761 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
762 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
763 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
|
764 jid.JID("toto@example.org"), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
765 ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT), |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
766 ap_gateway._pps.get_public_subscribers_node(ap_gateway._m.namespace), |
3770
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 None, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
769 None, |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
770 ) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
771 assert len(items) == 2 |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
772 for idx, entity in enumerate( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
773 ("local_user@test.example", "ext_user\\40example.org@ap.test.example") |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
774 ): |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
775 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
|
776 assert subscriber_elt is not None |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
777 assert subscriber_elt["jid"] == 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_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
|
781 """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
|
782 subscriptions = [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
783 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
784 id="subscription_1", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
785 payload=ap_gateway._pps.build_subscription_elt( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
786 ap_gateway._m.namespace, jid.JID("local_user@test.example") |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
787 ), |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
788 ), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
789 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
790 id="subscription_2", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
791 payload=ap_gateway._pps.build_subscription_elt( |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
792 ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
793 jid.JID("ext_user\\40example.org@ap.test.example"), |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
794 ), |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
795 ), |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
796 ] |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
797 monkeypatch.setattr( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
798 ap_gateway._p, "get_items", partial(mock_get_items, ret_items=subscriptions) |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
799 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
800 following = await ap_gateway.server.resource.ap_following_request( |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
801 **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
|
802 ) |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
803 assert following["@context"] == ["https://www.w3.org/ns/activitystreams"] |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
804 assert ( |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
805 following["id"] == "https://test.example/_ap/following/some_user@test.example" |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
806 ) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
807 assert following["totalItems"] == len(subscriptions) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
808 assert following["type"] == "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
809 assert following.get("first") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
810 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
811 first_page = following["first"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
812 assert first_page["type"] == "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
813 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
|
814 items = first_page["orderedItems"] |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
815 assert items == ["local_user@test.example", "ext_user@example.org"] |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
816 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
817 @ed |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
818 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
|
819 """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
|
820 subscribers = [ |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
821 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
822 id="subscriber_1", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
823 payload=ap_gateway._pps.build_subscriber_elt( |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
824 jid.JID("local_user@test.example") |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
825 ), |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
826 ), |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
827 pubsub.Item( |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
828 id="subscriber_2", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
829 payload=ap_gateway._pps.build_subscriber_elt( |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
830 jid.JID("ext_user\\40example.org@ap.test.example") |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
831 ), |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
832 ), |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
833 ] |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
834 monkeypatch.setattr( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
835 ap_gateway._p, "get_items", partial(mock_get_items, ret_items=subscribers) |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
836 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
837 followers = await ap_gateway.server.resource.ap_followers_request( |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
838 **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
|
839 ) |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
840 assert followers["@context"] == ["https://www.w3.org/ns/activitystreams"] |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
841 assert ( |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
842 followers["id"] == "https://test.example/_ap/followers/some_user@test.example" |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
843 ) |
3770
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
844 assert followers["totalItems"] == len(subscribers) |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
845 assert followers["type"] == "OrderedCollection" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
846 assert followers.get("first") |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
847 |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
848 first_page = followers["first"] |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
849 assert first_page["type"] == "OrderedCollectionPage" |
f31113777881
tests (unit/ap-gateway): tests for following/followers <=> PPS:
Goffi <goffi@goffi.org>
parents:
3735
diff
changeset
|
850 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
|
851 items = first_page["orderedItems"] |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
852 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
|
853 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
854 @ed |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
855 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
|
856 """XMPP message are sent as AP direct message""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
857 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
858 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
859 monkeypatch.setattr(ap_gateway, "ap_get", 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
|
860 mess_data = { |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
861 "from": TEST_JID, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
862 "to": ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT), |
3808
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
863 "type": "chat", |
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
864 "message": {"": "This is a test message."}, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
865 "extra": {"origin-id": "123"}, |
3808
39fc2e1b3793
tests (unit/ap gateway): fix `onMessage` call following change in the component:
Goffi <goffi@goffi.org>
parents:
3785
diff
changeset
|
866 } |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
867 with patch.object(ap_gateway, "ap_post") as ap_post: |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
868 await ap_gateway.on_message(ap_gateway.client, mess_data) |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
869 url, actor_id, doc = ap_post.call_args[0] |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
870 assert url == "https://example.org/users/test_user/inbox" |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
871 assert actor_id == "https://test.example/_ap/actor/some_user@test.example" |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
872 obj = doc["object"] |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
873 assert doc["@context"] == ["https://www.w3.org/ns/activitystreams"] |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
874 assert doc["actor"] == "https://test.example/_ap/actor/some_user@test.example" |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
875 assert obj["type"] == "Note" |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
876 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
|
877 assert obj["attributedTo"] == ( |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
878 "https://test.example/_ap/actor/some_user@test.example" |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
879 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
880 # 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
|
881 # ("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
|
882 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
|
883 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
|
884 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
|
885 assert field not in doc |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
886 assert field not in obj |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
887 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
888 @ed |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
889 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
|
890 """AP direct message are sent as XMPP message (not Pubsub)""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
891 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
892 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
893 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
894 # 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
|
895 monkeypatch.setattr(defer, "DeferredList", AsyncMock()) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
896 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
897 xmpp_actor_id = ap_gateway.build_apurl(ap_const.TYPE_ACTOR, TEST_JID.userhost()) |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
898 direct_ap_message = { |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
899 "attributedTo": TEST_AP_ACTOR_ID, |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
900 "cc": [], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
901 "content": "<p>test direct message</p>", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
902 "contentMap": {"en": "<p>test direct message</p>"}, |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
903 "id": f"{TEST_AP_ACTOR_ID}/statuses/123", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
904 "published": "2022-05-20T08:14:39Z", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
905 "to": [xmpp_actor_id], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
906 "type": "Note", |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
907 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
908 client = ap_gateway.client.get_virtual_client( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
909 ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
910 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
911 with patch.object(client, "sendMessage") as sendMessage: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
912 await ap_gateway.new_ap_item( |
3785
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
913 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
|
914 ) |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
915 |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
916 # 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
|
917 # 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
|
918 assert sendMessage.called |
0b54be42d0aa
test (unit/AP gateway): AP direct message ↔ XMPP `<message>` conversion:
Goffi <goffi@goffi.org>
parents:
3783
diff
changeset
|
919 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
|
920 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
|
921 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
922 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
923 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
|
924 """Pubsub retract requests are converted to AP delete activity""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
925 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
926 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
927 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
928 retract_id = "retract_123" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
929 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
|
930 retract_elt["id"] = retract_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
931 items_event = pubsub.ItemsEvent( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
932 sender=TEST_JID, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
933 recipient=ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT), |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
934 nodeIdentifier=ap_gateway._m.namespace, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
935 items=[retract_elt], |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
936 headers={}, |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
937 ) |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
938 with patch.object(ap_gateway, "ap_post") as ap_post: |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
939 ap_post.return_value = FakeTReqPostResponse() |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
940 # we simulate the reception of a retract event |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
941 await ap_gateway._items_received(ap_gateway.client, items_event) |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
942 url, actor_id, doc = ap_post.call_args[0] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
943 jid_account = await ap_gateway.get_ap_account_from_jid_and_node(TEST_JID, None) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
944 jid_actor_id = ap_gateway.build_apurl(ap_const.TYPE_ACTOR, jid_account) |
3890
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
945 assert url == f"{TEST_BASE_URL}/inbox" |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
946 assert actor_id == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
947 assert doc["type"] == "Delete" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
948 assert doc["actor"] == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
949 obj = doc["object"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
950 assert obj["type"] == ap_const.TYPE_TOMBSTONE |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
951 url_item_id = ap_gateway.build_apurl(ap_const.TYPE_ITEM, jid_account, retract_id) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
952 assert obj["id"] == url_item_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
953 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
954 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
955 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
|
956 """AP delete activity is converted to pubsub retract""" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
957 client = ap_gateway.client.get_virtual_client( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
958 ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
959 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
960 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
961 ap_item = { |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
962 "@context": "https://www.w3.org/ns/activitystreams", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
963 "actor": TEST_AP_ACTOR_ID, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
964 "id": "https://test.example/retract_123", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
965 "type": "Delete", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
966 "object": {"id": f"{TEST_AP_ACTOR_ID}/item/123", "type": "Tombstone"}, |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
967 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
968 } |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
969 with patch.multiple( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
970 ap_gateway.host.memory.storage, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
971 get=DEFAULT, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
972 get_pubsub_node=DEFAULT, |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
973 delete_pubsub_items=DEFAULT, |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
974 ) as mock_objs: |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
975 mock_objs["get"].return_value = None |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
976 cached_node = MagicMock() |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
977 mock_objs["get_pubsub_node"].return_value = cached_node |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
978 subscription = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
979 subscription.state = SubscriptionState.SUBSCRIBED |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
980 subscription.subscriber = TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
981 cached_node.subscriptions = [subscription] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
982 with patch.object( |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
983 ap_gateway.pubsub_service, "notifyRetract" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
984 ) as notifyRetract: |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
985 # we simulate a received Delete activity |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
986 await ap_gateway.new_ap_delete_item( |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
987 client=client, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
988 destinee=None, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
989 node=ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
990 item=ap_item, |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
991 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
992 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
993 # item is deleted from database |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
994 delete_pubsub_items = mock_objs["delete_pubsub_items"] |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
995 assert delete_pubsub_items.call_count == 1 |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
996 assert delete_pubsub_items.call_args.args[1] == [ap_item["id"]] |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
997 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
998 # retraction notification is sent to subscribers |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
999 assert notifyRetract.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1000 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
|
1001 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
|
1002 notifications = notifyRetract.call_args.args[2] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1003 assert len(notifications) == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1004 subscriber, __, item_elts = notifications[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1005 assert subscriber == TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1006 assert len(item_elts) == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1007 item_elt = item_elts[0] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1008 assert isinstance(item_elt, domish.Element) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1009 assert item_elt.name == "item" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1010 assert item_elt["id"] == ap_item["id"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1011 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1012 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1013 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
|
1014 """Message retract requests are converted to AP delete activity""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1015 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1016 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1017 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1018 # 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
|
1019 origin_id = "mess_retract_123" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1020 |
4213 | 1021 # we call send_retract to get the message element of a retraction request |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1022 fake_client = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1023 fake_client.jid = TEST_JID |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1024 dest_jid = ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
4213 | 1025 fake_history = MagicMock() |
1026 fake_history.type = C.MESS_TYPE_CHAT | |
1027 ap_gateway._r.send_retract(fake_client, dest_jid, origin_id, fake_history) | |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1028 # 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
|
1029 message_retract_elt = fake_client.send.call_args.args[0] |
4213 | 1030 retract_elt = next(message_retract_elt.elements(NS_MESSAGE_RETRACT, "retract")) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1031 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1032 with patch.object(ap_gateway, "ap_post") as ap_post: |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1033 ap_post.return_value = FakeTReqPostResponse() |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1034 fake_fastened_elts = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1035 fake_fastened_elts.id = origin_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1036 # 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
|
1037 # we generated above |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1038 await ap_gateway._on_message_retract( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1039 ap_gateway.client, message_retract_elt, retract_elt, fake_fastened_elts |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1040 ) |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1041 url, actor_id, doc = ap_post.call_args[0] |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1042 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1043 # the AP delete activity must have been sent through ap_post |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1044 # we check its values |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1045 jid_account = await ap_gateway.get_ap_account_from_jid_and_node(TEST_JID, None) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1046 jid_actor_id = ap_gateway.build_apurl(ap_const.TYPE_ACTOR, jid_account) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1047 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
|
1048 assert actor_id == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1049 assert doc["type"] == "Delete" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1050 assert doc["actor"] == jid_actor_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1051 obj = doc["object"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1052 assert obj["type"] == ap_const.TYPE_TOMBSTONE |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1053 url_item_id = ap_gateway.build_apurl(ap_const.TYPE_ITEM, jid_account, origin_id) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1054 assert obj["id"] == url_item_id |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1055 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1056 @ed |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1057 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
|
1058 """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
|
1059 # 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
|
1060 # 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
|
1061 # by ``test_ap_delete_to_pubsub_retract``) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1062 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1063 # we don't want actual queries in database |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1064 retract_db_history = AsyncMock() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1065 monkeypatch.setattr(ap_gateway._r, "retract_db_history", retract_db_history) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1066 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1067 client = ap_gateway.client.get_virtual_client( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1068 ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1069 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1070 fake_send = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1071 monkeypatch.setattr(client, "send", fake_send) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1072 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1073 ap_item = { |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1074 "@context": "https://www.w3.org/ns/activitystreams", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1075 "actor": TEST_AP_ACTOR_ID, |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1076 "id": "https://test.example/retract_123", |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1077 "type": "Delete", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1078 "object": {"id": f"{TEST_AP_ACTOR_ID}/item/123", "type": "Tombstone"}, |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1079 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1080 } |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1081 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
|
1082 fake_history = MagicMock() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1083 fake_history.source_jid = client.jid |
4213 | 1084 fake_history.dest = str(TEST_JID) |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1085 fake_history.dest_jid = TEST_JID |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1086 fake_history.origin_id = ap_item["id"] |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1087 storage_get.return_value = fake_history |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1088 # we simulate a received Delete activity |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1089 await ap_gateway.new_ap_delete_item( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1090 client=client, destinee=None, node=ap_gateway._m.namespace, item=ap_item |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1091 ) |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1092 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1093 # item is deleted from database |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1094 assert retract_db_history.call_count == 1 |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1095 assert retract_db_history.call_args.args[0] == client |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1096 assert retract_db_history.call_args.args[1] == fake_history |
3809
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 # retraction notification is sent to destinee |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1099 assert fake_send.call_count == 1 |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1100 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
|
1101 assert sent_elt.name == "message" |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1102 assert sent_elt["from"] == client.jid.full() |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1103 assert sent_elt["to"] == TEST_JID.full() |
4213 | 1104 retract_elt = next(sent_elt.elements(NS_MESSAGE_RETRACT, "retract")) |
1105 assert retract_elt["id"] == ap_item["id"] | |
3809
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1106 assert retract_elt is not None |
04b57c0b2278
tests (unit/ap gateway): message/item retractation tests:
Goffi <goffi@goffi.org>
parents:
3808
diff
changeset
|
1107 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
|
1108 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1109 @ed |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1110 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
|
1111 """AP actor metadata are converted to XMPP/vCard4""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1112 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1113 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1114 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1115 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1116 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
|
1117 jid.JID("toto@example.org"), |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1118 ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT), |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1119 # VCard4 node |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1120 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
|
1121 None, |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1122 None, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1123 None, |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1124 ) |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1125 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
|
1126 vcard_elt = next(items[0].elements(ap_gateway._v.namespace, "vcard")) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1127 vcard = ap_gateway._v.vcard_2_dict(vcard_elt) |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1128 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
|
1129 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
|
1130 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1131 @ed |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1132 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
|
1133 """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
|
1134 # 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
|
1135 # XEPs/locations (vCard4, vcard-tmp, etc) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1136 with patch.object(ap_gateway._i, "get_identity") as get_identity: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1137 get_identity.return_value = { |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1138 "nicknames": ["nick1", "nick2"], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1139 "description": "test description", |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1140 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1141 actor_data = await ap_gateway.server.resource.ap_actor_request( |
3826
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1142 **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
|
1143 ) |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1144 |
81c79b7cafa7
tests (unit/ap-gateway): tests for XMPP identity/vCard4 <=> AP actor data conversion:
Goffi <goffi@goffi.org>
parents:
3809
diff
changeset
|
1145 # 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
|
1146 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
|
1147 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
|
1148 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1149 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1150 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
|
1151 """AP mentions by direct addressing are converted to XEP-0372 references""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1152 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1153 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1154 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1155 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1156 xmpp_actor_id = ap_gateway.build_apurl(ap_const.TYPE_ACTOR, TEST_JID.userhost()) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1157 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1158 direct_addr_mention = { |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1159 "attributedTo": TEST_AP_ACTOR_ID, |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1160 "cc": [], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1161 "content": "<p>test mention by direct addressing</p>", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1162 "id": f"{TEST_AP_ACTOR_ID}/statuses/direct_addr_123", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1163 "published": "2022-05-20T08:14:39Z", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1164 "to": [ap_const.NS_AP_PUBLIC, xmpp_actor_id], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1165 "type": "Note", |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1166 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1167 client = ap_gateway.client.get_virtual_client( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1168 ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1169 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1170 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
|
1171 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1172 with patch.object(ap_gateway._refs, "send_reference") as send_reference: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1173 await ap_gateway.new_ap_item( |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1174 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
|
1175 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1176 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1177 assert send_reference.call_count == 1 |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1178 assert send_reference.call_args.kwargs["to_jid"] == TEST_JID |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1179 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1180 local_actor_jid = ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1181 expected_anchor = xmpp_uri.build_xmpp_uri( |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1182 "pubsub", |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1183 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
|
1184 node=ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1185 item=direct_addr_mention["id"], |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1186 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1187 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1188 assert send_reference.call_args.kwargs["anchor"] == expected_anchor |
3837
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 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1191 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
|
1192 """AP mentions in "tag" field are converted to XEP-0372 references""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1193 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1194 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1195 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1196 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1197 xmpp_actor_id = ap_gateway.build_apurl(ap_const.TYPE_ACTOR, TEST_JID.userhost()) |
3837
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 direct_addr_mention = { |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1200 "attributedTo": TEST_AP_ACTOR_ID, |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1201 "cc": [], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1202 "content": "<p>test mention by tag</p>", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1203 "id": f"{TEST_AP_ACTOR_ID}/statuses/tag_123", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1204 "published": "2022-05-20T08:14:39Z", |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1205 "to": [ap_const.NS_AP_PUBLIC], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1206 "tag": [{"type": "Mention", "href": xmpp_actor_id, "name": f"@{TEST_JID}'"}], |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1207 "type": "Note", |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1208 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1209 client = ap_gateway.client.get_virtual_client( |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1210 ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3837
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 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
|
1213 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1214 with patch.object(ap_gateway._refs, "send_reference") as send_reference: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1215 await ap_gateway.new_ap_item( |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1216 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
|
1217 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1218 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1219 assert send_reference.call_count == 1 |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1220 assert send_reference.call_args.kwargs["to_jid"] == TEST_JID |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1221 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1222 local_actor_jid = ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1223 expected_anchor = xmpp_uri.build_xmpp_uri( |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1224 "pubsub", |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1225 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
|
1226 node=ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1227 item=direct_addr_mention["id"], |
3837
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 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1230 assert send_reference.call_args.kwargs["anchor"] == expected_anchor |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1231 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1232 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1233 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
|
1234 """Check that mentions in body are converted to AP mentions""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1235 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1236 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1237 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1238 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1239 mb_data = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1240 "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
|
1241 "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
|
1242 "service": TEST_JID.full(), |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1243 "node": ap_gateway._m.namespace, |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1244 } |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1245 ap_item = await ap_gateway.mb_data_2_ap_item( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1246 ap_gateway.client, mb_data, public=True |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1247 ) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1248 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1249 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
|
1250 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
|
1251 expected_mention = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1252 "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
|
1253 "href": TEST_AP_ACTOR_ID, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1254 "name": f"@{TEST_AP_ACCOUNT}", |
3837
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 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
|
1257 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1258 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1259 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
|
1260 """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
|
1261 # this is the same test as test_auto_mentions above, except that public is not set |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1262 # in mb_data_2_ap_item |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1263 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1264 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1265 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3837
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 mb_data = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1268 "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
|
1269 "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
|
1270 "service": TEST_JID.full(), |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1271 "node": ap_gateway._m.namespace, |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1272 } |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1273 ap_item = await ap_gateway.mb_data_2_ap_item( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1274 ap_gateway.client, mb_data, public=False |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1275 ) |
3837
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 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
|
1278 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
|
1279 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
|
1280 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1281 @ed |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1282 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
|
1283 """Check that XEP-0372 references are converted to AP mention""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1284 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1285 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1286 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1287 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1288 local_actor_jid = ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1289 item_elt = XMPP_ITEMS[0] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1290 anchor = xmpp_uri.build_xmpp_uri( |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1291 "pubsub", |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1292 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
|
1293 node=ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1294 item=item_elt["id"], |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1295 ) |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1296 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1297 ref_data: Dict[str, Union[str, int, dict]] = { |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1298 "uri": xmpp_uri.build_xmpp_uri(None, path=local_actor_jid.full()), |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1299 "type_": "mention", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1300 "anchor": anchor, |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1301 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1302 reference_elt = ap_gateway._refs.build_ref_element(**ref_data) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1303 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1304 # 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
|
1305 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1306 ref_data["parsed_uri"] = xmpp_uri.parse_xmpp_uri(ref_data["uri"]) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1307 ref_data["parsed_anchor"] = xmpp_uri.parse_xmpp_uri(ref_data["anchor"]) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1308 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1309 # "type" is a builtin function, thus "type_" is used in build_ref_element, but in |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1310 # 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
|
1311 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
|
1312 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
|
1313 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1314 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
|
1315 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
|
1316 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1317 with patch.object(ap_gateway.host.memory.storage, "get_items") as get_items: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1318 # get_items returns a sqla_mapping.PubsubItem, thus we need to fake it and set |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1319 # 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
|
1320 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
|
1321 mock_pubsub_item.data = item_elt |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1322 get_items.return_value = ([mock_pubsub_item], {}) |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1323 with patch.object(ap_gateway, "ap_post") as ap_post: |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1324 ap_post.return_value.code = 202 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1325 await ap_gateway._on_reference_received( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1326 ap_gateway.client, message_elt, ref_data |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1327 ) |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1328 |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1329 # 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
|
1330 # actor, and they must be in "to" field and in "tag" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1331 assert ap_post.call_count == 1 |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1332 send_ap_item = ap_post.call_args.args[-1] |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1333 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
|
1334 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
|
1335 expected_mention = { |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1336 "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
|
1337 "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
|
1338 # 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
|
1339 # item with XMPP |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1340 "name": f"{TEST_AP_ACCOUNT}", |
3837
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1341 } |
56720561f45f
test (unit/AP gateway): tests for XMPP reference/mention <=> AP mention conversion:
Goffi <goffi@goffi.org>
parents:
3826
diff
changeset
|
1342 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
|
1343 |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1344 @ed |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1345 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
|
1346 """XEP-0272 post repeat is converted to AP Announce activity""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1347 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1348 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1349 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1350 |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1351 # JID repeated AP actor (also the recipient of the message) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1352 recipient_jid = ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1353 # repeated item |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1354 ap_item = TEST_AP_ITEMS[0] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1355 ap_item_url = xmpp_uri.build_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
|
1356 "pubsub", |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1357 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
|
1358 node=ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1359 item=ap_item["id"], |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1360 ) |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1361 item_elt = xml_tools.parse( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1362 f""" |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1363 <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
|
1364 <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
|
1365 <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
|
1366 <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
|
1367 <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
|
1368 <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
|
1369 </div> |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1370 </title> |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1371 <author> |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1372 <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
|
1373 <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
|
1374 </author> |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1375 <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
|
1376 <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
|
1377 <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
|
1378 <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
|
1379 </entry> |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1380 </item> |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1381 """ |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1382 ) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1383 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
|
1384 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1385 with patch.object(ap_gateway, "ap_post") as ap_post: |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1386 ap_post.return_value.code = 202 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1387 await ap_gateway.convert_and_post_items( |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1388 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
|
1389 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
|
1390 TEST_JID, |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1391 ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1392 [item_elt], |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1393 ) |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1394 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1395 assert ap_post.called |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1396 url, actor_id, doc = ap_post.call_args.args |
3890
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
1397 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"] |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1398 assert actor_id == ap_gateway.build_apurl( |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1399 ap_const.TYPE_ACTOR, TEST_JID.userhost() |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1400 ) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1401 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
|
1402 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
|
1403 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
|
1404 |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1405 @ed |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1406 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
|
1407 """AP Announce activity is converted to XEP-0272 post repeat""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1408 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1409 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1410 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1411 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1412 xmpp_actor_id = ap_gateway.build_apurl(ap_const.TYPE_ACTOR, TEST_JID.userhost()) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1413 # announced item |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1414 xmpp_item = XMPP_ITEMS[0] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1415 xmpp_item_url = ap_gateway.build_apurl( |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1416 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
|
1417 ) |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1418 announce = { |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1419 "@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
|
1420 "type": "Announce", |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1421 "actor": TEST_AP_ACTOR_ID, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1422 "cc": [xmpp_actor_id, TEST_USER_DATA["followers"]], |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1423 "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
|
1424 "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
|
1425 "published": "2022-07-22T09:24:12Z", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1426 "to": [ap_const.NS_AP_PUBLIC], |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1427 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1428 with patch.object(ap_gateway.host.memory.storage, "get_items") as get_items: |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1429 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
|
1430 mock_pubsub_item.data = xmpp_item |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1431 get_items.return_value = ([mock_pubsub_item], {}) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1432 with patch.object( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1433 ap_gateway.host.memory.storage, "cache_pubsub_items" |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1434 ) as cache_pubsub_items: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1435 await ap_gateway.server.resource.handle_announce_activity( |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1436 TEST_AP_ACTOR_ID, |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1437 Request(MagicMock()), |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1438 announce, |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1439 None, |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1440 None, |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1441 None, |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1442 "", |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1443 TEST_AP_ACTOR_ID, |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1444 ) |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1445 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1446 assert cache_pubsub_items.called |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1447 # the microblog data put in cache correspond to the item sent to subscribers |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1448 __, __, __, [mb_data] = cache_pubsub_items.call_args.args |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1449 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
|
1450 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
|
1451 repeated = extra["repeated"] |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1452 assert ( |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1453 repeated["by"] |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1454 == ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT).full() |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1455 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1456 xmpp_item_xmpp_url = xmpp_uri.build_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
|
1457 "pubsub", |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1458 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
|
1459 node=ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1460 item=xmpp_item["id"], |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1461 ) |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1462 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
|
1463 |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1464 @ed |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1465 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
|
1466 """Pubsub-attachments ``noticed`` is converted to AP Like activity""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1467 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1468 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1469 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1470 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1471 recipient_jid = ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1472 # noticed item |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1473 ap_item = TEST_AP_ITEMS[0] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1474 attachment_node = ap_gateway._pa.get_attachment_node_name( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1475 recipient_jid, ap_gateway._m.namespace, ap_item["id"] |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1476 ) |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1477 item_elt = xml_tools.parse( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1478 f""" |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1479 <item id="{TEST_JID.userhost()}" published="{TEST_JID.userhostJID()}"> |
3890
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
1480 <attachments xmlns="urn:xmpp:pubsub-attachments:1"> |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1481 <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
|
1482 </attachments> |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1483 </item> |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1484 """ |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1485 ) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1486 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
|
1487 items_event = pubsub.ItemsEvent( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1488 TEST_JID, recipient_jid, attachment_node, [item_elt], {} |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1489 ) |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1490 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1491 with patch.object(ap_gateway, "ap_post") as ap_post: |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1492 ap_post.return_value.code = 202 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1493 await ap_gateway._items_received(ap_gateway.client, items_event) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1494 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1495 assert ap_post.called |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1496 url, actor_id, doc = ap_post.call_args.args |
3890
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
1497 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"] |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1498 assert actor_id == ap_gateway.build_apurl( |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1499 ap_const.TYPE_ACTOR, TEST_JID.userhost() |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1500 ) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1501 assert doc["type"] == "Like" |
3890
c129234a5d0b
tests (AP gateway): fix tests following changes in gateway:
Goffi <goffi@goffi.org>
parents:
3871
diff
changeset
|
1502 assert ap_const.NS_AP_PUBLIC in doc["cc"] |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1503 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
|
1504 |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1505 @ed |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1506 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
|
1507 """AP Like activity is converted to ``noticed`` attachment""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1508 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1509 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1510 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1511 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1512 xmpp_actor_id = ap_gateway.build_apurl(ap_const.TYPE_ACTOR, TEST_JID.userhost()) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1513 # liked item |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1514 xmpp_item = XMPP_ITEMS[0] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1515 xmpp_item_url = ap_gateway.build_apurl( |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1516 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
|
1517 ) |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1518 like = { |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1519 "@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
|
1520 "type": "Like", |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1521 "actor": TEST_AP_ACTOR_ID, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1522 "cc": [xmpp_actor_id, TEST_USER_DATA["followers"]], |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1523 "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
|
1524 "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
|
1525 "published": "2022-07-22T09:24:12Z", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1526 "to": [ap_const.NS_AP_PUBLIC], |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1527 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1528 with patch.object(ap_gateway.host.memory.storage, "get_items") as get_items: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1529 get_items.return_value = ([], {}) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1530 with patch.object(ap_gateway._p, "send_items") as send_items: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1531 await ap_gateway.server.resource.ap_inbox_request( |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1532 **self.ap_request_params( |
3981
acc9dfc8ba8d
component AP gateway: parse body immediately on `POST` request:
Goffi <goffi@goffi.org>
parents:
3908
diff
changeset
|
1533 ap_gateway, "inbox", data=like, signing_actor=TEST_AP_ACTOR_ID |
3871
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 ) |
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1536 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1537 assert send_items.called |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1538 si_client, si_service, si_node, [si_item] = send_items.call_args.args |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1539 assert si_client.jid == ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1540 assert si_service == TEST_JID |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1541 assert si_node == ap_gateway._pa.get_attachment_node_name( |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1542 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
|
1543 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1544 [parsed_item] = ap_gateway._pa.items_2_attachment_data(si_client, [si_item]) |
3871
8c01d8ab9447
tests (unit/AP gateway): tests for item repeat/announce and noticed/like conversion:
Goffi <goffi@goffi.org>
parents:
3837
diff
changeset
|
1545 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
|
1546 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
|
1547 assert parsed_item["noticed"]["noticed"] == True |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1548 |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1549 @ed |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1550 async def test_xmpp_pubsub_reactions_to_ap(self, ap_gateway, monkeypatch): |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1551 """Pubsub-attachments ``reactions`` is converted to AP EmojiReact activity""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1552 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1553 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1554 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1555 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1556 recipient_jid = ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1557 # noticed item |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1558 ap_item = TEST_AP_ITEMS[0] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1559 ap_item_url = xmpp_uri.build_xmpp_uri( |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1560 "pubsub", |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1561 path=recipient_jid.full(), |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1562 node=ap_gateway._m.namespace, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1563 item=ap_item["id"], |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1564 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1565 attachment_node = ap_gateway._pa.get_attachment_node_name( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1566 recipient_jid, ap_gateway._m.namespace, ap_item["id"] |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1567 ) |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1568 reactions = ["🦁", "🥜", "🎻"] |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1569 item_elt = xml_tools.parse( |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1570 f""" |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1571 <item id="{TEST_JID.userhost()}" published="{TEST_JID.userhostJID()}"> |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1572 <attachments xmlns="urn:xmpp:pubsub-attachments:1"> |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1573 <reactions timestamp="2022-08-31T12:17:23Z"> |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1574 <reaction>{reactions[0]}</reaction> |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1575 <reaction>{reactions[1]}</reaction> |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1576 <reaction>{reactions[2]}</reaction> |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1577 </reactions> |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1578 </attachments> |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1579 </item> |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1580 """ |
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1581 ) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1582 item_elt.uri = pubsub.NS_PUBSUB_EVENT |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1583 items_event = pubsub.ItemsEvent( |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1584 TEST_JID, recipient_jid, attachment_node, [item_elt], {} |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1585 ) |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1586 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1587 with patch.object(ap_gateway, "ap_post") as ap_post: |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1588 ap_post.return_value.code = 202 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1589 await ap_gateway._items_received(ap_gateway.client, items_event) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1590 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1591 assert ap_post.call_count == 3 |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1592 for idx, call_args in enumerate(ap_post.call_args_list): |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1593 url, actor_id, doc = call_args.args |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1594 assert url == TEST_USER_DATA["endpoints"]["sharedInbox"] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1595 assert actor_id == ap_gateway.build_apurl( |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1596 ap_const.TYPE_ACTOR, TEST_JID.userhost() |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1597 ) |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1598 assert doc["type"] == "EmojiReact" |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1599 assert ap_const.NS_AP_PUBLIC in doc["cc"] |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1600 assert doc["object"] == ap_item["id"] |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1601 # reactions can be sent in random order (due to the use of set), thus we check |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1602 # if each reaction appear once, and that nothing is left after all calls are |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1603 # checked. |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1604 assert doc["content"] in reactions |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1605 reactions.remove(doc["content"]) |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1606 assert len(reactions) == 0 |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1607 |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1608 @ed |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1609 async def test_ap_reactions_to_xmpp(self, ap_gateway, monkeypatch): |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1610 """AP EmojiReact activity is converted to ``reactions`` attachment""" |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1611 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "get", mock_treq_get) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1612 monkeypatch.setattr(plugin_comp_ap_gateway.treq, "json_content", mock_treq_json) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1613 monkeypatch.setattr(ap_gateway, "ap_get", mock_ap_get) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1614 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1615 xmpp_actor_id = ap_gateway.build_apurl(ap_const.TYPE_ACTOR, TEST_JID.userhost()) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1616 # item on which reaction is attached |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1617 xmpp_item = XMPP_ITEMS[0] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1618 xmpp_item_url = ap_gateway.build_apurl( |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1619 ap_const.TYPE_ITEM, TEST_JID.userhost(), xmpp_item["id"] |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1620 ) |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1621 like = { |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1622 "@context": "https://www.w3.org/ns/activitystreams", |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1623 "type": "EmojiReact", |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1624 "actor": TEST_AP_ACTOR_ID, |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1625 "cc": [xmpp_actor_id, TEST_USER_DATA["followers"]], |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1626 "id": "https://example.org/like/123", |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1627 "object": xmpp_item_url, |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1628 "content": "🐅", |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1629 "published": "2022-07-22T09:24:12Z", |
3907
755920bd30da
tests (unit/AP gateway): fix tests:
Goffi <goffi@goffi.org>
parents:
3891
diff
changeset
|
1630 "to": [ap_const.NS_AP_PUBLIC], |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1631 } |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1632 with patch.object(ap_gateway.host.memory.storage, "get_items") as get_items: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1633 get_items.return_value = ([], {}) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1634 with patch.object(ap_gateway._p, "send_items") as send_items: |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1635 await ap_gateway.server.resource.ap_inbox_request( |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1636 **self.ap_request_params( |
3981
acc9dfc8ba8d
component AP gateway: parse body immediately on `POST` request:
Goffi <goffi@goffi.org>
parents:
3908
diff
changeset
|
1637 ap_gateway, "inbox", data=like, signing_actor=TEST_AP_ACTOR_ID |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1638 ) |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1639 ) |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1640 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1641 assert send_items.called |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1642 si_client, si_service, si_node, [si_item] = send_items.call_args.args |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1643 assert si_client.jid == ap_gateway.get_local_jid_from_account(TEST_AP_ACCOUNT) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1644 assert si_service == TEST_JID |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1645 assert si_node == ap_gateway._pa.get_attachment_node_name( |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1646 TEST_JID, ap_gateway._m.namespace, xmpp_item["id"] |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1647 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3994
diff
changeset
|
1648 [parsed_item] = ap_gateway._pa.items_2_attachment_data(si_client, [si_item]) |
3891
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1649 assert parsed_item["from"] == si_client.jid.full() |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1650 assert "reactions" in parsed_item |
989df1047c3c
tests (AP gateway): reactions tests:
Goffi <goffi@goffi.org>
parents:
3890
diff
changeset
|
1651 assert parsed_item["reactions"]["reactions"] == ["🐅"] |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1652 |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1653 @ed |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1654 async def test_xmpp_event_2_ap_event(self, ap_gateway): |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1655 """XMPP events are converted to AP events""" |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1656 # we use internal event data |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1657 event_data = { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1658 "id": "event_123", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1659 "name": {"": "test event"}, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1660 "start": 1664222400.0, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1661 "end": 1664226000.0, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1662 "head-picture": { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1663 "sources": [{"url": "https://example.org/head_picture.jpg"}] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1664 }, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1665 "descriptions": [{"description": "meeting for test", "type": "text"}], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1666 "categories": [{"term": "test", "wikidata_id": "Q1003030"}], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1667 "locations": [{"description": "somewhere in the world"}], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1668 "rsvp": [ |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1669 { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1670 "fields": [ |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1671 { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1672 "type": "list-single", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1673 "name": "attending", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1674 "label": "Attending", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1675 "options": [ |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1676 {"value": "maybe", "label": "maybe"}, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1677 {"value": "yes", "label": "yes"}, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1678 {"value": "no", "label": "no"}, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1679 ], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1680 } |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1681 ], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1682 "namespace": "urn:xmpp:events:rsvp:0", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1683 } |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1684 ], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1685 "extra": { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1686 "status": "confirmed", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1687 }, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1688 } |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1689 |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1690 ap_item = await ap_gateway.ap_events.event_data_2_ap_item(event_data, TEST_JID) |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1691 ap_object = ap_item["object"] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1692 actor_id = ( |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1693 "https://test.example/_ap/actor/" |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
1694 "___urn.3Axmpp.3Aevents.3A0---some_user@test.example" |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1695 ) |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1696 event_id = ( |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1697 "https://test.example/_ap/item/" |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
1698 "___urn.3Axmpp.3Aevents.3A0---some_user@test.example/event_123" |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1699 ) |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1700 assert ap_object["name"] == "test event" |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1701 assert ap_object["actor"] == actor_id |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1702 assert ap_object["attributedTo"] == actor_id |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1703 assert ap_object["type"] == "Event" |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1704 assert ap_object["startTime"] == "2022-09-26T20:00:00Z" |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1705 assert ap_object["endTime"] == "2022-09-26T21:00:00Z" |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1706 assert ap_object["id"] == event_id |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1707 assert ap_object["url"] == event_id |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1708 assert ap_object["attachment"] == [ |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1709 { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1710 "name": "Banner", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1711 "type": "Document", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1712 "mediaType": "image/jpeg", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1713 "url": "https://example.org/head_picture.jpg", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1714 } |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1715 ] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1716 assert ap_object["content"] == "<p>meeting for test</p>" |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1717 assert ap_object["tag"] == [{"name": "#test", "type": "Hashtag"}] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1718 assert ap_object["location"] == {"name": "somewhere in the world"} |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1719 assert ap_object["ical:status"] == "CONFIRMED" |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1720 assert ap_item["type"] == "Create" |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1721 |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1722 @ed |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1723 async def test_ap_event_2_xmpp_event(self, ap_gateway): |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1724 """AP events are converted to XMPP events""" |
3994
69d970f974ff
component AP gateway: don't percent-encode `@`:
Goffi <goffi@goffi.org>
parents:
3981
diff
changeset
|
1725 test_actor = "___urn.3Axmpp.3Aevents.3A0---some_user@test.example" |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1726 ap_object = { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1727 "actor": f"https://test.example/_ap/actor/{test_actor}", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1728 "attachment": [ |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1729 { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1730 "mediaType": "image/jpeg", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1731 "name": "Banner", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1732 "type": "Document", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1733 "url": "https://example.org/head_picture.jpg", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1734 } |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1735 ], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1736 "attributedTo": f"https://test.example/_ap/actor/{test_actor}", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1737 "content": "<p>meeting for test</p>", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1738 "endTime": "2022-09-26T21:00:00Z", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1739 "ical:status": "CONFIRMED", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1740 "id": f"https://test.example/_ap/item/{test_actor}/event_123", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1741 "location": {"name": "somewhere in the world"}, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1742 "name": "test event", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1743 "startTime": "2022-09-26T20:00:00Z", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1744 "tag": [{"name": "#test", "type": "Hashtag"}], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1745 "to": ["https://www.w3.org/ns/activitystreams#Public"], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1746 "type": "Event", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1747 "url": f"https://test.example/_ap/item/{test_actor}/event_123", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1748 } |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1749 |
4259
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1750 event_data = await ap_gateway.ap_events.ap_item_2_event_data( |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1751 TEST_AP_ACTOR_ID, ap_object |
49019947cc76
component AP Gateway: implement HTTP GET signature.
Goffi <goffi@goffi.org>
parents:
4213
diff
changeset
|
1752 ) |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1753 |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1754 assert event_data["id"] == ap_object["id"] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1755 assert event_data["name"] == {"": "test event"} |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1756 assert event_data["start"] == 1664222400 |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1757 assert event_data["end"] == 1664226000 |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1758 assert event_data["head-picture"] == { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1759 "sources": [{"url": "https://example.org/head_picture.jpg"}] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1760 } |
4285
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1761 assert event_data["descriptions"] == [ |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1762 {"description": "<p>meeting for test</p>", "type": "xhtml"} |
f1d0cde61af7
tests (unit): fix tests + black reformatting.
Goffi <goffi@goffi.org>
parents:
4259
diff
changeset
|
1763 ] |
3908
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1764 assert event_data["categories"] == [{"term": "test"}] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1765 assert event_data["locations"] == [{"description": "somewhere in the world"}] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1766 assert event_data["rsvp"] == [ |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1767 { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1768 "fields": [ |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1769 { |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1770 "label": "Attending", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1771 "name": "attending", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1772 "options": [ |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1773 {"label": "yes", "value": "yes"}, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1774 {"label": "no", "value": "no"}, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1775 ], |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1776 "required": True, |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1777 "type": "list-single", |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1778 } |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1779 ] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1780 } |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1781 ] |
d43b197735d1
tests (unit/AP gateway): add tests for events:
Goffi <goffi@goffi.org>
parents:
3907
diff
changeset
|
1782 assert event_data["extra"] == {"status": "confirmed"} |