test_frinkiac.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # -*- coding: utf-8 -*-
  2. from collections import defaultdict
  3. import mock
  4. from json import dumps
  5. from searx.engines import frinkiac
  6. from searx.testing import SearxTestCase
  7. class TestFrinkiacEngine(SearxTestCase):
  8. def test_request(self):
  9. query = 'test_query'
  10. request_dict = defaultdict(dict)
  11. params = frinkiac.request(query, request_dict)
  12. self.assertTrue('url' in params)
  13. def test_response(self):
  14. self.assertRaises(AttributeError, frinkiac.response, None)
  15. self.assertRaises(AttributeError, frinkiac.response, [])
  16. self.assertRaises(AttributeError, frinkiac.response, '')
  17. self.assertRaises(AttributeError, frinkiac.response, '[]')
  18. text = """
  19. [{"Id":770931,
  20. "Episode":"S06E18",
  21. "Timestamp":534616,
  22. "Filename":""},
  23. {"Id":1657080,
  24. "Episode":"S12E14",
  25. "Timestamp":910868,
  26. "Filename":""},
  27. {"Id":1943753,
  28. "Episode":"S14E21",
  29. "Timestamp":773439,
  30. "Filename":""},
  31. {"Id":107835,
  32. "Episode":"S02E03",
  33. "Timestamp":531709,
  34. "Filename":""}]
  35. """
  36. response = mock.Mock(text=text)
  37. results = frinkiac.response(response)
  38. self.assertEqual(type(results), list)
  39. self.assertEqual(len(results), 4)
  40. self.assertEqual(results[0]['title'], u'S06E18')
  41. self.assertEqual(results[0]['url'], 'https://frinkiac.com/?p=caption&e=S06E18&t=534616')
  42. self.assertEqual(results[0]['thumbnail_src'], 'https://frinkiac.com/img/S06E18/534616/medium.jpg')
  43. self.assertEqual(results[0]['img_src'], 'https://frinkiac.com/img/S06E18/534616.jpg')