annotate tests/unit/test_ap-gateway.py @ 3743:54c249ec35ce

core (memory/migration): ignore FTS table when autogenerating script for migration: SQLite Full-Text Search stable are not associated to Python object and can't be detected by Alembic. To avoid the generation of unwanted drop commands, they are now ignored when autogenerating migration scripts. rel 364
author Goffi <goffi@goffi.org>
date Tue, 22 Mar 2022 17:00:42 +0100
parents 04ecc8eeb81a
children f31113777881
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
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 from unittest.mock import MagicMock, patch
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 from urllib import parse
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
22
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
23 import pytest
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from pytest_twisted import ensureDeferred as ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from twisted.words.protocols.jabber import jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from twisted.web.server import Request
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from wokkel import rsm, pubsub
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
28
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from sat.core import exceptions
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from sat.plugins import plugin_comp_ap_gateway
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 from sat.plugins.plugin_comp_ap_gateway.http_server import HTTPServer
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from sat.tools.utils import xmpp_date
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from sat.tools import xml_tools
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
35
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
36 TEST_BASE_URL = "https://example.org"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
37 TEST_USER = "test_user"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 TEST_AP_ACCOUNT = f"{TEST_USER}@example.org"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
40 AP_REQUESTS = {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
41 f"{TEST_BASE_URL}/.well-known/webfinger?"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
42 f"resource=acct:{parse.quote(TEST_AP_ACCOUNT)}": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
43 "aliases": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
44 f"{TEST_BASE_URL}/@{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
45 f"{TEST_BASE_URL}/users/{TEST_USER}"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
46 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 "links": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
48 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 "href": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 "rel": "self",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 "type": "application/activity+json"
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 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
54 "subject": f"acct:{TEST_AP_ACCOUNT}"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 },
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 f"{TEST_BASE_URL}/users/{TEST_USER}": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
58 "@context": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
59 "https://www.w3.org/ns/activitystreams",
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 "endpoints": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
62 "sharedInbox": f"{TEST_BASE_URL}/inbox"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
64 "followers": f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
65 "following": f"{TEST_BASE_URL}/users/{TEST_USER}/following",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 "id": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 "inbox": f"{TEST_BASE_URL}/users/{TEST_USER}/inbox",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 "name": "",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 "outbox": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
70 "preferredUsername": f"{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 "type": "Person",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
72 "url": f"{TEST_BASE_URL}/@{TEST_USER}"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
73 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
74
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 "@context": "https://www.w3.org/ns/activitystreams",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
77 "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
78 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 "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
80 "totalItems": 4,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
81 "type": "OrderedCollection"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
82 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
83 f"{TEST_BASE_URL}/users/{TEST_USER}/outbox?page=true": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 "@context": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 "https://www.w3.org/ns/activitystreams",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
86 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 "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
88 "orderedItems": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
89 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
90 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
91 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 "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
95 "object": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
99 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 "content": "<p>test message 1</p>",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 "contentMap": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 "en": "<p>test message 1</p>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
103 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/1",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
105 "inReplyTo": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 "published": "2021-12-16T17:28:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
107 "sensitive": False,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
108 "summary": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 "tag": [],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
110 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
112 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 "type": "Note",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
114 "url": f"{TEST_BASE_URL}/@{TEST_USER}/1"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
115 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 "published": "2021-12-16T17:28:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
117 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
118 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 "type": "Create"
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 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
123 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
125 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 "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
128 "object": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
130 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
131 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
132 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 "content": "<p>test message 2</p>",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
134 "contentMap": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 "en": "<p>test message 2</p>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
136 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/2",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 "inReplyTo": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 "published": "2021-12-16T17:27:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
140 "sensitive": False,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 "summary": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 "tag": [],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
144 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
145 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
146 "type": "Note",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
147 "url": f"{TEST_BASE_URL}/@{TEST_USER}/2"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
148 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
149 "published": "2021-12-16T17:27:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
150 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
151 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
152 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
153 "type": "Create"
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 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
156 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
157 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
158 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
159 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
160 "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
161 "object": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
162 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
163 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
164 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
165 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
166 "content": "<p>test message 3</p>",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
167 "contentMap": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
168 "en": "<p>test message 3</p>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
169 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
170 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/3",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
171 "inReplyTo": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
172 "published": "2021-12-16T17:26:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
173 "sensitive": False,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
174 "summary": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
175 "tag": [],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
176 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
177 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
178 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
179 "type": "Note",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
180 "url": f"{TEST_BASE_URL}/@{TEST_USER}/3"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
181 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
182 "published": "2021-12-16T17:26:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
183 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
184 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
185 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
186 "type": "Create"
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 {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
189 "actor": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
190 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
191 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
192 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
193 "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
194 "object": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
195 "attributedTo": f"{TEST_BASE_URL}/users/{TEST_USER}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
196 "cc": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
197 f"{TEST_BASE_URL}/users/{TEST_USER}/followers",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
198 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
199 "content": "<p>test message 4</p>",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
200 "contentMap": {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
201 "en": "<p>test message 4</p>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
202 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
203 "id": f"{TEST_BASE_URL}/users/{TEST_USER}/statuses/4",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
204 "inReplyTo": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 "published": "2021-12-16T17:25:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
206 "sensitive": False,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
207 "summary": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
208 "tag": [],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
209 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 "type": "Note",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 "url": f"{TEST_BASE_URL}/@{TEST_USER}/4"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 },
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 "published": "2021-12-16T17:25:03Z",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 "to": [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 "https://www.w3.org/ns/activitystreams#Public"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 "type": "Create"
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 ],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 "partOf": f"{TEST_BASE_URL}/users/{TEST_USER}/outbox",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 "prev": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 "type": "OrderedCollectionPage"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 }
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
226
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
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 XMPP_ITEM_TPL = """
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 <item id='{id}' publisher='{publisher_jid}'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
231 <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
232 <title type='xhtml'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 <div xmlns='http://www.w3.org/1999/xhtml'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 <p>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
235 XMPP item {id}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 </p>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 </div>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
238 </title>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 <title type='text'>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 XMPP item {id}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 </title>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 <author>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 <name>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 test_user
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 </name>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
246 <uri>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 xmpp:{publisher_jid}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 </uri>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
249 </author>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 <updated>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 {updated}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 </updated>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 <published>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 {published}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 </published>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 <id>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
257 xmpp:{publisher_jid}?;node=urn%3Axmpp%3Amicroblog%3A0;item={id}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
258 </id>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
259 </entry>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
260 </item>
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 """
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
262
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 ITEM_BASE_TS = 1643385499
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
264 XMPP_ITEMS = [
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
265 xml_tools.parse(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 "".join(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 l.strip() for l in XMPP_ITEM_TPL.format(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
268 id=i,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 publisher_jid="some_user@test.example",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 updated=xmpp_date(ITEM_BASE_TS + i * 60),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 published=xmpp_date(ITEM_BASE_TS + i * 60),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
272 ).split("\n")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 ),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
274 namespace=pubsub.NS_PUBSUB
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 for i in range(1, 5)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 ]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
278
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 async def mock_ap_get(url):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 return deepcopy(AP_REQUESTS[url])
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
281
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
282
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 async def mock_treq_json(data):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 return dict(data)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
285
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
286
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 async def mock_getItems(*args, **kwargs):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 rsm_resp = rsm.RSMResponse(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
289 first=XMPP_ITEMS[0]["id"],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 last=XMPP_ITEMS[-1]["id"],
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
291 index=0,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
292 count=len(XMPP_ITEMS)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
293 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
294 return XMPP_ITEMS, {"rsm": rsm_resp.toDict(), "complete": True}
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
295
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
296
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
297 @pytest.fixture(scope="session")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
298 def ap_gateway(host):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
299 gateway = plugin_comp_ap_gateway.APGateway(host)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
300 gateway.initialised = True
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
301 client = MagicMock()
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
302 client.jid = jid.JID("ap.test.example")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
303 client.host = "test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
304 gateway.client = client
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
305 gateway.local_only = True
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
306 gateway.public_url = "test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
307 gateway.ap_path = '_ap'
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
308 gateway.base_ap_url = parse.urljoin(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
309 f"https://{gateway.public_url}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
310 f"{gateway.ap_path}/"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
311 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
312 gateway.server = HTTPServer(gateway)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
313 return gateway
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
314
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
315
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
316 class TestActivityPubGateway:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
317
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
318 @ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
319 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
320 """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
321 get_account = ap_gateway.getAPAccountFromJidAndNode
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
322
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
323 # local jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
324 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
325 jid_ = jid.JID("simple@test.example"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
326 node = None
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
327 ) == "simple@test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
328
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
329 # non local jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
330 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
331 jid_ = jid.JID("simple@example.org"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
332 node = None
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
333 ) == "___simple.40example.2eorg@ap.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
334
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
335 # local jid with non microblog node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
336 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
337 jid_ = jid.JID("simple@test.example"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
338 node = "some_other_node"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
339 ) == "some_other_node---simple@test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
340
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
341 # local pubsub node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
342 with patch.object(ap_gateway, "isPubsub") as isPubsub:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
343 isPubsub.return_value = True
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
344 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
345 jid_ = jid.JID("pubsub.test.example"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
346 node = "some_node"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
347 ) == "some_node@pubsub.test.example"
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 # non local pubsub node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
350 with patch.object(ap_gateway, "isPubsub") as isPubsub:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
351 isPubsub.return_value = True
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
352 assert await get_account(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
353 jid_ = jid.JID("pubsub.example.org"),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
354 node = "some_node"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
355 ) == "___some_node.40pubsub.2eexample.2eorg@ap.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
356
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
357 @ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
358 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
359 """AP actor handle convert correctly to JID and pubsub node"""
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
360 get_jid_node = ap_gateway.getJIDAndNode
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
361
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
362 # for following assertion, host is not a pubsub service
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
363 with patch.object(ap_gateway, "isPubsub") as isPubsub:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
364 isPubsub.return_value = False
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
365
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
366 # simple local jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
367 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
368 "toto@test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
369 ) == (jid.JID("toto@test.example"), None)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
370
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
371 # simple external jid
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
372
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
373 ## with "local_only" set, it should raise an exception
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
374 with pytest.raises(exceptions.PermissionError):
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
375 await get_jid_node("toto@example.org")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
376
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
377 ## with "local_only" unset, it should work
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
378 with monkeypatch.context() as m:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
379 m.setattr(ap_gateway, "local_only", False, raising=True)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
380 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
381 "toto@example.org"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
382 ) == (jid.JID("toto@example.org"), None)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
383
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
384 # explicit node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
385 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
386 "tata---toto@test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
387 ) == (jid.JID("toto@test.example"), "tata")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
388
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
389 # for following assertion, host is a pubsub service
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
390 with patch.object(ap_gateway, "isPubsub") as isPubsub:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
391 isPubsub.return_value = True
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 # simple local node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
394 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
395 "toto@pubsub.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
396 ) == (jid.JID("pubsub.test.example"), "toto")
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 # encoded local node
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
399 assert await get_jid_node(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
400 "___urn.3axmpp.3amicroblog.3a0@pubsub.test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
401 ) == (jid.JID("pubsub.test.example"), "urn:xmpp:microblog:0")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
402
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
403 @ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
404 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
405 """AP requests are converted to pubsub"""
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
406 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
407 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
408 monkeypatch.setattr(ap_gateway, "apGet", mock_ap_get)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
409
3735
04ecc8eeb81a tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents: 3733
diff changeset
410 actor_data = await ap_gateway.getAPActorDataFromId(TEST_AP_ACCOUNT)
04ecc8eeb81a tests (ap-gateway): fix use of outbox URL to get items
Goffi <goffi@goffi.org>
parents: 3733
diff changeset
411 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
412 items, rsm_resp = await ap_gateway.getAPItems(outbox, 2)
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
413
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
414 assert rsm_resp.count == 4
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
415 assert rsm_resp.index == 0
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
416 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
417 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
418
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
419 assert items[0].entry.title.toXml() == (
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
420 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
421 "<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
422 "</title>"
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 author_uri = str(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
425 [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
426 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
427 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
428 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
429
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
430 assert items[1].entry.title.toXml() == (
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
431 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
432 "<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
433 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
434 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
435 author_uri = str(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
436 [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
437 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
438 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
439 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
440
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
441 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
442 outbox,
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
443 max_items=2,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
444 after_id="https://example.org/users/test_user/statuses/3",
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
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
447 assert rsm_resp.count == 4
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
448 assert rsm_resp.index == 2
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
449 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
450 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
451
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
452 assert items[0].entry.title.toXml() == (
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
453 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
454 "<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
455 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
456 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
457 author_uri = str(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
458 [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
459 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
460 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
461 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
462
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
463 assert items[1].entry.title.toXml() == (
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
464 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
465 "<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
466 "</title>"
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 author_uri = str(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
469 [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
470 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
471 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
472 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
473
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
474 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
475 outbox,
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
476 max_items=1,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
477 start_index=2
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
478 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
479
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
480 assert rsm_resp.count == 4
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
481 assert rsm_resp.index == 2
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
482 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
483 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
484 assert len(items) == 1
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
485
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
486 assert items[0].entry.title.toXml() == (
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
487 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
488 "<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
489 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
490 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
491 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
492
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
493 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
494 outbox,
3733
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
495 max_items=3,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
496 chronological_pagination=False
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
497 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
498 assert rsm_resp.count == 4
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
499 assert rsm_resp.index == 1
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
500 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
501 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
502 assert len(items) == 3
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
503 assert items[0].entry.title.toXml() == (
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
504 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
505 "<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
506 "</title>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
507 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
508 assert items[2].entry.title.toXml() == (
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
509 "<title xmlns='http://www.w3.org/2005/Atom' type='xhtml'>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
510 "<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
511 "</title>"
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
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
514 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
515 """Generate parameters for HTTPAPGServer's AP*Request
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
516
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
517 @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
518 @param url: URL to query (mutually exclusif with type_)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
519 @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
520 @return dict with kw params to use
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 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
523 if type_ is not None:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
524 path = f"_ap/{type_}/some_user%40test.example"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
525 else:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
526 url_parsed = parse.urlparse(url)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
527 path = url_parsed.path.lstrip("/")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
528 type_ = path.split("/")[1]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
529 if query_data is None:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
530 query_data = parse.parse_qs(url_parsed.query)
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 if query_data:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
533 uri = f"{path}?{parse.urlencode(query_data, doseq=True)}"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
534 else:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
535 uri = path
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
536
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
537 test_jid = jid.JID("some_user@test.example")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
538 request = Request(MagicMock())
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
539 request.path = path.encode()
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
540 request.uri = uri.encode()
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
541 ap_url = parse.urljoin(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
542 f"https://{ap_gateway.public_url}",
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
543 path
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
544 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
545 kwargs = {
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
546 "request": request,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
547 "account_jid": test_jid,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
548 "node": None,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
549 "ap_account": test_jid.full(),
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
550 "ap_url": ap_url,
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
551 }
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
552 if type_ == "outbox" and query_data:
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
553 kwargs["query_data"] = query_data
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
554 return kwargs
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
555
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
556 @ed
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
557 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
558 """Pubsub nodes are converted to AP collections"""
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
559 monkeypatch.setattr(ap_gateway._p, "getItems", mock_getItems)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
560 outbox = await ap_gateway.server.resource.APOutboxRequest(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
561 **self.ap_request_params(ap_gateway, "outbox")
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
562 )
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
563 assert outbox["@context"] == "https://www.w3.org/ns/activitystreams"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
564 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
565 assert outbox["totalItems"] == len(XMPP_ITEMS)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
566 assert outbox["type"] == "OrderedCollection"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
567 assert outbox["first"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
568 assert outbox["last"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
569
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
570 first_page = await ap_gateway.server.resource.APOutboxPageRequest(
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
571 **self.ap_request_params(ap_gateway, url=outbox["first"])
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 first_page["@context"] == "https://www.w3.org/ns/activitystreams"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
574 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
575 assert first_page["type"] == "OrderedCollectionPage"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
576 assert first_page["partOf"] == outbox["id"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
577 assert len(first_page["orderedItems"]) == len(XMPP_ITEMS)
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
578 first_item = first_page["orderedItems"][0]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
579 assert first_item["@context"] == "https://www.w3.org/ns/activitystreams"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
580 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
581 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
582 assert first_item["type"] == "Create"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
583 first_item_obj = first_item["object"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
584 assert first_item_obj["id"] == first_item["id"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
585 assert first_item_obj["type"] == "Note"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
586 assert first_item_obj["published"] == "2022-01-28T16:02:19Z"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
587 assert first_item_obj["attributedTo"] == first_item["actor"]
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
588 assert first_item_obj["content"] == "<div><p>XMPP item 4</p></div>"
6cc39a3b8c14 tests (unit): AP gateway unit tests:
Goffi <goffi@goffi.org>
parents:
diff changeset
589 assert first_item_obj["to"] == "https://www.w3.org/ns/activitystreams#Public"