diff options
author | Kirill Isakov <ukwt@ya.ru> | 2016-03-25 00:24:37 +0600 |
---|---|---|
committer | Kirill Isakov <ukwt@ya.ru> | 2016-03-25 00:24:37 +0600 |
commit | e5677ae6b6b23c943e64d8e2abcb64c13c0e8bbf (patch) | |
tree | c437375db9a77f84a0eabf69279c31a3b4d3b7ce /tests | |
parent | d748b8419ad1ef875f34783bbbcf773ebc4cfb5e (diff) | |
download | searxng-e5677ae6b6b23c943e64d8e2abcb64c13c0e8bbf.tar.gz searxng-e5677ae6b6b23c943e64d8e2abcb64c13c0e8bbf.zip |
Add Nyaa.se search engine
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/engines/test_nyaa.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/unit/engines/test_nyaa.py b/tests/unit/engines/test_nyaa.py new file mode 100644 index 000000000..db412e1cc --- /dev/null +++ b/tests/unit/engines/test_nyaa.py @@ -0,0 +1,66 @@ +from collections import defaultdict +import mock +from searx.engines import nyaa +from searx.testing import SearxTestCase + + +class TestNyaaEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dic = defaultdict(dict) + dic['pageno'] = 1 + params = nyaa.request(query, dic) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('nyaa.se' in params['url']) + + def test_response(self): + resp = mock.Mock(text='<html></html>') + self.assertEqual(nyaa.response(resp), []) + + html = """ + <table class="tlist"> + <tbody> + <tr class="trusted tlistrow"> + <td class="tlisticon"> + <a href="//www.nyaa.se" title="English-translated Anime"> + <img src="//files.nyaa.se" alt="English-translated Anime"> + </a> + </td> + <td class="tlistname"> + <a href="//www.nyaa.se/?page3"> + Sample torrent title + </a> + </td> + <td class="tlistdownload"> + <a href="//www.nyaa.se/?page_dl" title="Download"> + <img src="//files.nyaa.se/www-dl.png" alt="DL"> + </a> + </td> + <td class="tlistsize">10 MiB</td> + <td class="tlistsn">1</td> + <td class="tlistln">3</td> + <td class="tlistdn">666</td> + <td class="tlistmn">0</td> + </tr> + </tbody> + </table> + """ + + resp = mock.Mock(text=html) + results = nyaa.response(resp) + + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + + r = results[0] + self.assertTrue(r['url'].find('www.nyaa.se/?page3') >= 0) + self.assertTrue(r['torrentfile'].find('www.nyaa.se/?page_dl') >= 0) + self.assertTrue(r['content'].find('English-translated Anime') >= 0) + self.assertTrue(r['content'].find('Downloaded 666 times.') >= 0) + + self.assertEqual(r['title'], 'Sample torrent title') + self.assertEqual(r['seed'], 1) + self.assertEqual(r['leech'], 3) + self.assertEqual(r['filesize'], 10 * 1024 * 1024) |