annotate tests/e2e/libervia-cli/test_libervia-cli.py @ 3892:ba78cc0c8d59

doc (components/AP gateway): "reactions": fix 371
author Goffi <goffi@goffi.org>
date Wed, 31 Aug 2022 17:07:03 +0200
parents a75874df92b8
children f2a5936f2496
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python3
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
2
3480
7550ae9cfbac Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
3 # Libervia: an XMPP client
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3429
diff changeset
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
5
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 # This program is free software: you can redistribute it and/or modify
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # it under the terms of the GNU Affero General Public License as published by
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # the Free Software Foundation, either version 3 of the License, or
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # (at your option) any later version.
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
10
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
11 # This program is distributed in the hope that it will be useful,
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # GNU Affero General Public License for more details.
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
15
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
16 # You should have received a copy of the GNU Affero General Public License
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
19 import os
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import shutil
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import pytest
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
22 import sh
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
23 from sh import li
3769
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
24 from time import sleep
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.tools.common import uri
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
26
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
27
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
28 if os.getenv("LIBERVIA_TEST_ENV_E2E") is None:
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
29 pytest.skip(
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
30 "skipping end-to-end tests, we are not in a test environment",
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
31 allow_module_level=True
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
32 )
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
34
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
35 pytestmark = pytest.mark.usefixtures("test_profiles")
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
36
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
37
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
38 class TestInstall:
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
39
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
40 def test_li_can_run(self):
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
41 li("--version")
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
42
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
43
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
44 class TestLiberviaCliAccount:
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
45
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
46 def test_create_and_delete(self, li_json):
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
47 """Create an account in-band, connect it, then delete it and its profile"""
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
48 li.account.create(
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
49 "test_create@server1.test",
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
50 "test",
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
51 profile="test_create",
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
52 host="server1.test"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
53 )
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
54 profiles = li_json.profile.list()
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
55 assert "test_create" in profiles
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
56 li.profile.connect(connect=True, profile="test_create")
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
57 li.account.delete(profile="test_create", force=True)
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
58 li.profile.delete("test_create", force=True)
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
59 profiles = li_json.profile.list()
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
60 assert "test_create" not in profiles
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
61
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
62
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
63 @pytest.mark.usefixtures("pubsub_nodes")
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
64 class TestLiberviaCliPubsub:
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
65
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
66 def test_node_create_info_delete(self):
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
67 node_name = "tmp_node"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
68 with pytest.raises(sh.ErrorReturnCode_16):
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
69 # the node should not exist
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
70 li.pubsub.node.info(node=node_name)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
71 try:
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
72 li.pubsub.node.create(node=node_name)
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
73 # if node exist as expected, following command won't raise an exception
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
74 metadata = li.pubsub.node.info(node=node_name)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
75 assert len(metadata.strip())
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
76 finally:
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
77 li.pubsub.node.delete(node=node_name, force=True)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
78
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
79 with pytest.raises(sh.ErrorReturnCode_16):
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
80 # the node should not exist anymore
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
81 li.pubsub.node.info(node=node_name)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
82
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
83 def test_set_get_delete_purge(self, li_elt):
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
84 content = "test item"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
85 payload = f"<test>{content}</test>"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
86
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
87 # we create 3 items and check them
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
88 item1_id = li.pubsub.set(node="test", quiet=True, _in=payload)
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
89 item2_id = li.pubsub.set(node="test", quiet=True, _in=payload)
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
90 item3_id = li.pubsub.set(node="test", quiet=True, _in=payload)
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
91 parsed_elt = li_elt.pubsub.get(node="test", item=item1_id)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
92 payload = parsed_elt.firstChildElement()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
93 assert payload.name == 'test'
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
94 assert str(payload) == content
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
95 parsed_elt = li_elt.pubsub.get(node="test", item=item2_id)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
96 payload = parsed_elt.firstChildElement()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
97 assert payload.name == 'test'
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
98 assert str(payload) == content
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
99 parsed_elt = li_elt.pubsub.get(node="test", item=item3_id)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
100 payload = parsed_elt.firstChildElement()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
101 assert payload.name == 'test'
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
102 assert str(payload) == content
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
103
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
104 # deleting first item should work
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
105 li.pubsub.delete(node="test", item=item1_id, force=True)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
106 with pytest.raises(sh.ErrorReturnCode_16):
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
107 li.pubsub.get(node="test", item=item1_id)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
108
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
109 # there must be a least item2 and item3 in the node
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
110 node_items = li_elt.pubsub.get(node="test")
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
111 assert len(list(node_items.elements())) >= 2
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
112
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
113 # after purge, node must be empty
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
114 li.pubsub.node.purge(node="test", force=True)
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
115 node_items = li_elt.pubsub.get(node="test")
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
116 assert len(list(node_items.elements())) == 0
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
117
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
118 def test_edit(self, editor, li_elt):
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
119 content = "original item"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
120 payload = f"<test>{content}</test>"
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
121 item_id = li.pubsub.set(node="test", quiet=True, _in=payload)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
122 editor.set_filter('content.replace("original", "edited")')
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
123 li.pubsub.edit(node="test", item=item_id, _env=editor.env)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
124 assert "original item" in editor.original_content
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
125 parsed_elt = li_elt.pubsub.get(node="test", item=item_id)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
126 edited_payload = parsed_elt.firstChildElement()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
127 expected_edited_content = content.replace("original", "edited")
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
128 assert edited_payload.name == 'test'
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
129 assert str(edited_payload) == expected_edited_content
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
130
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
131 def test_affiliations(self, li_json):
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
132 affiliations = li_json.pubsub.affiliations()
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
133 assert affiliations["test"] == "owner"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
134
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
135 def test_uri(self):
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
136 built_uri = li.pubsub.uri(
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
137 service="pubsub.example.net", node="some_node"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
138 ).strip()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
139 assert built_uri == "xmpp:pubsub.example.net?;node=some_node"
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
140 built_uri = li.pubsub.uri(
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
141 service="pubsub.example.net", node="some_node", item="some_item"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
142 ).strip()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
143 assert built_uri == "xmpp:pubsub.example.net?;node=some_node;item=some_item"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
144
3674
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
145 def test_cache_search(self, li_json):
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
146 """A Full-Text Search query can be done"""
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
147 sk_txt = "this is a blog post about Slovakia"
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
148 fr_txt = "this is a blog post about France"
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
149 nc_txt = "this is a blog post about New Caledonia"
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
150 au_txt = "this is a blog post about Australia"
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
151 li.blog.set(
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
152 "-t", "travel", "-t", "europe",
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
153 _in=sk_txt,
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
154 syntax="markdown"
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
155 )
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
156 li.blog.set(
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
157 "-t", "travel", "-t", "europe",
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
158 _in=fr_txt,
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
159 syntax="markdown"
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
160 )
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
161 li.blog.set(
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
162 "-t", "travel", "-t", "south pacific",
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
163 _in=nc_txt,
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
164 syntax="markdown"
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
165 )
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
166 li.blog.set(
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
167 "-t", "travel", "-t", "south pacific",
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
168 _in="this is a blog post about Australia",
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
169 title=au_txt,
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
170 syntax="markdown"
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
171 )
3769
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
172 # we get the blog to activate the cache for it
3674
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
173 li.blog.get(max_items=1)
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
174 # FTS
3769
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
175 found = []
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
176 for __ in range(5):
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
177 found = li_json.pubsub.cache.search(
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
178 type="blog", fts='Slovakia OR "New Caledonia"'
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
179 )
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
180 if found:
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
181 break
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
182 else:
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
183 # retrieving blog triggers the caching, but it's done in parallel
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
184 # thus we may have nothing in cache yet
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
185 sleep(0.5)
3674
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
186 assert len(found) == 2
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
187 assert all(i["content"] in (sk_txt, nc_txt) for i in found)
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
188 # search by field
3769
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
189 found = li_json.pubsub.cache.search(
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
190 "-F", "tags", "overlap", "travel", type="blog"
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
191 )
3674
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
192 assert len(found) == 4
3769
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
193 found = li_json.pubsub.cache.search(
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
194 "-F", "tags", "overlap", "europe", type="blog"
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
195 )
3674
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
196 assert len(found) == 2
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
197 assert all(i["content"] in (sk_txt, fr_txt) for i in found)
3769
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
198 found = li_json.pubsub.cache.search(
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
199 "-F", "tags", "ioverlap", "SOUTH PACIFIC", type="blog"
a75874df92b8 tests (e2e/cli/cache_search): make the test more resilient:
Goffi <goffi@goffi.org>
parents: 3731
diff changeset
200 )
3674
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
201 assert all(i["content"] in (nc_txt, au_txt) for i in found)
eeb8be32d644 tests (e2e/CLI): tests for Pubsub Cache Search
Goffi <goffi@goffi.org>
parents: 3658
diff changeset
202
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
203
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
204 class TestLiberviaCliBlog:
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
205 MICROBLOG_NS = "urn:xmpp:microblog:0"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
206
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
207 def test_set_get(self, li_json):
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
208 li.blog.set(_in="markdown **bold** [link](https://example.net)")
3731
7e51cfc36d4e tests (e2e/CLI/set_get): fix RSM request:
Goffi <goffi@goffi.org>
parents: 3674
diff changeset
209 item_data = li_json.blog.get(max=1, before="")
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
210 item = item_data[0][0]
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
211 metadata = item_data[1]
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
212 assert metadata['service'] == "account1@server1.test"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
213 assert metadata['node'] == self.MICROBLOG_NS
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
214 assert metadata['rsm'].keys() <= {"first", "last", "index", "count"}
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
215 item_id = item['id']
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
216 expected_uri = uri.buildXMPPUri(
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
217 'pubsub', subtype="microblog", path="account1@server1.test",
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
218 node=self.MICROBLOG_NS, item=item_id
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
219 )
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
220 assert item['uri'] == expected_uri
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
221 assert item['content_xhtml'] == (
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
222 '<div><p>markdown <strong>bold</strong> '
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
223 '<a href="https://example.net">link</a></p></div>'
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
224 )
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
225 assert isinstance(item['published'], int)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
226 assert isinstance(item['updated'], int)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
227 assert isinstance(item['comments'], list)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
228 assert isinstance(item['tags'], list)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
229 assert item['author'] == 'account1'
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
230 assert item['author_jid'] == 'account1@server1.test'
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
231
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
232 def test_edit(self, editor, li_json):
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
233 payload_md = "content in **markdown**"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
234 editor.set_filter(repr(payload_md))
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
235 li.blog.edit(_env=editor.env)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
236 assert len(editor.original_content) == 0
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
237 assert editor.new_content == payload_md
3658
9e491b2bab88 test (e2e/cli): use `max_items` instead of `max` when retrieving blog items:
Goffi <goffi@goffi.org>
parents: 3498
diff changeset
238 items_data = li_json.blog.get(max_items=1)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
239 last_item = items_data[0][0]
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
240 last_item_id = last_item['id']
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
241 assert last_item['content'] == "content in markdown"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
242 assert last_item['content_xhtml'] == (
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
243 "<div><p>content in <strong>markdown</strong></p></div>"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
244 )
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
245 editor.set_filter('f"{content} extended"')
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
246 li.blog.edit("--last-item", _env=editor.env)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
247 assert editor.original_content == payload_md
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
248 assert editor.new_content == f"{payload_md} extended"
3658
9e491b2bab88 test (e2e/cli): use `max_items` instead of `max` when retrieving blog items:
Goffi <goffi@goffi.org>
parents: 3498
diff changeset
249 items_data = li_json.blog.get(max_items=1)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
250 last_item = items_data[0][0]
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
251 # we check that the id hasn't been modified
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
252 assert last_item['id'] == last_item_id
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
253 assert last_item['content'] == "content in markdown extended"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
254 assert last_item['content_xhtml'] == (
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
255 "<div><p>content in <strong>markdown</strong> extended</p></div>"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
256 )
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
257
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
258
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
259 class TestLiberviaCliFile:
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
260
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
261 def test_upload_get(self, fake_file):
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
262 source_file = fake_file.size(10240)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
263 source_file_hash = fake_file.get_source_hash(source_file)
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
264 upload_url = li.file.upload(source_file).strip()
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
265
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
266 dest_file = fake_file.new_dest_file()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
267 try:
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
268 li.file.get(upload_url, dest_file=dest_file)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
269 dest_file_hash = fake_file.get_dest_hash(dest_file)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
270 finally:
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
271 dest_file.unlink()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
272
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
273 assert source_file_hash == dest_file_hash
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
274
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
275 def test_send_receive(self, fake_file):
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
276 source_file = fake_file.size(10240)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
277 source_file_hash = fake_file.get_source_hash(source_file)
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
278 send_cmd = li.file.send(source_file, "account1@server2.test", _bg=True)
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
279 dest_path = fake_file.dest_files / "test_send_receive"
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
280 dest_path.mkdir()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
281 try:
3498
d78b5eae912a tests: update following names change
Goffi <goffi@goffi.org>
parents: 3480
diff changeset
282 li.file.receive(
3415
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
283 "account1@server1.test", profile="account1_s2", path=dest_path)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
284 dest_file = dest_path / source_file.name
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
285 dest_file_hash = fake_file.get_dest_hash(dest_file)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
286 finally:
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
287 shutil.rmtree(dest_path)
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
288 send_cmd.wait()
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
289
814e118d9ef3 tests: end-2-end tests first draft:
Goffi <goffi@goffi.org>
parents:
diff changeset
290 assert source_file_hash == dest_file_hash