From 931b53a974163f8c601e696e498021cb2e5fc5d4 Mon Sep 17 00:00:00 2001 From: mutantmonkey Date: Wed, 6 Jun 2012 22:23:06 -0700 Subject: [PATCH] add .head tests --- modules/test/test_head.py | 43 +++++++++++++++++++++++++++++++++++++++ modules/test/test_wuvt.py | 4 ---- 2 files changed, 43 insertions(+), 4 deletions(-) create mode 100644 modules/test/test_head.py diff --git a/modules/test/test_head.py b/modules/test/test_head.py new file mode 100644 index 0000000..e0918a5 --- /dev/null +++ b/modules/test/test_head.py @@ -0,0 +1,43 @@ +""" +test_head.py - tests for the HTTP metadata utilities module +author: mutantmonkey +""" + +import re +import unittest +from mock import MagicMock, Mock +from modules.head import head, snarfuri + +class TestHead(unittest.TestCase): + def setUp(self): + self.phenny = MagicMock() + + def test_head(self): + input = Mock(group=lambda x: 'http://vtluug.org') + head(self.phenny, input) + + out = self.phenny.reply.call_args[0][0] + m = re.match('^200, text/html, utf-8, \d{4}\-\d{2}\-\d{2} '\ + '\d{2}:\d{2}:\d{2} UTC, [0-9\.]+ s$', out, flags=re.UNICODE) + self.assertTrue(m) + + def test_header(self): + input = Mock(group=lambda x: 'http://vtluug.org Server') + head(self.phenny, input) + + self.phenny.say.assert_called_once_with("Server: nginx") + + def test_header_bad(self): + input = Mock(group=lambda x: 'http://vtluug.org truncatedcone') + head(self.phenny, input) + + self.phenny.say.assert_called_once_with("There was no truncatedcone "\ + "header in the response.") + + def test_snarfuri(self): + self.phenny.config.prefix = '.' + input = Mock(group=lambda x=0: 'http://google.com', + sender='#phenny') + snarfuri(self.phenny, input) + + self.phenny.msg.assert_called_once_with('#phenny', "[ Google ]") diff --git a/modules/test/test_wuvt.py b/modules/test/test_wuvt.py index 5271f9d..046b0c8 100644 --- a/modules/test/test_wuvt.py +++ b/modules/test/test_wuvt.py @@ -3,10 +3,6 @@ test_wuvt.py - tests for the wuvt module author: mutantmonkey """ -# add current working directory to path -import sys -sys.path.append('.') - import re import unittest from mock import MagicMock