XEP-0461: Message Replies
This commit is contained in:
48
tests/test_stanza_xep_0461.py
Normal file
48
tests/test_stanza_xep_0461.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import unittest
|
||||
from slixmpp import Message
|
||||
from slixmpp.test import SlixTest
|
||||
from slixmpp.plugins.xep_0461 import stanza
|
||||
|
||||
|
||||
class TestReply(SlixTest):
|
||||
def setUp(self):
|
||||
stanza.register_plugins()
|
||||
|
||||
def testReply(self):
|
||||
message = Message()
|
||||
message["reply"]["id"] = "some-id"
|
||||
message["body"] = "some-body"
|
||||
|
||||
self.check(
|
||||
message,
|
||||
"""
|
||||
<message>
|
||||
<reply xmlns="urn:xmpp:reply:0" id="some-id" />
|
||||
<body>some-body</body>
|
||||
</message>
|
||||
""",
|
||||
)
|
||||
|
||||
def testFallback(self):
|
||||
message = Message()
|
||||
message["body"] = "12345\nrealbody"
|
||||
message["feature_fallback"]["for"] = "NS"
|
||||
message["feature_fallback"]["fallback_body"]["start"] = "0"
|
||||
message["feature_fallback"]["fallback_body"]["end"] = "6"
|
||||
|
||||
self.check(
|
||||
message,
|
||||
"""
|
||||
<message xmlns="jabber:client">
|
||||
<body>12345\nrealbody</body>
|
||||
<fallback xmlns='urn:xmpp:feature-fallback:0' for='NS'>
|
||||
<body start="0" end="6" />
|
||||
</fallback>
|
||||
</message>
|
||||
""",
|
||||
)
|
||||
|
||||
assert message["feature_fallback"].get_stripped_body() == "realbody"
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestReply)
|
||||
48
tests/test_stream_xep_0461.py
Normal file
48
tests/test_stream_xep_0461.py
Normal file
@@ -0,0 +1,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>> 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)
|
||||
Reference in New Issue
Block a user