phenny-1/modules/test/test_search.py

78 lines
2.0 KiB
Python
Raw Permalink Normal View History

2012-06-02 05:38:22 -04:00
"""
test_search.py - tests for the search module
author: mutantmonkey <mutantmonkey@mutantmonkey.in>
"""
import re
import unittest
from mock import MagicMock, Mock
2017-02-11 01:21:04 -05:00
from modules.search import duck_api, google_search, google_count, \
2012-06-02 05:38:22 -04:00
formatnumber, g, gc, gcs, bing_search, bing, duck_search, duck, \
2017-04-10 02:15:25 -04:00
search
2012-06-02 05:38:22 -04:00
class TestSearch(unittest.TestCase):
def setUp(self):
self.phenny = MagicMock()
def test_google_search(self):
out = google_search('phenny')
m = re.match('^https?://.*$', out, flags=re.UNICODE)
self.assertTrue(m)
def test_g(self):
input = Mock(group=lambda x: 'swhack')
g(self.phenny, input)
2017-02-11 01:21:04 -05:00
assert self.phenny.reply.called is True
2012-06-02 05:38:22 -04:00
def test_gc(self):
query = 'extrapolate'
input = Mock(group=lambda x: query)
gc(self.phenny, input)
out = self.phenny.say.call_args[0][0]
m = re.match('^{0}: [0-9,\.]+$'.format(query), out, flags=re.UNICODE)
self.assertTrue(m)
def test_gcs(self):
input = Mock(group=lambda x: 'vtluug virginia phenny')
gcs(self.phenny, input)
assert self.phenny.say.called is True
2012-06-02 05:38:22 -04:00
def test_bing_search(self):
out = bing_search('phenny')
m = re.match('^https?://.*$', out, flags=re.UNICODE)
self.assertTrue(m)
def test_bing(self):
input = Mock(group=lambda x: 'swhack')
bing(self.phenny, input)
assert self.phenny.reply.called is True
2012-06-02 05:38:22 -04:00
def test_duck_search(self):
out = duck_search('phenny')
m = re.match('^https?://.*$', out, flags=re.UNICODE)
self.assertTrue(m)
def test_duck(self):
input = Mock(group=lambda x: 'swhack')
duck(self.phenny, input)
assert self.phenny.reply.called is True
2012-06-02 05:38:22 -04:00
2017-02-11 01:21:04 -05:00
def test_duck_api(self):
input = Mock(group=lambda x: 'swhack')
duck(self.phenny, input)
2012-06-02 05:38:22 -04:00
def test_search(self):
input = Mock(group=lambda x: 'vtluug')
duck(self.phenny, input)
assert self.phenny.reply.called is True