summaryrefslogtreecommitdiff
path: root/tests/test_stream_xep_0249.py
blob: f12978a8c341a12879d48eae76e3ad439873cc75 (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
import time

import unittest
from slixmpp.test import SlixTest


class TestStreamDirectInvite(SlixTest):

    """
    Test using the XEP-0249 plugin.
    """

    def tearDown(self):
        self.stream_close()

    def testReceiveInvite(self):
        self.stream_start(mode='client',
                          plugins=['xep_0030',
                                   'xep_0249'])

        events = []

        def handle_invite(msg):
            events.append(True)

        self.xmpp.add_event_handler('groupchat_direct_invite',
                                    handle_invite)

        self.recv("""
          <message>
            <x xmlns="jabber:x:conference"
               jid="sleek@conference.jabber.org"
               password="foo"
               reason="For testing" />
          </message>
        """)

        self.failUnless(events == [True],
                "Event not raised: %s" % events)

    def testSentDirectInvite(self):
        self.stream_start(mode='client',
                          plugins=['xep_0030',
                                   'xep_0249'])

        self.xmpp['xep_0249'].send_invitation('user@example.com',
                                              'sleek@conference.jabber.org',
                                              reason='Need to test Slixmpp')

        self.send("""
          <message to="user@example.com">
            <x xmlns="jabber:x:conference"
               jid="sleek@conference.jabber.org"
               reason="Need to test Slixmpp" />
          </message>
        """)


suite = unittest.TestLoader().loadTestsFromTestCase(TestStreamDirectInvite)