XEP-0422,0424,0425,0439: Add basic stanza tests
This commit is contained in:
parent
2c523d1a3b
commit
fdb0749cd1
4 changed files with 176 additions and 0 deletions
33
tests/test_stanza_xep_0422.py
Normal file
33
tests/test_stanza_xep_0422.py
Normal file
|
@ -0,0 +1,33 @@
|
|||
import unittest
|
||||
from slixmpp import Message
|
||||
from slixmpp.test import SlixTest
|
||||
from slixmpp.xmlstream import ET
|
||||
from slixmpp.plugins.xep_0422 import stanza
|
||||
|
||||
|
||||
class TestFastening(SlixTest):
|
||||
|
||||
def setUp(self):
|
||||
stanza.register_plugins()
|
||||
|
||||
def testFastenExternal(self):
|
||||
message = Message()
|
||||
message['apply_to']['id'] = 'some-id'
|
||||
message['apply_to'].xml.append(
|
||||
ET.fromstring('<test xmlns="urn:tmp:test">Test</test>')
|
||||
)
|
||||
message['apply_to']['external']['name'] = 'body'
|
||||
message['body'] = 'Toto'
|
||||
|
||||
self.check(message, """
|
||||
<message>
|
||||
<apply-to xmlns="urn:xmpp:fasten:0" id="some-id">
|
||||
<test xmlns="urn:tmp:test">Test</test>
|
||||
<external name='body'/>
|
||||
</apply-to>
|
||||
<body>Toto</body>
|
||||
</message>
|
||||
""", use_values=False)
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestFastening)
|
39
tests/test_stanza_xep_0424.py
Normal file
39
tests/test_stanza_xep_0424.py
Normal file
|
@ -0,0 +1,39 @@
|
|||
import unittest
|
||||
from slixmpp import Message
|
||||
from slixmpp.test import SlixTest
|
||||
from slixmpp.plugins.xep_0424 import stanza
|
||||
|
||||
|
||||
class TestRetraction(SlixTest):
|
||||
|
||||
def setUp(self):
|
||||
stanza.register_plugins()
|
||||
|
||||
def testRetract(self):
|
||||
message = Message()
|
||||
message['apply_to']['id'] = 'some-id'
|
||||
message['apply_to']['retract']
|
||||
|
||||
self.check(message, """
|
||||
<message>
|
||||
<apply-to xmlns="urn:xmpp:fasten:0" id="some-id">
|
||||
<retract xmlns="urn:xmpp:message-retract:0"/>
|
||||
</apply-to>
|
||||
</message>
|
||||
""", use_values=False)
|
||||
|
||||
def testRetracted(self):
|
||||
message = Message()
|
||||
message['retracted']['stamp'] = '2019-09-20T23:09:32Z'
|
||||
message['retracted']['origin_id']['id'] = 'originid'
|
||||
|
||||
self.check(message, """
|
||||
<message>
|
||||
<retracted stamp="2019-09-20T23:09:32Z" xmlns="urn:xmpp:message-retract:0">
|
||||
<origin-id xmlns="urn:xmpp:sid:0" id="originid"/>
|
||||
</retracted>
|
||||
</message>
|
||||
""")
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestRetraction)
|
47
tests/test_stanza_xep_0425.py
Normal file
47
tests/test_stanza_xep_0425.py
Normal file
|
@ -0,0 +1,47 @@
|
|||
import unittest
|
||||
from slixmpp import Message, Iq, JID
|
||||
from slixmpp.test import SlixTest
|
||||
from slixmpp.plugins.xep_0425 import stanza
|
||||
|
||||
|
||||
class TestModeration(SlixTest):
|
||||
|
||||
def setUp(self):
|
||||
stanza.register_plugins()
|
||||
|
||||
def testModerate(self):
|
||||
iq = Iq()
|
||||
iq['type'] = 'set'
|
||||
iq['id'] = 'a'
|
||||
iq['apply_to']['id'] = 'some-id'
|
||||
iq['apply_to']['moderate'].enable('retract')
|
||||
iq['apply_to']['moderate']['reason'] = 'R'
|
||||
|
||||
self.check(iq, """
|
||||
<iq type='set' id='a'>
|
||||
<apply-to id="some-id" xmlns="urn:xmpp:fasten:0">
|
||||
<moderate xmlns='urn:xmpp:message-moderate:0'>
|
||||
<retract xmlns='urn:xmpp:message-retract:0'/>
|
||||
<reason>R</reason>
|
||||
</moderate>
|
||||
</apply-to>
|
||||
</iq>
|
||||
""", use_values=False)
|
||||
|
||||
def testModerated(self):
|
||||
message = Message()
|
||||
message['moderated']['by'] = JID('toto@titi')
|
||||
message['moderated']['retracted']['stamp'] = '2019-09-20T23:09:32Z'
|
||||
message['moderated']['reason'] = 'R'
|
||||
|
||||
self.check(message, """
|
||||
<message>
|
||||
<moderated xmlns="urn:xmpp:message-moderate:0" by="toto@titi">
|
||||
<retracted stamp="2019-09-20T23:09:32Z" xmlns="urn:xmpp:message-retract:0" />
|
||||
<reason>R</reason>
|
||||
</moderated>
|
||||
</message>
|
||||
""")
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestModeration)
|
57
tests/test_stanza_xep_0439.py
Normal file
57
tests/test_stanza_xep_0439.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
import unittest
|
||||
from slixmpp import Message
|
||||
from slixmpp.test import SlixTest
|
||||
from slixmpp.plugins.xep_0439 import stanza
|
||||
|
||||
|
||||
class TestQuickResponse(SlixTest):
|
||||
|
||||
def setUp(self):
|
||||
stanza.register_plugins()
|
||||
|
||||
def testResponse(self):
|
||||
message = Message()
|
||||
message['body'] = 'Reply 1 or 2?'
|
||||
for (value, label) in [('1', 'Rep 1'), ('2', 'Rep 2')]:
|
||||
rep = stanza.Response()
|
||||
rep['value'] = value
|
||||
rep['label'] = label
|
||||
message.append(rep)
|
||||
|
||||
self.check(message, """
|
||||
<message>
|
||||
<body>Reply 1 or 2?</body>
|
||||
<response xmlns="urn:xmpp:tmp:quick-response" value="1" label="Rep 1" />
|
||||
<response xmlns="urn:xmpp:tmp:quick-response" value="2" label="Rep 2" />
|
||||
</message>
|
||||
""", use_values=False)
|
||||
|
||||
def testAction(self):
|
||||
message = Message()
|
||||
message['body'] = 'action 1 or 2?'
|
||||
for (id_, label) in [('1', 'action 1'), ('2', 'action 2')]:
|
||||
act = stanza.Action()
|
||||
act['id'] = id_
|
||||
act['label'] = label
|
||||
message.append(act)
|
||||
|
||||
self.check(message, """
|
||||
<message>
|
||||
<body>action 1 or 2?</body>
|
||||
<action xmlns="urn:xmpp:tmp:quick-response" id="1" label="action 1" />
|
||||
<action xmlns="urn:xmpp:tmp:quick-response" id="2" label="action 2" />
|
||||
</message>
|
||||
""", use_values=False)
|
||||
|
||||
def testActionSelected(self):
|
||||
message = Message()
|
||||
message['action_selected']['id'] = 'act1'
|
||||
|
||||
self.check(message, """
|
||||
<message>
|
||||
<action-selected xmlns="urn:xmpp:tmp:quick-response" id="act1" />
|
||||
</message>
|
||||
""", use_values=False)
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestQuickResponse)
|
Loading…
Reference in a new issue