浏览代码

add digbt unittest

Noemi Vanyi 8 年前
父节点
当前提交
6dd5f7a8c9
共有 1 个文件被更改,包括 59 次插入0 次删除
  1. 59
    0
      tests/unit/engines/test_digbt.py

+ 59
- 0
tests/unit/engines/test_digbt.py 查看文件

@@ -0,0 +1,59 @@
1
+from collections import defaultdict
2
+import mock
3
+from searx.engines import digbt
4
+from searx.testing import SearxTestCase
5
+
6
+
7
+class TestDigBTEngine(SearxTestCase):
8
+
9
+    def test_request(self):
10
+        query = 'test_query'
11
+        dicto = defaultdict(dict)
12
+        dicto['pageno'] = 0
13
+        params = digbt.request(query, dicto)
14
+        self.assertIn('url', params)
15
+        self.assertIn(query, params['url'])
16
+        self.assertIn('digbt.org', params['url'])
17
+
18
+    def test_response(self):
19
+        self.assertRaises(AttributeError, digbt.response, None)
20
+        self.assertRaises(AttributeError, digbt.response, [])
21
+        self.assertRaises(AttributeError, digbt.response, '')
22
+        self.assertRaises(AttributeError, digbt.response, '[]')
23
+
24
+        response = mock.Mock(content='<html></html>')
25
+        self.assertEqual(digbt.response(response), [])
26
+
27
+        html = """
28
+        <table class="table">
29
+            <tr><td class="x-item">
30
+            <div>
31
+                <a title="The Big Bang Theory" class="title" href="/The-Big-Bang-Theory-d2.html">The Big Bang Theory</a>
32
+                <span class="ctime"><span style="color:red;">4 hours ago</span></span>
33
+            </div>
34
+            <div class="files">
35
+                <ul>
36
+                    <li>The Big Bang Theory  2.9 GB</li>
37
+                    <li>....</li>
38
+                </ul>
39
+            </div>
40
+            <div class="tail">
41
+                Files: 1 Size: 2.9 GB  Downloads: 1 Updated: <span style="color:red;">4 hours ago</span>
42
+                &nbsp; &nbsp;
43
+                <a class="title" href="magnet:?xt=urn:btih:a&amp;dn=The+Big+Bang+Theory">
44
+                    <span class="glyphicon glyphicon-magnet"></span> magnet-link
45
+                </a>
46
+                &nbsp; &nbsp;
47
+            </div>
48
+            </td></tr>
49
+        </table>
50
+        """
51
+        response = mock.Mock(content=html)
52
+        results = digbt.response(response)
53
+        self.assertEqual(type(results), list)
54
+        self.assertEqual(len(results), 1)
55
+        self.assertEqual(results[0]['title'], 'The Big Bang Theory')
56
+        self.assertEqual(results[0]['url'], 'https://digbt.org/The-Big-Bang-Theory-d2.html')
57
+        self.assertEqual(results[0]['content'], 'The Big Bang Theory 2.9 GB ....')
58
+        self.assertEqual(results[0]['filesize'], 3113851289)
59
+        self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:a&dn=The+Big+Bang+Theory')