2012-06-07 01:23:06 -04:00
|
|
|
"""
|
|
|
|
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):
|
2016-03-06 17:55:50 -05:00
|
|
|
input = Mock(group=lambda x: 'https://vtluug.org')
|
2012-06-07 01:23:06 -04:00
|
|
|
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} '\
|
2017-02-11 01:21:04 -05:00
|
|
|
'\d{2}:\d{2}:\d{2} UTC, [0-9]+ bytes, [0-9]+.[0-9]+ s$', out, flags=re.UNICODE)
|
2012-06-07 01:23:06 -04:00
|
|
|
self.assertTrue(m)
|
|
|
|
|
2013-07-21 01:25:45 -04:00
|
|
|
def test_head_404(self):
|
2016-03-06 17:40:11 -05:00
|
|
|
input = Mock(group=lambda x: 'https://vtluug.org/trigger_404')
|
2013-07-21 01:25:45 -04:00
|
|
|
head(self.phenny, input)
|
|
|
|
|
|
|
|
out = self.phenny.say.call_args[0][0]
|
|
|
|
self.assertEqual(out, '404')
|
|
|
|
|
2012-06-07 01:23:06 -04:00
|
|
|
def test_header(self):
|
2016-03-06 17:40:11 -05:00
|
|
|
input = Mock(group=lambda x: 'https://vtluug.org Server')
|
2012-06-07 01:23:06 -04:00
|
|
|
head(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.say.assert_called_once_with("Server: nginx")
|
|
|
|
|
|
|
|
def test_header_bad(self):
|
2016-03-06 17:40:11 -05:00
|
|
|
input = Mock(group=lambda x: 'https://vtluug.org truncatedcone')
|
2012-06-07 01:23:06 -04:00
|
|
|
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 = '.'
|
2012-12-05 15:17:25 -05:00
|
|
|
self.phenny.config.linx_api_key = ""
|
2016-03-06 17:40:11 -05:00
|
|
|
input = Mock(group=lambda x=0: 'https://www.google.com',
|
2012-06-07 01:23:06 -04:00
|
|
|
sender='#phenny')
|
|
|
|
snarfuri(self.phenny, input)
|
|
|
|
|
|
|
|
self.phenny.msg.assert_called_once_with('#phenny', "[ Google ]")
|
2013-11-29 02:28:11 -05:00
|
|
|
|
|
|
|
def test_snarfuri_405(self):
|
|
|
|
self.phenny.config.prefix = '.'
|
|
|
|
self.phenny.config.linx_api_key = ""
|
|
|
|
input = Mock(group=lambda x=0: 'http://ozuma.sakura.ne.jp/httpstatus/405',
|
|
|
|
sender='#phenny')
|
|
|
|
snarfuri(self.phenny, input)
|
|
|
|
|
|
|
|
self.assertEqual(self.phenny.msg.called, False)
|