Mercurial > libervia-backend
annotate tests/unit/test_plugin_xep_0298.py @ 4299:d2deddd6df44
tools (xml_tools): add `namespace` argument to `xmlui_result_to_elt`:
this allows to specify resulting Form namespace.
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 06 Sep 2024 17:45:46 +0200 |
parents | 9447796408f6 |
children |
rev | line source |
---|---|
4293
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 from twisted.words.xish import domish |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 from twisted.words.protocols.jabber import jid |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 from libervia.backend.plugins.plugin_xep_0298 import NS_COIN, NS_CONFERENCE_INFO, XEP_0298 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 from libervia.backend.core.constants import Const as C |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 class TestXEP0298: |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 def test_add_conference_info(self, host): |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 """Conference info element is correctly added to jingle element""" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 xep_0298 = XEP_0298(host) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 jingle_elt = domish.Element((None, "jingle")) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 conference_info_elt = xep_0298.add_conference_info( |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 jingle_elt, is_focus=True, room="test_room" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 ) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 assert conference_info_elt.name == "conference-info" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 assert conference_info_elt.uri == NS_CONFERENCE_INFO |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 assert conference_info_elt["isfocus"] == C.BOOL_TRUE |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 assert conference_info_elt["room"] == "test_room" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
21 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 def test_add_user(self, host): |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
23 """User is correctly added to conference info element""" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 xep_0298 = XEP_0298(host) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
25 conference_info_elt = domish.Element((NS_CONFERENCE_INFO, "conference-info")) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 entity = jid.JID("user@example.com/resource") |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
27 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 user_elt = xep_0298.add_user(conference_info_elt, entity) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 assert user_elt.name == "user" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 assert user_elt.parent.name == "users" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 assert user_elt["entity"] == "xmpp:user%40example.com" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
33 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 def test_add_multiple_users(self, host): |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 """Multiple users are correctly added to conference info element""" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 xep_0298 = XEP_0298(host) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 conference_info_elt = domish.Element((NS_CONFERENCE_INFO, "conference-info")) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 entities = [jid.JID(f"user{i}@example.com/resource") for i in range(3)] |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 for entity in entities: |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 xep_0298.add_user(conference_info_elt, entity) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 users_elt = next(conference_info_elt.elements(NS_CONFERENCE_INFO, "users")) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 user_elts = list(users_elt.elements(NS_CONFERENCE_INFO, "user")) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 assert len(user_elts) == 3 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 for i, user_elt in enumerate(user_elts): |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 assert user_elt["entity"] == f"xmpp:user{i}%40example.com" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 def test_parse_with_conference_info(self, host): |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 """Jingle element with conference info is correctly parsed""" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 xep_0298 = XEP_0298(host) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 jingle_elt = domish.Element((None, "jingle")) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 conference_info_elt = jingle_elt.addElement( |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 (NS_CONFERENCE_INFO, "conference-info") |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 ) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 users_elt = conference_info_elt.addElement("users") |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 user_elt = users_elt.addElement("user") |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 user_elt["entity"] = "xmpp:user%40example.com" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 result = xep_0298.parse(jingle_elt) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 assert "info" in result |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 assert "users" in result["info"] |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 assert len(result["info"]["users"]) == 1 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 assert str(result["info"]["users"][0]) == "user@example.com" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
66 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
67 def test_parse_without_conference_info(self, host): |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 """Jingle element without conference info returns empty dict""" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 xep_0298 = XEP_0298(host) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 jingle_elt = domish.Element((None, "jingle")) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 result = xep_0298.parse(jingle_elt) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
73 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
74 assert result == {} |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
75 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
76 def test_coin_handler_disco_info(self, host): |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 """CoinHandler returns correct disco info""" |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 xep_0298 = XEP_0298(host) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 handler = xep_0298.get_handler(None) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 disco_info = handler.getDiscoInfo(None, None) |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 assert len(disco_info) == 1 |
9447796408f6
tests (unit): add test for XEP-0298 plugin + fix XEP-0167:
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 assert disco_info[0] == NS_COIN |