logo

searx

My custom branche(s) on searx, a meta-search engine git clone https://anongit.hacktivis.me/git/searx.git/

test_github.py (1941B)


  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import github
  4. from searx.testing import SearxTestCase
  5. class TestGitHubEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. params = github.request(query, defaultdict(dict))
  9. self.assertTrue('url' in params)
  10. self.assertTrue(query in params['url'])
  11. self.assertTrue('github.com' in params['url'])
  12. self.assertEqual(params['headers']['Accept'], github.accept_header)
  13. def test_response(self):
  14. self.assertRaises(AttributeError, github.response, None)
  15. self.assertRaises(AttributeError, github.response, [])
  16. self.assertRaises(AttributeError, github.response, '')
  17. self.assertRaises(AttributeError, github.response, '[]')
  18. response = mock.Mock(text='{}')
  19. self.assertEqual(github.response(response), [])
  20. response = mock.Mock(text='{"items": []}')
  21. self.assertEqual(github.response(response), [])
  22. json = """
  23. {
  24. "items": [
  25. {
  26. "name": "title",
  27. "html_url": "url",
  28. "description": ""
  29. }
  30. ]
  31. }
  32. """
  33. response = mock.Mock(text=json)
  34. results = github.response(response)
  35. self.assertEqual(type(results), list)
  36. self.assertEqual(len(results), 1)
  37. self.assertEqual(results[0]['title'], 'title')
  38. self.assertEqual(results[0]['url'], 'url')
  39. self.assertEqual(results[0]['content'], '')
  40. json = """
  41. {
  42. "items": [
  43. {
  44. "name": "title",
  45. "html_url": "url",
  46. "description": "desc"
  47. }
  48. ]
  49. }
  50. """
  51. response = mock.Mock(text=json)
  52. results = github.response(response)
  53. self.assertEqual(results[0]['content'], "desc")