Commit bd625aa5 authored by louiz’'s avatar louiz’
Browse files

e2etests: we are able to receive optional stanzas

parent 45f442b6
......@@ -21,6 +21,17 @@ class MatchAll(MatcherBase):
class StanzaError(Exception):
Raised when a step fails.
class SkipStepError(Exception):
Raised by a step when it needs to be skiped, by running
the next available step immediately.
......@@ -69,6 +80,10 @@ class XMPPComponent(slixmpp.BaseXMPP):
except StanzaError as e:
except SkipStepError:
# Run the next step and then re-handle this same stanza
return self.handle_incoming_stanza(stanza)
self.stanza_checker = None
......@@ -97,6 +112,13 @@ def check_xpath(xpaths, stanza):
raise StanzaError("Received stanza “%s” did not match expected xpath “%s”" % (stanza, xpath))
def check_xpath_optional(xpaths, stanza):
check_xpath(xpaths, stanza)
except StanzaError:
raise SkipStepError()
class Scenario:
"""Defines a list of actions that are executed in sequence, until one of
them throws an exception, or until the end. An action can be something
......@@ -170,11 +192,12 @@ def send_stanza(stanza, xmpp, biboumi):
def expect_stanza(xpaths, xmpp, biboumi):
def expect_stanza(xpaths, xmpp, biboumi, optional=False):
check_func = check_xpath if not optional else check_xpath_optional
if isinstance(xpaths, str):
xmpp.stanza_checker = partial(check_xpath, [xpaths.format_map(common_replacements)])
xmpp.stanza_checker = partial(check_func, [xpaths.format_map(common_replacements)])
elif isinstance(xpaths, tuple):
xmpp.stanza_checker = partial(check_xpath, [xpath.format_map(common_replacements) for xpath in xpaths])
xmpp.stanza_checker = partial(check_func, [xpath.format_map(common_replacements) for xpath in xpaths])
print("Warning, from argument type passed to expect_stanza: %s" % (type(xpaths)))
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