瀏覽代碼

Added unit test

rinpatch 6 年之前
父節點
當前提交
dcc9fdb47f
沒有帳戶連結到提交者的電子郵件
共有 2 個文件被更改,包括 68 次插入1 次删除
  1. 1
    1
      searx/engines/acgsou.py
  2. 67
    0
      tests/unit/engines/test_acgsou.py

+ 1
- 1
searx/engines/acgsou.py 查看文件

@@ -63,7 +63,7 @@ def response(resp):
63 63
             filesize = get_torrent_size(filesize, filesize_multiplier)
64 64
         except:
65 65
             pass
66
-        # I didn't add download/seed/leech count since as I figured out they are generated randowmly everytime
66
+        # I didn't add download/seed/leech count since as I figured out they are generated randomly everytime
67 67
         content = 'Category: "{category}".'
68 68
         content = content.format(category=category)
69 69
 

+ 67
- 0
tests/unit/engines/test_acgsou.py 查看文件

@@ -0,0 +1,67 @@
1
+from collections import defaultdict
2
+import mock
3
+from searx.engines import acgsou
4
+from searx.testing import SearxTestCase
5
+
6
+
7
+class TestAcgsouEngine(SearxTestCase):
8
+
9
+    def test_request(self):
10
+        query = 'test_query'
11
+        dic = defaultdict(dict)
12
+        dic['pageno'] = 1
13
+        params = acgsou.request(query, dic)
14
+        self.assertTrue('url' in params)
15
+        self.assertTrue(query in params['url'])
16
+        self.assertTrue('acgsou.com' in params['url'])
17
+
18
+    def test_response(self):
19
+        resp = mock.Mock(text='<html></html>')
20
+        self.assertEqual(acgsou.response(resp), [])
21
+
22
+        html = """
23
+<table id="listTable" class="list_style table_fixed">
24
+  <thead class="tcat">
25
+      <tr>
26
+      tablehead
27
+      </tr>
28
+  </thead>
29
+  <tbody class="tbody" id="data_list">
30
+              <tr class="alt1 ">
31
+        <td nowrap="nowrap">date</td>
32
+        <td><a href="category.html">testcategory</a></td>
33
+        <td style="text-align:left;">
34
+            <a href="show-torrentid.html" target="_blank">torrentname</a>
35
+        </td>
36
+        <td>1MB</td>
37
+        <td nowrap="nowrap">
38
+            <span class="bts_1">
39
+            29
40
+            </span>
41
+        </td>
42
+        <td nowrap="nowrap">
43
+            <span class="btl_1">
44
+            211
45
+        </span>
46
+        </td>
47
+        <td nowrap="nowrap">
48
+        <span class="btc_">
49
+            168
50
+        </span>
51
+        </td>
52
+        <td><a href="random.html">user</a></td>
53
+      </tr>
54
+</table>
55
+        """
56
+
57
+        resp = mock.Mock(text=html)
58
+        results = acgsou.response(resp)
59
+
60
+        self.assertEqual(type(results), list)
61
+        self.assertEqual(len(results), 1)
62
+
63
+        r = results[0]
64
+        self.assertEqual(r['url'], 'https://www.acgsou.com/show-torrentid.html')
65
+        self.assertEqual(r['content'], 'Category: "testcategory".')
66
+        self.assertEqual(r['title'], 'torrentname')
67
+        self.assertEqual(r['filesize'], 1048576)