2015-01-25 21:12:34 +00:00
|
|
|
from collections import defaultdict
|
|
|
|
import mock
|
|
|
|
from searx.engines import deezer
|
|
|
|
from searx.testing import SearxTestCase
|
|
|
|
|
|
|
|
|
|
|
|
class TestDeezerEngine(SearxTestCase):
|
|
|
|
|
|
|
|
def test_request(self):
|
|
|
|
query = 'test_query'
|
|
|
|
dicto = defaultdict(dict)
|
|
|
|
dicto['pageno'] = 0
|
|
|
|
params = deezer.request(query, dicto)
|
|
|
|
self.assertTrue('url' in params)
|
|
|
|
self.assertTrue(query in params['url'])
|
|
|
|
self.assertTrue('deezer.com' in params['url'])
|
|
|
|
|
|
|
|
def test_response(self):
|
|
|
|
self.assertRaises(AttributeError, deezer.response, None)
|
|
|
|
self.assertRaises(AttributeError, deezer.response, [])
|
|
|
|
self.assertRaises(AttributeError, deezer.response, '')
|
|
|
|
self.assertRaises(AttributeError, deezer.response, '[]')
|
|
|
|
|
|
|
|
response = mock.Mock(text='{}')
|
|
|
|
self.assertEqual(deezer.response(response), [])
|
|
|
|
|
|
|
|
response = mock.Mock(text='{"data": []}')
|
|
|
|
self.assertEqual(deezer.response(response), [])
|
|
|
|
|
2016-07-11 13:29:47 +00:00
|
|
|
json = r"""
|
2015-01-25 21:12:34 +00:00
|
|
|
{"data":[
|
|
|
|
{"id":100, "title":"Title of track",
|
2015-03-03 10:44:12 +00:00
|
|
|
"link":"https:\/\/www.deezer.com\/track\/1094042","duration":232,
|
2015-01-25 21:12:34 +00:00
|
|
|
"artist":{"id":200,"name":"Artist Name",
|
2015-03-03 10:44:12 +00:00
|
|
|
"link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"},
|
2015-01-25 21:12:34 +00:00
|
|
|
"album":{"id":118106,"title":"Album Title","type":"album"},"type":"track"}
|
|
|
|
]}
|
|
|
|
"""
|
|
|
|
response = mock.Mock(text=json)
|
|
|
|
results = deezer.response(response)
|
|
|
|
self.assertEqual(type(results), list)
|
|
|
|
self.assertEqual(len(results), 1)
|
|
|
|
self.assertEqual(results[0]['title'], 'Title of track')
|
2015-03-03 10:44:12 +00:00
|
|
|
self.assertEqual(results[0]['url'], 'https://www.deezer.com/track/1094042')
|
2016-12-09 18:10:57 +00:00
|
|
|
self.assertEqual(results[0]['content'], 'Artist Name - Album Title - Title of track')
|
2015-01-25 21:33:02 +00:00
|
|
|
self.assertTrue('100' in results[0]['embedded'])
|
2015-01-25 21:12:34 +00:00
|
|
|
|
2016-07-11 13:29:47 +00:00
|
|
|
json = r"""
|
2015-01-25 21:12:34 +00:00
|
|
|
{"data":[
|
|
|
|
{"id":200,"name":"Artist Name",
|
2015-03-03 10:44:12 +00:00
|
|
|
"link":"https:\/\/www.deezer.com\/artist\/1217","type":"artist"}
|
2015-01-25 21:12:34 +00:00
|
|
|
]}
|
|
|
|
"""
|
|
|
|
response = mock.Mock(text=json)
|
|
|
|
results = deezer.response(response)
|
|
|
|
self.assertEqual(type(results), list)
|
|
|
|
self.assertEqual(len(results), 0)
|