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