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