annotate tests/unit/test_ap-gateway.py @ 3770:f31113777881

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