phenny-1/modules/test/test_hs.py

56 lines
1.6 KiB
Python
Raw Normal View History

2012-06-01 01:44:03 -04:00
"""
test_hs.py - tests for the hokie stalker module
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
import re
import unittest
from mock import MagicMock, Mock
from modules.hs import search, hs
2012-06-01 01:44:03 -04:00
class TestHs(unittest.TestCase):
def setUp(self):
self.phenny = MagicMock()
def test_search(self):
data = search('john')
assert len(data) >= 1
2013-08-25 17:32:42 -04:00
self.assertIn('uid', data[0])
self.assertIn('cn', data[0])
2012-06-01 01:44:03 -04:00
def test_single(self):
input = Mock(group=lambda x: 'marchany')
hs(self.phenny, input)
2013-08-25 17:32:42 -04:00
pattern = re.compile(
2012-06-01 01:44:03 -04:00
'^.* - http://search\.vt\.edu/search/person\.html\?person=\d+$',
2013-08-25 17:32:42 -04:00
flags=re.UNICODE)
out = self.phenny.reply.call_args[0][0]
self.assertRegex(out, pattern)
2012-06-01 01:44:03 -04:00
def test_multi(self):
input = Mock(group=lambda x: 'john')
hs(self.phenny, input)
2013-08-25 17:32:42 -04:00
pattern = re.compile(
2012-06-01 01:44:03 -04:00
'^Multiple results found; try http://search\.vt\.edu/search/people\.html\?q=.*$',
2013-08-25 17:32:42 -04:00
flags=re.UNICODE)
out = self.phenny.reply.call_args[0][0]
self.assertRegex(out, pattern)
def test_2char(self):
input = Mock(group=lambda x: 'hs')
hs(self.phenny, input)
out = self.phenny.reply.call_args[0][0]
self.phenny.reply.assert_called_once_with("No results found")
2013-08-25 17:32:42 -04:00
def test_none(self):
input = Mock(group=lambda x: 'THIS_IS_NOT_A_REAL_SEARCH_QUERY')
hs(self.phenny, input)
out = self.phenny.reply.call_args[0][0]
self.phenny.reply.assert_called_once_with("No results found")