summaryrefslogtreecommitdiff
path: root/itests/test_quickresponse.py
blob: 972659f3a69647f597d70140195458e979587e64 (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 unittest
from slixmpp.test.integration import SlixIntegration
from slixmpp.plugins.xep_0439 import stanza


class TestQuickResponse(SlixIntegration):
    async def asyncSetUp(self):
        self.add_client(
            self.envjid('CI_ACCOUNT1'),
            self.envstr('CI_ACCOUNT1_PASSWORD'),
        )
        self.add_client(
            self.envjid('CI_ACCOUNT2'),
            self.envstr('CI_ACCOUNT2_PASSWORD'),
        )
        self.register_plugins(['xep_0439'])
        await self.connect_clients()

    async def test_quickresponse(self):
        """Send and receive actions and responses"""
        actions = [
            ('id1', 'Action 1'),
            ('id2', 'Action 2'),
        ]
        self.clients[0]['xep_0439'].ask_for_actions(
            self.clients[1].boundjid.full,
            "Action 1 or 2 ?",
            actions
        )
        msg = await self.clients[1].wait_until('action_received')
        actions_recv = [
            (st['id'], st['label']) for st in msg if isinstance(st, stanza.Action)
        ]
        self.assertEqual(
                actions,
                actions_recv,
        )

        reply = self.clients[1].make_message(
            mto=self.clients[0].boundjid.full
        )
        reply['action_selected']['id'] = 'id1'
        reply.send()

        reply_recv = await self.clients[0].wait_until('action_selected')
        self.assertEqual(
            reply_recv['action_selected']['id'],
            'id1',
        )

        self.clients[0]['xep_0439'].ask_for_response(
            self.clients[1].boundjid.full,
            "Reply with action 1 or 2 (id1/id2) ?",
            actions
        )
        msg = await self.clients[1].wait_until('responses_received')


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