From e94ca0d74a76bc1f49266597cbab7160c45fc75d Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Tue, 21 May 2013 13:34:49 -0400 Subject: [PATCH] add unit tests for remind module --- modules/remind.py | 1 + modules/test/test_remind.py | 49 +++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 modules/test/test_remind.py diff --git a/modules/remind.py b/modules/remind.py index 1067461..7363a89 100644 --- a/modules/remind.py +++ b/modules/remind.py @@ -56,6 +56,7 @@ def setup(phenny): targs = (phenny,) t = threading.Thread(target=monitor, args=targs) + t.daemon = True t.start() scaling = { diff --git a/modules/test/test_remind.py b/modules/test/test_remind.py new file mode 100644 index 0000000..dca7e6c --- /dev/null +++ b/modules/test/test_remind.py @@ -0,0 +1,49 @@ +""" +test_remind.py - tests for the remind module +author: mutantmonkey +""" + +import re +import unittest +import threading +import time +import tools +from mock import MagicMock, Mock, patch +from modules import remind + + +class TestRemind(unittest.TestCase): + def setUp(self): + self.phenny = MagicMock() + self.phenny.nick = 'phenny' + self.phenny.config.host = 'test-phenny.example.com' + + remind.load_database = lambda name: {} + remind.dump_database = lambda name, data: name + remind.setup(self.phenny) + + def test_remind(self): + secs = 5 + input = Mock(sender='#testsworth', nick='Testsworth', + bytes='.in {0} seconds TEST REMIND'.format(secs)) + + remind.remind(self.phenny, input) + self.phenny.reply.assert_called_once_with("Okay, will remind in {0}"\ + " secs".format(secs)) + + time.sleep(secs + 1) + self.phenny.msg.assert_called_once_with(input.sender, + input.nick + ': TEST REMIND') + + def test_remind_nomsg(self): + secs = 5 + input = Mock(sender='#testsworth', nick='Testsworth', + bytes='.in {0} seconds'.format(secs)) + + remind.remind(self.phenny, input) + self.phenny.reply.assert_called_once_with("Okay, will remind in {0}"\ + " secs".format(secs)) + + time.sleep(secs + 1) + self.phenny.msg.assert_called_once_with(input.sender, + input.nick + '!')