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.si' in params['url']) def test_response(self): resp = mock.Mock(text='') self.assertEqual(nyaa.response(resp), []) html = """
Category
Name
Link
Size
Date
Anime - English-translated Sample title 1 723.7 MiB 2017-08-21 11:24 1 3 12
Anime - English-translated Sample title 2 8.2 GiB 2017-04-08 01:40 10 1 206
""" resp = mock.Mock(text=html) results = nyaa.response(resp) self.assertEqual(type(results), list) self.assertEqual(len(results), 2) r = results[0] self.assertTrue(r['url'].find('1') >= 0) self.assertTrue(r['torrentfile'].find('1.torrent') >= 0) self.assertTrue(r['content'].find('Anime - English-translated') >= 0) self.assertTrue(r['content'].find('Downloaded 12 times.') >= 0) self.assertEqual(r['title'], 'Sample title 1') self.assertEqual(r['seed'], 1) self.assertEqual(r['leech'], 3) self.assertEqual(r['filesize'], 723700000) r = results[1] self.assertTrue(r['url'].find('2') >= 0) self.assertTrue(r['magnetlink'].find('magnet:') >= 0)