on master help sign in
Added unit test
commitdcc9fdb47fd16aa65216846dc52470ada016753c authorrinpatch <rinpatch@airmail.cc> dateFri 27 Apr 2018, 15:36 (8 years ago) parente3bd267
2 files changed+68−1
searx/engines/acgsou.py+1−1 tests/unit/engines/test_acgsou.py+67
searx/engines/acgsou.py+1−1
@@ -63,7 +63,7 @@ def response(resp):
6363 filesize = get_torrent_size(filesize, filesize_multiplier)
6464 except:
6565 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
6767 content = 'Category: "{category}".'
6868 content = content.format(category=category)
6969
tests/unit/engines/test_acgsou.pynew file+67
@@ -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)