summaryrefslogtreecommitdiff
path: root/tests/test_stream_xep_0066.py
blob: 3dbaf840fe4859a034fb3995241609e7182aabb9 (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
61
62
63
64
65
66
67
68
69
70
71
72
import time
import threading

from sleekxmpp.test import *


class TestOOB(SleekTest):

    def tearDown(self):
        self.stream_close()

    def testSendOOB(self):
        """Test sending an OOB transfer request."""
        self.stream_start(plugins=['xep_0066', 'xep_0030'])

        url = 'http://github.com/fritzy/SleekXMPP/blob/master/README'

        t = threading.Thread(
                name='send_oob',
                target=self.xmpp['xep_0066'].send_oob,
                args=('user@example.com', url),
                kwargs={'desc': 'SleekXMPP README'})

        t.start()

        self.send("""
          <iq to="user@example.com" type="set" id="1">
            <query xmlns="jabber:iq:oob">
              <url>http://github.com/fritzy/SleekXMPP/blob/master/README</url>
              <desc>SleekXMPP README</desc>
            </query>
          </iq>
        """)

        self.recv("""
          <iq id="1" type="result"
              to="tester@localhost"
              from="user@example.com" />
        """)

        t.join()

    def testReceiveOOB(self):
        """Test receiving an OOB request."""
        self.stream_start(plugins=['xep_0066', 'xep_0030'])

        events = []

        def receive_oob(iq):
            events.append(iq['oob_transfer']['url'])

        self.xmpp.add_event_handler('oob_transfer', receive_oob)

        self.recv("""
          <iq to="tester@localhost"
              from="user@example.com"
              type="set" id="1">
            <query xmlns="jabber:iq:oob">
              <url>http://github.com/fritzy/SleekXMPP/blob/master/README</url>
              <desc>SleekXMPP README</desc>
            </query>
          </iq>
        """)

        time.sleep(0.1)

        self.assertEqual(events,
                ['http://github.com/fritzy/SleekXMPP/blob/master/README'],
                'URL was not received: %s' % events)


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