import unittest
from slixmpp.test import SlixTest
class TestJabberSearch(SlixTest):
def setUp(self):
self.stream_start(
mode="component",
plugin_config={
"xep_0055": {
"form_fields": {"first", "last"},
"form_instructions": "INSTRUCTIONS",
"form_title": "User Directory Search",
}
},
jid="characters.shakespeare.lit",
plugins={"xep_0055"}
)
self.xmpp["xep_0055"].api.register(get_results, "search_query")
self.xmpp["xep_0055"].api.register(get_results, "search_query")
def testRequestingSearchFields(self):
self.recv(
"""
"""
)
self.send(
"""
User Directory Search
INSTRUCTIONS
jabber:iq:search
""",
use_values=False,
)
def testSearchResult(self):
self.recv(
"""
jabber:iq:search
Montague
"""
)
self.send(
"""
jabber:iq:search
-
Benvolio
Montague
""",
use_values=False, # TypeError: element indices must be integers without that
)
def testSearchNoResult(self):
self.xmpp["xep_0055"].api.register(get_results, "search_query")
self.recv(
"""
jabber:iq:search
Capulet
"""
)
self.send(
"""
jabber:iq:search
""",
use_values=False, # TypeError: element indices must be integers without that
)
async def get_results(jid, node, ifrom, iq):
reply = iq.reply()
form = reply["search"]["form"]
form["type"] = "result"
form.add_reported("first", label="Given Name")
form.add_reported("last", label="Family Name")
d = iq["search"]["form"].get_values()
if d["last"] == "Montague":
form.add_item({"first": "Benvolio", "last": "Montague"})
return reply
suite = unittest.TestLoader().loadTestsFromTestCase(TestJabberSearch)