import unittest
from slixmpp import JID, Iq, Message
from slixmpp.test import SlixTest
from slixmpp.plugins.xep_0313 import stanza
from slixmpp.plugins.xep_0004.stanza import Form
from slixmpp.plugins.xep_0297 import stanza as fstanza
from slixmpp.plugins.xep_0059 import stanza as rstanza
from slixmpp.xmlstream import register_stanza_plugin
class TestMAM(SlixTest):
def setUp(self):
register_stanza_plugin(stanza.MAM, Form)
register_stanza_plugin(Iq, stanza.MAM)
register_stanza_plugin(Message, stanza.Result)
register_stanza_plugin(Iq, stanza.Fin)
register_stanza_plugin(
stanza.Result,
fstanza.Forwarded
)
register_stanza_plugin(stanza.MAM, rstanza.Set)
register_stanza_plugin(stanza.Fin, rstanza.Set)
register_stanza_plugin(Iq, stanza.Metadata)
register_stanza_plugin(stanza.Metadata, stanza.Start)
register_stanza_plugin(stanza.Metadata, stanza.End)
def testMAMQuery(self):
"""Test that we can build a simple MAM query."""
iq = Iq()
iq['type'] = 'set'
iq['mam']['queryid'] = 'f27'
self.check(iq, """
""")
def testMAMQueryOptions(self):
"""Test that we can build a mam query with all options."""
iq = Iq()
iq['type'] = 'set'
iq['mam']['with'] = JID('juliet@capulet.lit')
iq['mam']['start'] = '2010-06-07T00:00:00Z'
iq['mam']['end'] = '2010-07-07T13:23:54Z'
iq['mam']['after_id'] = 'id1'
iq['mam']['before_id'] = 'id2'
iq['mam']['ids'] = ['a', 'b', 'c']
self.check(iq, """
urn:xmpp:mam:2
juliet@capulet.lit
2010-06-07T00:00:00Z
2010-07-07T13:23:54Z
id1
id2
a
b
c
""", use_values=False)
def testMAMMetadata(self):
"""Test that we can build a MAM metadata payload"""
iq = Iq()
iq['type'] = 'result'
iq['mam_metadata']['start']['id'] = 'YWxwaGEg'
iq['mam_metadata']['start']['timestamp'] = '2008-08-22T21:09:04Z'
iq['mam_metadata']['end']['id'] = 'b21lZ2Eg'
iq['mam_metadata']['end']['timestamp'] = '2020-04-20T14:34:21Z'
self.check(iq, """
""")
suite = unittest.TestLoader().loadTestsFromTestCase(TestMAM)