File: test_mood.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 (49 lines) | stat: -rw-r--r-- 1,724 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
from test.lib.util import StanzaHandlerTest

from nbxmpp.namespaces import Namespace
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import MoodData
from nbxmpp.structs import PubSubEventData


class MoodTest(StanzaHandlerTest):

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

            data = MoodData(mood='annoyed', text='curse my nurse!')

            pubsub_event = PubSubEventData(
                node='http://jabber.org/protocol/mood',
                id='a475804a-0f9c-11dc-98a8-001143d5d5db',
                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='http://jabber.org/protocol/mood'>
                        <item id='a475804a-0f9c-11dc-98a8-001143d5d5db'>
                            <mood xmlns='http://jabber.org/protocol/mood'>
                                <annoyed/>
                                <text>curse my nurse!</text>
                            </mood>
                        </item>
                    </items>
                </event>
            </message>
        '''

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

        self.dispatcher.process_data(event)