add unit tests for remind module

master
mutantmonkey 2013-05-21 13:34:49 -04:00
parent 065fa5949e
commit e94ca0d74a
2 changed files with 50 additions and 0 deletions

View File

@ -56,6 +56,7 @@ def setup(phenny):
targs = (phenny,)
t = threading.Thread(target=monitor, args=targs)
t.daemon = True
t.start()
scaling = {

View File

@ -0,0 +1,49 @@
"""
test_remind.py - tests for the remind module
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
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 + '!')