summaryrefslogtreecommitdiff
path: root/tests/test_stream_xep_0461.py
blob: b73a99640ea7979ef15880adf3106d8e6316b863 (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
import logging
import unittest
from slixmpp.test import SlixTest


class TestReply(SlixTest):
    def setUp(self):
        self.stream_start(plugins=["xep_0461"])

    def tearDown(self):
        self.stream_close()

    def testFallBackBody(self):
        async def on_reply(msg):
            start = msg["feature_fallback"]["fallback_body"]["start"]
            end = msg["feature_fallback"]["fallback_body"]["end"]
            self.xmpp["xep_0461"].send_reply(
                reply_to=msg.get_from(),
                reply_id=msg.get_id(),
                mto="test@test.com",
                mbody=f"{start} to {end}",
            )

        self.xmpp.add_event_handler("message_reply", on_reply)

        self.recv(
            """
            <message id="other-id" from="from@from.com/res">
              <reply xmlns="urn:xmpp:reply:0" id="some-id" />
              <body>&gt; quoted\nsome-body</body>
                <fallback xmlns='urn:xmpp:feature-fallback:0' for='urn:xmpp:reply:0'>
                   <body start="0" end="8" />
                </fallback>
            </message>
            """
        )
        self.send(
            """
            <message xmlns="jabber:client" to="test@test.com" type="normal">
              <reply xmlns="urn:xmpp:reply:0" id="other-id" to="from@from.com/res" />
              <body>0 to 8</body>
            </message>
            """
        )


logging.basicConfig(level=logging.DEBUG)
suite = unittest.TestLoader().loadTestsFromTestCase(TestReply)