Commit 5ae33d6b authored by louiz’'s avatar louiz’

e2e: add tests for the linger time option

parent 70014a7f
#!/usr/bin/env python3
import collections
import datetime
import slixmpp
import asyncio
import logging
......@@ -95,7 +96,11 @@ class XMPPComponent(slixmpp.BaseXMPP):
def run_scenario(self):
if self.scenario.steps:
step = self.scenario.steps.pop(0)
step(self, self.biboumi)
try:
step(self, self.biboumi)
except Exception as e:
self.error(e)
self.run_scenario()
else:
if self.biboumi:
self.biboumi.stop()
......@@ -261,6 +266,16 @@ def expect_stanza(xpaths, xmpp, biboumi, optional=False, after=None):
else:
print("Warning, from argument type passed to expect_stanza: %s" % (type(xpaths)))
def save_datetime(xmpp, biboumi):
xmpp.saved_values["saved_datetime"] = datetime.datetime.now()
asyncio.get_event_loop().call_soon(xmpp.run_scenario)
def expect_now_is_after(timedelta, xmpp, biboumi):
time_passed = datetime.datetime.now() - xmpp.saved_values["saved_datetime"]
if time_passed < timedelta:
raise StanzaError("Not enough time has passed: %s instead of %s" % (time_passed, timedelta))
asyncio.get_event_loop().call_soon(xmpp.run_scenario)
# list_of_xpaths: [(xpath, xpath), (xpath, xpath), (xpath)]
def expect_unordered(list_of_xpaths, xmpp, biboumi):
formatted_list_of_xpaths = []
......@@ -473,7 +488,6 @@ def extract_attribute(xpath, name, stanza):
def save_value(name, func, stanza, xmpp):
xmpp.saved_values[name] = func(stanza)
if __name__ == '__main__':
atexit.register(asyncio.get_event_loop().close)
......@@ -1947,6 +1961,42 @@ if __name__ == '__main__':
partial(send_stanza, "<iq type='set' id='id4' from='{jid_one}/{resource_one}' to='{irc_server_one}'><command xmlns='http://jabber.org/protocol/commands' action='cancel' node='configure' sessionid='{sessionid}' /></iq>"),
partial(expect_stanza, "/iq[@type='result']/commands:command[@node='configure'][@status='canceled']"),
]),
Scenario("irc_server_linger_time",
[
handshake_sequence(),
# Set a custom value for the linger_time option, using the ad-hoc command
partial(send_stanza, "<iq type='set' id='id1' from='{jid_one}/{resource_one}' to='{irc_server_one}'><command xmlns='http://jabber.org/protocol/commands' node='configure' action='execute' /></iq>"),
partial(expect_stanza, ("/iq[@type='result']/commands:command[@node='configure'][@sessionid][@status='executing']",
"/iq/commands:command/dataform:x[@type='form']/dataform:title[text()='Configure the IRC server irc.localhost']",
"/iq/commands:command/commands:actions/commands:next",
),
after = partial(save_value, "sessionid", partial(extract_attribute, "/iq[@type='result']/commands:command[@node='configure']", "sessionid"))
),
partial(send_stanza, "<iq type='set' id='id2' from='{jid_one}/{resource_one}' to='{irc_server_one}'>"
"<command xmlns='http://jabber.org/protocol/commands' node='configure' sessionid='{sessionid}' action='next'>"
"<x xmlns='jabber:x:data' type='submit'>"
"<field var='linger_time'><value>3</value></field>"
"</x></command></iq>"),
partial(expect_stanza, "/iq[@type='result']/commands:command[@node='configure'][@status='completed']/commands:note[@type='info'][text()='Configuration successfully applied.']"),
partial(send_stanza,
"<presence from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' />"),
connection_sequence("irc.localhost", '{jid_one}/{resource_one}'),
partial(expect_stanza,
"/message/body[text()='Mode #foo [+nt] by {irc_host_one}']"),
partial(expect_stanza,
("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='admin'][@role='moderator']",
"/presence/muc_user:x/muc_user:status[@code='110']")
),
partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"),
partial(save_datetime),
partial(send_stanza, "<presence type='unavailable' from='{jid_one}/{resource_one}' to='#foo%{irc_server_one}/{nick_one}' />"),
partial(expect_stanza, "/presence[@type='unavailable'][@from='#foo%{irc_server_one}/{nick_one}']"),
partial(expect_stanza, "/message[@from='{irc_server_one}']/body[text()='ERROR: Closing Link: localhost (Client Quit)']"),
partial(expect_stanza, "/message[@from='{irc_server_one}']/body[text()='ERROR: Connection closed.']"),
partial(expect_now_is_after, datetime.timedelta(seconds=3)),
]),
Scenario("irc_tls_connection",
[
handshake_sequence(),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment