summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorlouiz’ <louiz@louiz.org>2017-02-12 16:50:47 +0100
committerlouiz’ <louiz@louiz.org>2017-02-12 16:50:47 +0100
commit5ae33d6b9ed47bf43626066c5bdc4d91a7b75db1 (patch)
treec4134347310d27559b15e662e8fa5b2d98556508 /tests
parent70014a7f6611360d4862835586dbaa30df20a2d0 (diff)
downloadbiboumi-5ae33d6b9ed47bf43626066c5bdc4d91a7b75db1.tar.gz
biboumi-5ae33d6b9ed47bf43626066c5bdc4d91a7b75db1.tar.bz2
biboumi-5ae33d6b9ed47bf43626066c5bdc4d91a7b75db1.tar.xz
biboumi-5ae33d6b9ed47bf43626066c5bdc4d91a7b75db1.zip
e2e: add tests for the linger time option
Diffstat (limited to 'tests')
-rw-r--r--tests/end_to_end/__main__.py54
1 files changed, 52 insertions, 2 deletions
diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py
index 20730a7..92a903c 100644
--- a/tests/end_to_end/__main__.py
+++ b/tests/end_to_end/__main__.py
@@ -1,6 +1,7 @@
#!/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(),