From 22011d91a91e4379cbb4553f2b9f9e5c472d862d Mon Sep 17 00:00:00 2001 From: Neil Date: Sun, 18 Nov 2012 15:59:27 +0200 Subject: [PATCH 1/1] Add test covering sending data --- tests/testirker.py | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) diff --git a/tests/testirker.py b/tests/testirker.py index 059f6bd..5352434 100644 --- a/tests/testirker.py +++ b/tests/testirker.py @@ -3,10 +3,10 @@ # Copyright 2012 Neil Muller # GPL 2+ - see COPYING for details from unittest import TestLoader +from SocketServer import TCPServer, StreamRequestHandler +import threading -from bzrlib import ( - config, - ) +from bzrlib import config from bzrlib.bzrdir import BzrDir from bzrlib.tests import TestCaseInTempDir from bzrlib.plugins.bzrirker.irkerhook import IrkerSender @@ -17,6 +17,8 @@ def test_suite(): sample_config = ("[DEFAULT]\n" "irker_project=bzrirker\n" + "irker_server=localhost\n" + "irker_port=6677\n" "irker_channels=irc://chat.example.test/commits\n") no_project_config = ("[DEFAULT]\n" @@ -28,6 +30,13 @@ colour_config = ("[DEFAULT]\n" "irker_channels=irc://chat.example.test/commits\n") +class MyHandler(StreamRequestHandler): + + def handle(self): + data = self.rfile.read() + self.server.data = data + + class TestConfigured(TestCaseInTempDir): def test_no_colours(self): @@ -64,6 +73,18 @@ class TestConfigured(TestCaseInTempDir): '\x02bzrirker:\x0f \x0303Sample \x0f' ' work * \x021\x0f / \x02\x0f: foo bar ', irker._format()) + def test_send(self): + irker = self.get_irker() + server = self.get_server() + irker.send() + while server.data is None: + pass + server.shutdown() + self.assertEqual(server.data, + '{"to": ["irc://chat.example.test/commits"]' + ', "privmsg": "bzrirker: Sample ' + ' work * 1 / : foo bar "}\n') + def get_irker(self, text=sample_config): my_config = config.MemoryStack(text) self.branch = BzrDir.create_branch_convenience('.') @@ -78,3 +99,10 @@ class TestConfigured(TestCaseInTempDir): # We're not calling send, so do the setup stuff here irker._setup_revision_and_revno() return irker + + def get_server(self): + server = TCPServer(('localhost', 6677), MyHandler) + server.data = None + thread = threading.Thread(target=server.serve_forever) + thread.start() + return server -- 2.34.1