From 34f3f8a9c4409f623abe5759ae0acd428c2aea29 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Fri, 1 Jun 2012 00:09:44 -0700 Subject: [PATCH] add urban dictionary test --- modules/test/test_urbandict.py | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 modules/test/test_urbandict.py diff --git a/modules/test/test_urbandict.py b/modules/test/test_urbandict.py new file mode 100644 index 0000000..28bd592 --- /dev/null +++ b/modules/test/test_urbandict.py @@ -0,0 +1,36 @@ +""" +test_urbandict.py - tests for the urban dictionary module +author: mutantmonkey +""" + +# add current working directory to path +import sys +sys.path.append('.') + +import re +import unittest +from mock import MagicMock, Mock +from modules.urbandict import urbandict + +class TestUrbandict(unittest.TestCase): + def setUp(self): + self.phenny = MagicMock() + + def test_result(self): + word = 'slemp' + input = Mock(group=lambda x: word) + urbandict(self.phenny, input) + + out = self.phenny.say.call_args[0][0] + m = re.match('^.* - '\ + 'http://www\.urbandictionary\.com/define\.php\?term=.*$', out, + flags=re.UNICODE) + self.assertTrue(m) + + def test_none(self): + word = '__no_word_here__' + input = Mock(group=lambda x: word) + urbandict(self.phenny, input) + + self.phenny.say.assert_called_once_with('No results found for '\ + '{0}'.format(word))