add .head tests

master
mutantmonkey 2012-06-06 22:23:06 -07:00
parent 2dbc8797e5
commit 931b53a974
2 changed files with 43 additions and 4 deletions

43
modules/test/test_head.py Normal file
View File

@ -0,0 +1,43 @@
"""
test_head.py - tests for the HTTP metadata utilities module
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
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 ]")

View File

@ -3,10 +3,6 @@ test_wuvt.py - tests for the wuvt module
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
# add current working directory to path
import sys
sys.path.append('.')
import re
import unittest
from mock import MagicMock