File: test_bookmarks.py

package info (click to toggle)
python-nbxmpp 2.0.2-1%2Bdeb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,120 kB
  • sloc: python: 14,949; makefile: 8
file content (114 lines) | stat: -rw-r--r-- 4,471 bytes parent folder | download | duplicates (3)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
from test.lib.util import StanzaHandlerTest

from nbxmpp.namespaces import Namespace
from nbxmpp.protocol import JID
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import BookmarkData
from nbxmpp.structs import PubSubEventData


class BookmarkTest(StanzaHandlerTest):

    def test_bookmark_1_parsing(self):
        def _on_message(_con, _stanza, properties):

            data = [
                BookmarkData(jid=JID.from_string('theplay@conference.shakespeare.lit'),
                             name='The Play\'s the Thing',
                             autojoin=True,
                             password='pass',
                             nick='JC'),
                BookmarkData(jid=JID.from_string('second@conference.shakespeare.lit'),
                             name='Second room',
                             autojoin=False,
                             password=None,
                             nick=None)
            ]

            pubsub_event = PubSubEventData(
                node='storage:bookmarks',
                id='current',
                item=None,
                data=data,
                deleted=False,
                retracted=False,
                purged=False)

            # We cant compare Node objects
            pubsub_event_ = properties.pubsub_event._replace(item=None)
            self.assertEqual(pubsub_event, pubsub_event_)

        event = '''
            <message from='test@test.test'>
                <event xmlns='http://jabber.org/protocol/pubsub#event'>
                    <items node='storage:bookmarks'>
                        <item id='current'>
                            <storage xmlns='storage:bookmarks'>
                                <conference name='The Play&apos;s the Thing'
                                            autojoin='true'
                                            jid='theplay@conference.shakespeare.lit'>
                                    <password>pass</password>
                                    <nick>JC</nick>
                                </conference>
                                <conference name='Second room'
                                            autojoin='0'
                                            jid='second@conference.shakespeare.lit'>
                                </conference>
                            </storage>
                        </item>
                    </items>
                </event>
            </message>
        '''

        self.dispatcher.register_handler(
            StanzaHandler(name='message',
                          callback=_on_message,
                          ns=Namespace.PUBSUB_EVENT))

        self.dispatcher.process_data(event)

    def test_bookmark_2_parsing(self):
        def _on_message(_con, _stanza, properties):

            data = BookmarkData(jid=JID.from_string('theplay@conference.shakespeare.lit'),
                                name='The Play\'s the Thing',
                                autojoin=True,
                                password=None,
                                nick='JC')

            pubsub_event = PubSubEventData(
                node='urn:xmpp:bookmarks:0',
                id='theplay@conference.shakespeare.lit',
                item=None,
                data=data,
                deleted=False,
                retracted=False,
                purged=False)

            # We cant compare Node objects
            pubsub_event_ = properties.pubsub_event._replace(item=None)
            self.assertEqual(pubsub_event, pubsub_event_)

        event = '''
            <message from='test@test.test'>
                <event xmlns='http://jabber.org/protocol/pubsub#event'>
                    <items node='urn:xmpp:bookmarks:0'>
                        <item id='theplay@conference.shakespeare.lit'>
                            <conference xmlns='urn:xmpp:bookmarks:0'
                                        name='The Play&apos;s the Thing'
                                        autojoin='1'>
                                <nick>JC</nick>
                            </conference>
                        </item>
                    </items>
                </event>
            </message>
        '''

        self.dispatcher.register_handler(
            StanzaHandler(name='message',
                          callback=_on_message,
                          ns=Namespace.PUBSUB_EVENT))

        self.dispatcher.process_data(event)