@@ -0,0 +1,110 @@
1+import mock
2+from collections import defaultdict
3+from searx.engines import tokyotoshokan
4+from searx.testing import SearxTestCase
5+from datetime import datetime
6+
7+
8+class TestTokyotoshokanEngine(SearxTestCase):
9+
10+ def test_request(self):
11+ query = 'test_query'
12+ dic = defaultdict(dict)
13+ dic['pageno'] = 1
14+ params = tokyotoshokan.request(query, dic)
15+ self.assertTrue('url' in params)
16+ self.assertTrue(query in params['url'])
17+ self.assertTrue('tokyotosho.info' in params['url'])
18+
19+ def test_response(self):
20+ resp = mock.Mock(text='<html></html>')
21+ self.assertEqual(tokyotoshokan.response(resp), [])
22+
23+ html = """
24+ <table class="listing">
25+ <tbody>
26+ <tr class="shade category_0">
27+ <td rowspan="2">
28+ <a href="/?cat=7"><span class="sprite_cat-raw"></span></a>
29+ </td>
30+ <td class="desc-top">
31+ <a href="magnet:?xt=urn:btih:4c19eb46b5113685fbd2288ed2531b0b">
32+ <span class="sprite_magnet"></span>
33+ </a>
34+ <a rel="nofollow" type="application/x-bittorrent" href="http://www.nyaa.se/f">
35+ Koyomimonogatari
36+ </a>
37+ </td>
38+ <td class="web"><a rel="nofollow" href="details.php?id=975700">Details</a></td>
39+ </tr>
40+ <tr class="shade category_0">
41+ <td class="desc-bot">
42+ Authorized: <span class="auth_ok">Yes</span>
43+ Submitter: <a href="?username=Ohys">Ohys</a> |
44+ Size: 10.5MB |
45+ Date: 2016-03-26 16:41 UTC |
46+ Comment: sample comment
47+ </td>
48+ <td style="color: #BBB; font-family: monospace" class="stats" align="right">
49+ S: <span style="color: red">53</span>
50+ L: <span style="color: red">18</span>
51+ C: <span style="color: red">0</span>
52+ ID: 975700
53+ </td>
54+ </tr>
55+
56+ <tr class="category_0">
57+ <td rowspan="2">
58+ <a href="/?cat=7"><span class="sprite_cat-raw"></span></a>
59+ </td>
60+ <td class="desc-top">
61+ <a rel="nofollow" type="application/x-bittorrent" href="http://google.com/q">
62+ Owarimonogatari
63+ </a>
64+ </td>
65+ <td class="web"><a rel="nofollow" href="details.php?id=975700">Details</a></td>
66+ </tr>
67+ <tr class="category_0">
68+ <td class="desc-bot">
69+ Submitter: <a href="?username=Ohys">Ohys</a> |
70+ Size: 932.84EB |
71+ Date: QWERTY-03-26 16:41 UTC
72+ </td>
73+ <td style="color: #BBB; font-family: monospace" class="stats" align="right">
74+ S: <span style="color: red">0</span>
75+ </td>
76+ </tr>
77+ </tbody>
78+ </table>
79+ """
80+
81+ resp = mock.Mock(text=html)
82+ results = tokyotoshokan.response(resp)
83+
84+ self.assertEqual(type(results), list)
85+ self.assertEqual(len(results), 2)
86+
87+ # testing the first result, which has correct format
88+ # and should have all information fields filled
89+ r = results[0]
90+ self.assertEqual(r['url'], 'http://www.nyaa.se/f')
91+ self.assertEqual(r['title'], 'Koyomimonogatari')
92+ self.assertEqual(r['magnetlink'], 'magnet:?xt=urn:btih:4c19eb46b5113685fbd2288ed2531b0b')
93+ self.assertEqual(r['filesize'], int(1024 * 1024 * 10.5))
94+ self.assertEqual(r['publishedDate'], datetime(2016, 03, 26, 16, 41))
95+ self.assertEqual(r['content'], 'Comment: sample comment')
96+ self.assertEqual(r['seed'], 53)
97+ self.assertEqual(r['leech'], 18)
98+
99+ # testing the second result, which does not include magnet link,
100+ # seed & leech info, and has incorrect size & creation date
101+ r = results[1]
102+ self.assertEqual(r['url'], 'http://google.com/q')
103+ self.assertEqual(r['title'], 'Owarimonogatari')
104+
105+ self.assertFalse('magnetlink' in r)
106+ self.assertFalse('filesize' in r)
107+ self.assertFalse('content' in r)
108+ self.assertFalse('publishedDate' in r)
109+ self.assertFalse('seed' in r)
110+ self.assertFalse('leech' in r)