File: test_bookmarks.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 (124 lines) | stat: -rw-r--r-- 4,459 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
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
115
116
117
118
119
120
121
122
123
124
from test.lib.util import StanzaHandlerTest

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


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",  # noqa: S106
                    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)