@@ -0,0 +1,110 @@
2+from collections import defaultdict
3+from searx.engines import tokyotoshokan
4+from searx.testing import SearxTestCase
5+from datetime import datetime
8+class TestTokyotoshokanEngine(SearxTestCase):
10+ def test_request(self):
12+ dic = defaultdict(dict)
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'])
19+ def test_response(self):
20+ resp = mock.Mock(text='<html></html>')
21+ self.assertEqual(tokyotoshokan.response(resp), [])
24+ <table class="listing">
26+ <tr class="shade category_0">
28+ <a href="/?cat=7"><span class="sprite_cat-raw"></span></a>
30+ <td class="desc-top">
31+ <a href="magnet:?xt=urn:btih:4c19eb46b5113685fbd2288ed2531b0b">
32+ <span class="sprite_magnet"></span>
34+ <a rel="nofollow" type="application/x-bittorrent" href="http://www.nyaa.se/f">
38+ <td class="web"><a rel="nofollow" href="details.php?id=975700">Details</a></td>
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> |
45+ Date: 2016-03-26 16:41 UTC |
46+ Comment: sample comment
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>
56+ <tr class="category_0">
58+ <a href="/?cat=7"><span class="sprite_cat-raw"></span></a>
60+ <td class="desc-top">
61+ <a rel="nofollow" type="application/x-bittorrent" href="http://google.com/q">
65+ <td class="web"><a rel="nofollow" href="details.php?id=975700">Details</a></td>
67+ <tr class="category_0">
68+ <td class="desc-bot">
69+ Submitter: <a href="?username=Ohys">Ohys</a> |
71+ Date: QWERTY-03-26 16:41 UTC
73+ <td style="color: #BBB; font-family: monospace" class="stats" align="right">
74+ S: <span style="color: red">0</span>
81+ resp = mock.Mock(text=html)
82+ results = tokyotoshokan.response(resp)
84+ self.assertEqual(type(results), list)
85+ self.assertEqual(len(results), 2)
87+ # testing the first result, which has correct format
88+ # and should have all information fields filled
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)
99+ # testing the second result, which does not include magnet link,
100+ # seed & leech info, and has incorrect size & creation date
102+ self.assertEqual(r['url'], 'http://google.com/q')
103+ self.assertEqual(r['title'], 'Owarimonogatari')
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)