File: test_hats.py

package info (click to toggle)
python-nbxmpp 6.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,340 kB
  • sloc: python: 19,639; makefile: 4
file content (56 lines) | stat: -rw-r--r-- 2,113 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from test.lib.util import StanzaHandlerTest

from nbxmpp import Presence
from nbxmpp.language import LanguageRange
from nbxmpp.modules.muc.hats import Hats
from nbxmpp.structs import Hat
from nbxmpp.structs import PresenceProperties


class TestHats(StanzaHandlerTest):
    def test_parse_hats(self):
        # language=XML
        xml = """
        <presence
            from='meeting123@meetings.example.com/Harry'
            id='D568A74F-E062-407C-83E9-531E91526516'
            to='someone@example.com/foo'>
          <x xmlns='http://jabber.org/protocol/muc#user'>
            <item affiliation='owner' role='moderator'/>
          </x>
          <hats xmlns='urn:xmpp:hats:0'>
            <hat title='Member' uri='http://schemas.example.com/hats#member' xml:lang='en-us' />
            <hat title='Mitglied' uri='http://schemas.example.com/hats#member' xml:lang='de-de' />
            <hat title='Owner' uri='http://schemas.example.com/hats#owner' xml:lang='en-us' />
            <hat title='Eigentümer' uri='http://schemas.example.com/hats#owner' xml:lang='de-de' />
          </hats>
        </presence>
        """

        props = PresenceProperties("mockjid")
        presence = Presence(node=xml)
        Hats._process_hats(None, None, presence, props)

        hat_list_en = [
            Hat(uri="http://schemas.example.com/hats#member", title="Member"),
            Hat(uri="http://schemas.example.com/hats#owner", title="Owner"),
        ]

        hat_list_de = [
            Hat(uri="http://schemas.example.com/hats#member", title="Mitglied"),
            Hat(uri="http://schemas.example.com/hats#owner", title="Eigentümer"),
        ]

        lang_range_en = [LanguageRange(tag="en")]
        lang_range_de = [LanguageRange(tag="de")]

        assert props.hats is not None

        hats_en = props.hats.get_hats(lang_range_en)
        self.assertSequenceEqual(hat_list_en, hats_en)

        hats_de = props.hats.get_hats(lang_range_de)
        self.assertSequenceEqual(hat_list_de, hats_de)

        hats_any = props.hats.get_hats()
        self.assertSequenceEqual(hat_list_de, hats_any)