From 53979a7bf7669c803c2a493fbf136519f6a293e6 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sat, 2 Jan 2016 11:14:49 +0100 Subject: [mod] remove buildout/makefile infrastructure --- tests/unit/engines/test_piratebay.py | 166 +++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 tests/unit/engines/test_piratebay.py (limited to 'tests/unit/engines/test_piratebay.py') diff --git a/tests/unit/engines/test_piratebay.py b/tests/unit/engines/test_piratebay.py new file mode 100644 index 000000000..5699380be --- /dev/null +++ b/tests/unit/engines/test_piratebay.py @@ -0,0 +1,166 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import piratebay +from searx.testing import SearxTestCase + + +class TestPiratebayEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['category'] = 'Toto' + params = piratebay.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('piratebay.se', params['url']) + self.assertIn('0', params['url']) + + dicto['category'] = 'music' + params = piratebay.request(query, dicto) + self.assertIn('100', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, piratebay.response, None) + self.assertRaises(AttributeError, piratebay.response, []) + self.assertRaises(AttributeError, piratebay.response, '') + self.assertRaises(AttributeError, piratebay.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(piratebay.response(response), []) + + html = """ + + + + + + + + + + + + + + + +
+
+ Anime
+ (Anime) +
+
+ + + Magnet link + + + Download + + + VIP + + + + This is the content and should be OK + + 13334
+
+ Anime
+ (Anime) +
+
+ + + Magnet link + + + VIP + + + + This is the content and should be OK + + 13334
+ """ + response = mock.Mock(text=html) + results = piratebay.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 2) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link') + self.assertEqual(results[0]['content'], 'This is the content and should be OK') + self.assertEqual(results[0]['seed'], 13) + self.assertEqual(results[0]['leech'], 334) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK') + self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent') + + self.assertEqual(results[1]['torrentfile'], None) + + html = """ + + + + + + + + + +
+
+ Anime
+ (Anime) +
+
+ + + Magnet link + + + Download + + + VIP + + + + This is the content and should be OK + + sd
+ """ + response = mock.Mock(text=html) + results = piratebay.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title') + self.assertEqual(results[0]['url'], 'https://thepiratebay.se/this.is.the.link') + self.assertEqual(results[0]['content'], 'This is the content and should be OK') + self.assertEqual(results[0]['seed'], 0) + self.assertEqual(results[0]['leech'], 0) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK') + self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent') + + html = """ + +
+ """ + response = mock.Mock(text=html) + results = piratebay.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) -- cgit v1.2.3-54-g00ecf