logo

searx

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

test_mixcloud.py (2431B)


  1. from collections import defaultdict
  2. import mock
  3. from searx.engines import mixcloud
  4. from searx.testing import SearxTestCase
  5. class TestMixcloudEngine(SearxTestCase):
  6. def test_request(self):
  7. query = 'test_query'
  8. dicto = defaultdict(dict)
  9. dicto['pageno'] = 0
  10. params = mixcloud.request(query, dicto)
  11. self.assertTrue('url' in params)
  12. self.assertTrue(query in params['url'])
  13. self.assertTrue('mixcloud.com' in params['url'])
  14. def test_response(self):
  15. self.assertRaises(AttributeError, mixcloud.response, None)
  16. self.assertRaises(AttributeError, mixcloud.response, [])
  17. self.assertRaises(AttributeError, mixcloud.response, '')
  18. self.assertRaises(AttributeError, mixcloud.response, '[]')
  19. response = mock.Mock(text='{}')
  20. self.assertEqual(mixcloud.response(response), [])
  21. response = mock.Mock(text='{"data": []}')
  22. self.assertEqual(mixcloud.response(response), [])
  23. json = """
  24. {"data":[
  25. {
  26. "user": {
  27. "url": "http://www.mixcloud.com/user/",
  28. "username": "user",
  29. "name": "User",
  30. "key": "/user/"
  31. },
  32. "key": "/user/this-is-the-url/",
  33. "created_time": "2014-11-14T13:30:02Z",
  34. "audio_length": 3728,
  35. "slug": "this-is-the-url",
  36. "name": "Title of track",
  37. "url": "http://www.mixcloud.com/user/this-is-the-url/",
  38. "updated_time": "2014-11-14T13:14:10Z"
  39. }
  40. ]}
  41. """
  42. response = mock.Mock(text=json)
  43. results = mixcloud.response(response)
  44. self.assertEqual(type(results), list)
  45. self.assertEqual(len(results), 1)
  46. self.assertEqual(results[0]['title'], 'Title of track')
  47. self.assertEqual(results[0]['url'], 'http://www.mixcloud.com/user/this-is-the-url/')
  48. self.assertEqual(results[0]['content'], 'User')
  49. self.assertTrue('http://www.mixcloud.com/user/this-is-the-url/' in results[0]['embedded'])
  50. json = r"""
  51. {"toto":[
  52. {"id":200,"name":"Artist Name",
  53. "link":"http:\/\/www.mixcloud.com\/artist\/1217","type":"artist"}
  54. ]}
  55. """
  56. response = mock.Mock(text=json)
  57. results = mixcloud.response(response)
  58. self.assertEqual(type(results), list)
  59. self.assertEqual(len(results), 0)