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_startpage.py | 140 +++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 tests/unit/engines/test_startpage.py (limited to 'tests/unit/engines/test_startpage.py') diff --git a/tests/unit/engines/test_startpage.py b/tests/unit/engines/test_startpage.py new file mode 100644 index 000000000..9a1a09bc7 --- /dev/null +++ b/tests/unit/engines/test_startpage.py @@ -0,0 +1,140 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import startpage +from searx.testing import SearxTestCase + + +class TestStartpageEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = startpage.request(query, dicto) + self.assertIn('url', params) + self.assertIn('startpage.com', params['url']) + self.assertIn('data', params) + self.assertIn('query', params['data']) + self.assertIn(query, params['data']['query']) + self.assertIn('with_language', params['data']) + self.assertIn('lang_fr', params['data']['with_language']) + + dicto['language'] = 'all' + params = startpage.request(query, dicto) + self.assertNotIn('with_language', params['data']) + + def test_response(self): + self.assertRaises(AttributeError, startpage.response, None) + self.assertRaises(AttributeError, startpage.response, []) + self.assertRaises(AttributeError, startpage.response, '') + self.assertRaises(AttributeError, startpage.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(startpage.response(response), []) + + html = """ +
+

+ + This should be the title + + +

+

+ This should be the content. +

+

+ www.speedtest.net/fr/ + + - + + Navigation avec Ixquick Proxy + + - + + Mis en surbrillance + +

+
+ """ + response = mock.Mock(content=html) + results = startpage.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This should be the title') + self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') + + html = """ +
+

+ + This should be the title + + +

+

+ This should be the content. +

+

+ www.speedtest.net/fr/ + + - + + Navigation avec Ixquick Proxy + + - + + Mis en surbrillance + +

+
+
+

+ +

+

+ This should be the content. +

+

+ www.speedtest.net/fr/ + +

+
+
+

+ + This should be the title + + +

+

+ www.speedtest.net/fr/ + + - + + Navigation avec Ixquick Proxy + + - + + Mis en surbrillance + +

+
+ """ + response = mock.Mock(content=html) + results = startpage.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['content'], '') -- cgit v1.2.3