annotate tests/unit/test_ap-gateway.py @ 3802:983df907d456

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