From 38a69dc35aacd60125b398b6a85ee7273db02797 Mon Sep 17 00:00:00 2001 From: Joachim Filip Ignacy Bartosik Date: Tue, 14 Jun 2011 20:14:03 +0200 Subject: Reminder plugin more testable + tests for it --- bot/Reminder/plugin.py | 6 ++---- bot/Reminder/run_test.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) create mode 100644 bot/Reminder/run_test.py diff --git a/bot/Reminder/plugin.py b/bot/Reminder/plugin.py index b7005a0..3b04ad3 100644 --- a/bot/Reminder/plugin.py +++ b/bot/Reminder/plugin.py @@ -41,11 +41,11 @@ import json import supybot.ircmsgs as ircmsgs class Reminder(callbacks.Plugin): - def __init__(self, irc): + def __init__(self, irc, sleep = 10): self.__parent = super(Reminder, self) self.__parent.__init__(irc) self.irc = irc - self.sleep = 10 + self.sleep = sleep self.source_url = 'http://localhost:3000/agendas/reminders' self.last_remind_time = time.gmtime(0) self.data = {} @@ -102,9 +102,7 @@ class Reminder(callbacks.Plugin): msg = self.data['message'] - print msg for nick in self.data['users']: - print nick self.irc.sendMsg(ircmsgs.privmsg(str(nick), str(msg))) Class = Reminder diff --git a/bot/Reminder/run_test.py b/bot/Reminder/run_test.py new file mode 100644 index 0000000..73bc394 --- /dev/null +++ b/bot/Reminder/run_test.py @@ -0,0 +1,28 @@ +import unittest +from plugin import Reminder +import urllib +import time + +class FakeIrc: + msgs = [] + + def sendMsg(self, msg): + self.msgs.append(msg) + +def do_nothing(): + pass +class TestSequenceFunctions(unittest.TestCase): + def test_ping_with_newer_stamp(self): + logger = FakeIrc() + testee = Reminder(logger, sleep = 0) + testee.get_data = do_nothing + testee.data = {"users":["nick1","nick2"],"remind_time":u"Wed Jun 08 20:15:04 2011","message":u"Test message"} + time.sleep(1) + assert(len(logger.msgs) == 2) + for i in range(2): + assert(logger.msgs[i].command == 'PRIVMSG') + assert(logger.msgs[i].args[0] == 'nick' + str(i+1)) + assert(logger.msgs[i].args[1] == u"Test message") + +if __name__ == '__main__': + unittest.main() -- cgit v1.2.3-18-g5258