From 31afd9cae56130cc835ce433314bfce68ebe9a40 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Wed, 30 May 2012 22:30:19 -0700 Subject: [PATCH] add some basic but incomplete bot.py tests --- tests/test_bot.py | 82 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 tests/test_bot.py diff --git a/tests/test_bot.py b/tests/test_bot.py new file mode 100644 index 0000000..b12a95d --- /dev/null +++ b/tests/test_bot.py @@ -0,0 +1,82 @@ +""" +Tests for phenny's bot.py +""" + +# add current working directory to path +import sys +sys.path.append('.') + +import unittest +from mock import call, patch, Mock + +import bot + + +class BotTest(unittest.TestCase): + @patch('bot.Phenny.setup') + def setUp(self, mock_setup): + class MockConfig(object): + nick = 'phenny' + password = 'nickserv_pass' + name = 'Phenny' + host = 'irc.example.com' + port = 6667 + ssl = False + ipv6 = True + channels = ['#phenny'] + owner = 'phenny_owner' + admins = [owner, 'phenny_admin'] + prefix = '.' + + self.bot = bot.Phenny(MockConfig) + + def test_input(self): + class MockOrigin(object): + nick = 'sock_puppet' + sender = '#phenny' + + origin = MockOrigin() + text = "Are you ready for phenny?" + match = Mock() + event = "PRIVMSG" + args = ('#phenny', ) + cmdinput = self.bot.input(origin, text, text, match, event, args) + + self.assertEqual(cmdinput.sender, origin.sender) + self.assertEqual(cmdinput.nick, origin.nick) + self.assertEqual(cmdinput.event, event) + self.assertEqual(cmdinput.bytes, text) + self.assertEqual(cmdinput.match, match) + self.assertEqual(cmdinput.group, match.group) + self.assertEqual(cmdinput.groups, match.groups) + self.assertEqual(cmdinput.args, args) + self.assertEqual(cmdinput.admin, False) + self.assertEqual(cmdinput.owner, False) + + def test_owner(self): + class MockOrigin(object): + nick = 'phenny_owner' + sender = '#phenny' + + origin = MockOrigin() + text = "Are you ready for phenny?" + match = Mock() + event = "PRIVMSG" + args = ('#phenny', ) + cmdinput = self.bot.input(origin, text, text, match, event, args) + + self.assertEqual(cmdinput.owner, True) + + def test_admin(self): + class MockOrigin(object): + nick = 'phenny_admin' + sender = '#phenny' + + origin = MockOrigin() + text = "Are you ready for phenny?" + match = Mock() + event = "PRIVMSG" + args = ('#phenny', ) + cmdinput = self.bot.input(origin, text, text, match, event, args) + + self.assertEqual(cmdinput.admin, True)