Bläddra i källkod

Mixcloud's unit test

Cqoicebordel 10 år sedan
förälder
incheckning
192f255e13

+ 1
- 0
searx/tests/engines/test_deezer.py Visa fil

@@ -43,6 +43,7 @@ class TestDeezerEngine(SearxTestCase):
43 43
         self.assertEqual(results[0]['title'], 'Title of track')
44 44
         self.assertEqual(results[0]['url'], 'http://www.deezer.com/track/1094042')
45 45
         self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track')
46
+        self.assertTrue('100' in results[0]['embedded'])
46 47
 
47 48
         json = """
48 49
         {"data":[

+ 67
- 0
searx/tests/engines/test_mixcloud.py Visa fil

@@ -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)

+ 1
- 0
searx/tests/test_engines.py Visa fil

@@ -2,3 +2,4 @@ from searx.tests.engines.test_bing import *  # noqa
2 2
 from searx.tests.engines.test_deezer import *  # noqa
3 3
 from searx.tests.engines.test_dummy import *  # noqa
4 4
 from searx.tests.engines.test_github import *  # noqa
5
+from searx.tests.engines.test_mixcloud import *  # noqa