Welcome to mirror list, hosted at ThFree Co, Russian Federation.

test_tune.py « unit « test - dev.gajim.org/gajim/python-nbxmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5984266ed2d771437e43cc419a153fe2c18a4840 (plain)
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
from test.lib.util import StanzaHandlerTest

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


class TuneTest(StanzaHandlerTest):

    def test_tune_parsing(self):
        def _on_message(_con, _stanza, properties):
   
            data = TuneData(artist='Yes',
                            length='686',
                            rating='8',
                            source='Yessongs',
                            title='Heart of the Sunrise',
                            track='3',
                            uri='https://www.artist.com')

            pubsub_event = PubSubEventData(
                node='http://jabber.org/protocol/tune',
                id='bffe6584-0f9c-11dc-84ba-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/tune'>
                        <item id='bffe6584-0f9c-11dc-84ba-001143d5d5db'>
                            <tune xmlns='http://jabber.org/protocol/tune'>
                                <artist>Yes</artist>
                                <length>686</length>
                                <rating>8</rating>
                                <source>Yessongs</source>
                                <title>Heart of the Sunrise</title>
                                <track>3</track>
                                <uri>https://www.artist.com</uri>
                            </tune>
                        </item>
                    </items>
                </event>
            </message>
        '''

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

        self.dispatcher.process_data(event)