|
@@ -0,0 +1,192 @@
|
|
1
|
+from collections import defaultdict
|
|
2
|
+import mock
|
|
3
|
+from searx.engines import soundcloud
|
|
4
|
+from searx.testing import SearxTestCase
|
|
5
|
+from urllib import quote_plus
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+class TestSoundcloudEngine(SearxTestCase):
|
|
9
|
+
|
|
10
|
+ def test_request(self):
|
|
11
|
+ query = 'test_query'
|
|
12
|
+ dicto = defaultdict(dict)
|
|
13
|
+ dicto['pageno'] = 1
|
|
14
|
+ params = soundcloud.request(query, dicto)
|
|
15
|
+ self.assertIn('url', params)
|
|
16
|
+ self.assertIn(query, params['url'])
|
|
17
|
+ self.assertIn('soundcloud.com', params['url'])
|
|
18
|
+
|
|
19
|
+ def test_response(self):
|
|
20
|
+ self.assertRaises(AttributeError, soundcloud.response, None)
|
|
21
|
+ self.assertRaises(AttributeError, soundcloud.response, [])
|
|
22
|
+ self.assertRaises(AttributeError, soundcloud.response, '')
|
|
23
|
+ self.assertRaises(AttributeError, soundcloud.response, '[]')
|
|
24
|
+
|
|
25
|
+ response = mock.Mock(text='{}')
|
|
26
|
+ self.assertEqual(soundcloud.response(response), [])
|
|
27
|
+
|
|
28
|
+ response = mock.Mock(text='{"data": []}')
|
|
29
|
+ self.assertEqual(soundcloud.response(response), [])
|
|
30
|
+
|
|
31
|
+ json = """
|
|
32
|
+ {
|
|
33
|
+ "collection": [
|
|
34
|
+ {
|
|
35
|
+ "kind": "track",
|
|
36
|
+ "id": 159723640,
|
|
37
|
+ "created_at": "2014/07/22 00:51:21 +0000",
|
|
38
|
+ "user_id": 2976616,
|
|
39
|
+ "duration": 303780,
|
|
40
|
+ "commentable": true,
|
|
41
|
+ "state": "finished",
|
|
42
|
+ "original_content_size": 13236349,
|
|
43
|
+ "last_modified": "2015/01/31 15:14:50 +0000",
|
|
44
|
+ "sharing": "public",
|
|
45
|
+ "tag_list": "seekae flume",
|
|
46
|
+ "permalink": "seekae-test-recognise-flume-re-work",
|
|
47
|
+ "streamable": true,
|
|
48
|
+ "embeddable_by": "all",
|
|
49
|
+ "downloadable": true,
|
|
50
|
+ "purchase_url": "http://www.facebook.com/seekaemusic",
|
|
51
|
+ "label_id": null,
|
|
52
|
+ "purchase_title": "Seekae",
|
|
53
|
+ "genre": "freedownload",
|
|
54
|
+ "title": "This is the title",
|
|
55
|
+ "description": "This is the content",
|
|
56
|
+ "label_name": "Future Classic",
|
|
57
|
+ "release": "",
|
|
58
|
+ "track_type": "remix",
|
|
59
|
+ "key_signature": "",
|
|
60
|
+ "isrc": "",
|
|
61
|
+ "video_url": null,
|
|
62
|
+ "bpm": null,
|
|
63
|
+ "release_year": 2014,
|
|
64
|
+ "release_month": 7,
|
|
65
|
+ "release_day": 22,
|
|
66
|
+ "original_format": "mp3",
|
|
67
|
+ "license": "all-rights-reserved",
|
|
68
|
+ "uri": "https://api.soundcloud.com/tracks/159723640",
|
|
69
|
+ "user": {
|
|
70
|
+ "id": 2976616,
|
|
71
|
+ "kind": "user",
|
|
72
|
+ "permalink": "flume",
|
|
73
|
+ "username": "Flume",
|
|
74
|
+ "last_modified": "2014/11/24 19:21:29 +0000",
|
|
75
|
+ "uri": "https://api.soundcloud.com/users/2976616",
|
|
76
|
+ "permalink_url": "http://soundcloud.com/flume",
|
|
77
|
+ "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg"
|
|
78
|
+ },
|
|
79
|
+ "permalink_url": "http://soundcloud.com/this.is.the.url",
|
|
80
|
+ "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg",
|
|
81
|
+ "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png",
|
|
82
|
+ "stream_url": "https://api.soundcloud.com/tracks/159723640/stream",
|
|
83
|
+ "download_url": "https://api.soundcloud.com/tracks/159723640/download",
|
|
84
|
+ "playback_count": 2190687,
|
|
85
|
+ "download_count": 54856,
|
|
86
|
+ "favoritings_count": 49061,
|
|
87
|
+ "comment_count": 826,
|
|
88
|
+ "likes_count": 49061,
|
|
89
|
+ "reposts_count": 15910,
|
|
90
|
+ "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments",
|
|
91
|
+ "policy": "ALLOW"
|
|
92
|
+ }
|
|
93
|
+ ],
|
|
94
|
+ "total_results": 375750,
|
|
95
|
+ "next_href": "https://api.soundcloud.com/search?&q=test",
|
|
96
|
+ "tx_id": ""
|
|
97
|
+ }
|
|
98
|
+ """
|
|
99
|
+ response = mock.Mock(text=json)
|
|
100
|
+ results = soundcloud.response(response)
|
|
101
|
+ self.assertEqual(type(results), list)
|
|
102
|
+ self.assertEqual(len(results), 1)
|
|
103
|
+ self.assertEqual(results[0]['title'], 'This is the title')
|
|
104
|
+ self.assertEqual(results[0]['url'], 'http://soundcloud.com/this.is.the.url')
|
|
105
|
+ self.assertEqual(results[0]['content'], 'This is the content')
|
|
106
|
+ self.assertIn(quote_plus('https://api.soundcloud.com/tracks/159723640'), results[0]['embedded'])
|
|
107
|
+
|
|
108
|
+ json = """
|
|
109
|
+ {
|
|
110
|
+ "collection": [
|
|
111
|
+ {
|
|
112
|
+ "kind": "user",
|
|
113
|
+ "id": 159723640,
|
|
114
|
+ "created_at": "2014/07/22 00:51:21 +0000",
|
|
115
|
+ "user_id": 2976616,
|
|
116
|
+ "duration": 303780,
|
|
117
|
+ "commentable": true,
|
|
118
|
+ "state": "finished",
|
|
119
|
+ "original_content_size": 13236349,
|
|
120
|
+ "last_modified": "2015/01/31 15:14:50 +0000",
|
|
121
|
+ "sharing": "public",
|
|
122
|
+ "tag_list": "seekae flume",
|
|
123
|
+ "permalink": "seekae-test-recognise-flume-re-work",
|
|
124
|
+ "streamable": true,
|
|
125
|
+ "embeddable_by": "all",
|
|
126
|
+ "downloadable": true,
|
|
127
|
+ "purchase_url": "http://www.facebook.com/seekaemusic",
|
|
128
|
+ "label_id": null,
|
|
129
|
+ "purchase_title": "Seekae",
|
|
130
|
+ "genre": "freedownload",
|
|
131
|
+ "title": "This is the title",
|
|
132
|
+ "description": "This is the content",
|
|
133
|
+ "label_name": "Future Classic",
|
|
134
|
+ "release": "",
|
|
135
|
+ "track_type": "remix",
|
|
136
|
+ "key_signature": "",
|
|
137
|
+ "isrc": "",
|
|
138
|
+ "video_url": null,
|
|
139
|
+ "bpm": null,
|
|
140
|
+ "release_year": 2014,
|
|
141
|
+ "release_month": 7,
|
|
142
|
+ "release_day": 22,
|
|
143
|
+ "original_format": "mp3",
|
|
144
|
+ "license": "all-rights-reserved",
|
|
145
|
+ "uri": "https://api.soundcloud.com/tracks/159723640",
|
|
146
|
+ "user": {
|
|
147
|
+ "id": 2976616,
|
|
148
|
+ "kind": "user",
|
|
149
|
+ "permalink": "flume",
|
|
150
|
+ "username": "Flume",
|
|
151
|
+ "last_modified": "2014/11/24 19:21:29 +0000",
|
|
152
|
+ "uri": "https://api.soundcloud.com/users/2976616",
|
|
153
|
+ "permalink_url": "http://soundcloud.com/flume",
|
|
154
|
+ "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg"
|
|
155
|
+ },
|
|
156
|
+ "permalink_url": "http://soundcloud.com/this.is.the.url",
|
|
157
|
+ "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg",
|
|
158
|
+ "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png",
|
|
159
|
+ "stream_url": "https://api.soundcloud.com/tracks/159723640/stream",
|
|
160
|
+ "download_url": "https://api.soundcloud.com/tracks/159723640/download",
|
|
161
|
+ "playback_count": 2190687,
|
|
162
|
+ "download_count": 54856,
|
|
163
|
+ "favoritings_count": 49061,
|
|
164
|
+ "comment_count": 826,
|
|
165
|
+ "likes_count": 49061,
|
|
166
|
+ "reposts_count": 15910,
|
|
167
|
+ "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments",
|
|
168
|
+ "policy": "ALLOW"
|
|
169
|
+ }
|
|
170
|
+ ],
|
|
171
|
+ "total_results": 375750,
|
|
172
|
+ "next_href": "https://api.soundcloud.com/search?&q=test",
|
|
173
|
+ "tx_id": ""
|
|
174
|
+ }
|
|
175
|
+ """
|
|
176
|
+ response = mock.Mock(text=json)
|
|
177
|
+ results = soundcloud.response(response)
|
|
178
|
+ self.assertEqual(type(results), list)
|
|
179
|
+ self.assertEqual(len(results), 0)
|
|
180
|
+
|
|
181
|
+ json = """
|
|
182
|
+ {
|
|
183
|
+ "collection": [],
|
|
184
|
+ "total_results": 375750,
|
|
185
|
+ "next_href": "https://api.soundcloud.com/search?&q=test",
|
|
186
|
+ "tx_id": ""
|
|
187
|
+ }
|
|
188
|
+ """
|
|
189
|
+ response = mock.Mock(text=json)
|
|
190
|
+ results = soundcloud.response(response)
|
|
191
|
+ self.assertEqual(type(results), list)
|
|
192
|
+ self.assertEqual(len(results), 0)
|