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