From 45f442b67d0331e82e25d8cafe3b6f2c87d1d611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Sun, 17 Apr 2016 17:01:28 +0200 Subject: More tests --- tests/end_to_end/__main__.py | 65 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 6 deletions(-) (limited to 'tests/end_to_end/__main__.py') diff --git a/tests/end_to_end/__main__.py b/tests/end_to_end/__main__.py index 3d907ca..f498585 100644 --- a/tests/end_to_end/__main__.py +++ b/tests/end_to_end/__main__.py @@ -87,6 +87,7 @@ class XMPPComponent(slixmpp.BaseXMPP): def check_stanza_against_all_expected_xpaths(self): pass + def check_xpath(xpaths, stanza): for xpath in xpaths: tree = lxml.etree.parse(io.StringIO(str(stanza))) @@ -118,6 +119,7 @@ class Scenario: else: self.steps.append(elem) + class ProcessRunner: def __init__(self): self.process = None @@ -155,13 +157,14 @@ class BiboumiRunner(ProcessRunner): self.create = asyncio.create_subprocess_exec("./biboumi", "test.conf", stdin=None, stdout=self.fd, stderr=self.fd, loop=None, limit=None) + class IrcServerRunner(ProcessRunner): def __init__(self): super().__init__() - self.create = asyncio.create_subprocess_exec("mammond", "--debug", "--nofork", - "--config", "../tests/end_to_end/mammond.conf", + self.create = asyncio.create_subprocess_exec("/home/louiz/sources/charybdis/ircd/charybdis", "-foreground", stderr=asyncio.subprocess.PIPE) + def send_stanza(stanza, xmpp, biboumi): xmpp.send_raw(stanza.format_map(common_replacements)) asyncio.get_event_loop().call_soon(xmpp.run_scenario) @@ -175,6 +178,7 @@ def expect_stanza(xpaths, xmpp, biboumi): else: print("Warning, from argument type passed to expect_stanza: %s" % (type(xpaths))) + class BiboumiTest: """ Spawns a biboumi process and a fake XMPP Component that will run a @@ -330,20 +334,69 @@ if __name__ == '__main__': # Second user joins partial(send_stanza, ""), + connection_sequence("irc.localhost", '{jid_two}/{resource_one}'), + # Our presence, sent to the other user + partial(expect_stanza, + ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']",)), + # The other user presence + partial(expect_stanza, + ("/presence[@to='{jid_second}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~nick@localhost'][@role='participant']") + ), + # Our own presence + partial(expect_stanza, + ("/presence[@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']", + "/presence/muc_user:x/muc_user:status[@code='110']") + ), + partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), + ]), + Scenario("channel_custom_topic", + [ + handshake_sequence(), + # First user joins + partial(send_stanza, + ""), + connection_sequence("irc.localhost", '{jid_one}/{resource_one}'), + partial(expect_stanza, + ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~nick@localhost'][@role='participant']", + "/presence/muc_user:x/muc_user:status[@code='110']") + ), + partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), + + # First user sets the topic + partial(send_stanza, + "TOPIC\nTEST"), + partial(expect_stanza, "/message[@from='#foo%{irc_server_one}/{nick_one}'][@type='groupchat'][@to='{jid_one}/{resource_one}']/subject[text()='TOPIC\nTEST']"), + + # # Second user joins + # partial(send_stanza, + # ""), # connection_sequence("irc.localhost", '{jid_two}/{resource_one}'), + # # Our presence, sent to the other user + # partial(expect_stanza, + # ("/presence[@to='{jid_one}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']",)), + # # The other user presence + # partial(expect_stanza, + # ("/presence[@to='{jid_second}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_one}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~nick@localhost'][@role='participant']") + # ), + # # Our own presence + # partial(expect_stanza, + # ("/presence[@to='{jid_two}/{resource_one}'][@from='#foo%{irc_server_one}/{nick_two}']/muc_user:x/muc_user:item[@affiliation='none'][@jid='~bobby@localhost'][@role='participant']", + # "/presence/muc_user:x/muc_user:status[@code='110']") + # ), + # partial(expect_stanza, "/message[@from='#foo%{irc_server_one}'][@type='groupchat']/subject[not(text())]"), ]), ) failures = 0 irc = IrcServerRunner() - print("Starting mammond server…") + print("Starting irc server…") asyncio.get_event_loop().run_until_complete(irc.start()) while True: res = asyncio.get_event_loop().run_until_complete(irc.process.stderr.readline()) - if b"init finished..." in res: + if b"now running in foreground mode" in res: break - print("mammond server started.") + print("irc server started.") print("Running %s checks for biboumi." % (len(scenarios))) for scenario in scenarios: @@ -353,7 +406,7 @@ if __name__ == '__main__': (scenario.name, scenario.name)) failures += 1 - print("Waiting for mammond to exit…") + print("Waiting for irc server to exit…") irc.stop() code = asyncio.get_event_loop().run_until_complete(irc.wait()) -- cgit v1.2.3