Browse Source

Searchcode doc's test unit

Cqoicebordel 10 years ago
parent
commit
0f81aa8410
2 changed files with 74 additions and 0 deletions
  1. 73
    0
      searx/tests/engines/test_searchcode_doc.py
  2. 1
    0
      searx/tests/test_engines.py

+ 73
- 0
searx/tests/engines/test_searchcode_doc.py View File

@@ -0,0 +1,73 @@
1
+from collections import defaultdict
2
+import mock
3
+from searx.engines import searchcode_doc
4
+from searx.testing import SearxTestCase
5
+
6
+
7
+class TestSearchcodeDocEngine(SearxTestCase):
8
+
9
+    def test_request(self):
10
+        query = 'test_query'
11
+        dicto = defaultdict(dict)
12
+        dicto['pageno'] = 0
13
+        params = searchcode_doc.request(query, dicto)
14
+        self.assertIn('url', params)
15
+        self.assertIn(query, params['url'])
16
+        self.assertIn('searchcode.com', params['url'])
17
+
18
+    def test_response(self):
19
+        self.assertRaises(AttributeError, searchcode_doc.response, None)
20
+        self.assertRaises(AttributeError, searchcode_doc.response, [])
21
+        self.assertRaises(AttributeError, searchcode_doc.response, '')
22
+        self.assertRaises(AttributeError, searchcode_doc.response, '[]')
23
+
24
+        response = mock.Mock(text='{}')
25
+        self.assertEqual(searchcode_doc.response(response), [])
26
+
27
+        response = mock.Mock(text='{"data": []}')
28
+        self.assertEqual(searchcode_doc.response(response), [])
29
+
30
+        json = """
31
+        {
32
+        "matchterm": "test",
33
+        "previouspage": null,
34
+        "searchterm": "test",
35
+        "query": "test",
36
+        "total": 60,
37
+        "page": 0,
38
+        "nextpage": 1,
39
+        "results": [
40
+            {
41
+            "synopsis": "Synopsis",
42
+            "displayname": null,
43
+            "name": "test",
44
+            "url": "http://url",
45
+            "type": "Type",
46
+            "icon": null,
47
+            "namespace": "Namespace",
48
+            "description": "Description"
49
+            }
50
+        ]
51
+        }
52
+        """
53
+        response = mock.Mock(text=json)
54
+        results = searchcode_doc.response(response)
55
+        self.assertEqual(type(results), list)
56
+        self.assertEqual(len(results), 1)
57
+        self.assertEqual(results[0]['title'], '[Type] Namespace test')
58
+        self.assertEqual(results[0]['url'], 'http://url')
59
+        self.assertIn('Synopsis', results[0]['content'])
60
+        self.assertIn('Type', results[0]['content'])
61
+        self.assertIn('test', results[0]['content'])
62
+        self.assertIn('Description', results[0]['content'])
63
+
64
+        json = """
65
+        {"toto":[
66
+            {"id":200,"name":"Artist Name",
67
+            "link":"http:\/\/www.searchcode_doc.com\/artist\/1217","type":"artist"}
68
+        ]}
69
+        """
70
+        response = mock.Mock(text=json)
71
+        results = searchcode_doc.response(response)
72
+        self.assertEqual(type(results), list)
73
+        self.assertEqual(len(results), 0)

+ 1
- 0
searx/tests/test_engines.py View File

@@ -5,4 +5,5 @@ from searx.tests.engines.test_flickr import *  # noqa
5 5
 from searx.tests.engines.test_github import *  # noqa
6 6
 from searx.tests.engines.test_mixcloud import *  # noqa
7 7
 from searx.tests.engines.test_searchcode_code import *  # noqa
8
+from searx.tests.engines.test_searchcode_doc import *  # noqa
8 9
 from searx.tests.engines.test_youtube import *  # noqa