PageRenderTime 0ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/test/test_search.py

https://github.com/apertium/phenny
Python | 45 lines | 35 code | 6 blank | 4 comment | 0 complexity | 048775fb982708dbf79340d333f13974 MD5 | raw file
 1"""
 2test_search.py - tests for the search module
 3author: mutantmonkey <mutantmonkey@mutantmonkey.in>
 4"""
 5import unittest
 6from mock import MagicMock, patch
 7from modules import search
 8from web import catch_timeout, unquote
 9
10
11class TestSearch(unittest.TestCase):
12
13    def setUp(self):
14        self.engines = {
15            'DuckDuckGo': 'https://api.duckduckgo.com',
16            'Suggestion API': 'http://suggestqueries.google.com/complete/search?output=toolbar&hl=en&q=test'
17        }
18        self.phenny = MagicMock()
19        self.input = MagicMock()
20
21    @patch('modules.search.requests.get')
22    @catch_timeout
23    def test_requests(self, mock_get):
24        mock_response = MagicMock()
25        mock_response.json.return_value = {
26            "AbstractText" : "TestText",
27            "AbstractURL" : "https://testurl.com"
28        }
29        mock_get.return_value = mock_response
30        self.input.group.return_value = 'test'
31        search.search(self.phenny, self.input)
32        self.phenny.say.assert_called_with('TestText - https://testurl.com')
33
34    @catch_timeout
35    def test_search(self):
36        self.input.group.return_value = 'Apertium'
37        search.search(self.phenny, self.input)
38        self.assertTrue(self.phenny.say.called)
39
40    @patch('modules.search.more')
41    @catch_timeout
42    def test_suggest(self, mock_more):
43        self.input.group.return_value = 'test'
44        search.suggest(self.phenny, self.input)
45        self.assertTrue(mock_more.add_messages.called)