logo

searx

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

test_frinkiac.py (1614B)


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