logo

searx

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

test_deezer.py (2199B)


  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import deezer
  4. from searx.testing import SearxTestCase
  5. class TestDeezerEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dicto = defaultdict(dict)
  9. dicto['pageno'] = 0
  10. params = deezer.request(query, dicto)
  11. self.assertTrue('url' in params)
  12. self.assertTrue(query in params['url'])
  13. self.assertTrue('deezer.com' in params['url'])
  14. def test_response(self):
  15. self.assertRaises(AttributeError, deezer.response, None)
  16. self.assertRaises(AttributeError, deezer.response, [])
  17. self.assertRaises(AttributeError, deezer.response, '')
  18. self.assertRaises(AttributeError, deezer.response, '[]')
  19. response = mock.Mock(text='{}')
  20. self.assertEqual(deezer.response(response), [])
  21. response = mock.Mock(text='{"data": []}')
  22. self.assertEqual(deezer.response(response), [])
  23. json = r"""
  24. {"data":[
  25. {"id":100, "title":"Title of track",
  26. "link":"https:\/\/www.deezer.com\/track\/1094042","duration":232,
  27. "artist":{"id":200,"name":"Artist Name",
  28. "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"},
  29. "album":{"id":118106,"title":"Album Title","type":"album"},"type":"track"}
  30. ]}
  31. """
  32. response = mock.Mock(text=json)
  33. results = deezer.response(response)
  34. self.assertEqual(type(results), list)
  35. self.assertEqual(len(results), 1)
  36. self.assertEqual(results[0]['title'], 'Title of track')
  37. self.assertEqual(results[0]['url'], 'https://www.deezer.com/track/1094042')
  38. self.assertEqual(results[0]['content'], 'Artist Name - Album Title - Title of track')
  39. self.assertTrue('100' in results[0]['embedded'])
  40. json = r"""
  41. {"data":[
  42. {"id":200,"name":"Artist Name",
  43. "link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"}
  44. ]}
  45. """
  46. response = mock.Mock(text=json)
  47. results = deezer.response(response)
  48. self.assertEqual(type(results), list)
  49. self.assertEqual(len(results), 0)