diff --git a/tests/unit/engines/test_base.py b/tests/unit/engines/test_base.py new file mode 100644 index 00000000..e008b034 --- /dev/null +++ b/tests/unit/engines/test_base.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import base +from searx.testing import SearxTestCase + + +class TestBaseEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = base.request(query, dicto) + self.assertIn('url', params) + self.assertIn('base-search.net', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, base.response, None) + self.assertRaises(AttributeError, base.response, []) + self.assertRaises(AttributeError, base.response, '') + self.assertRaises(AttributeError, base.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(base.response(response), []) + + xml_mock = """ + + + 0 + 1 + + + + 2000-01-01T01:01:01Z + 1 + cna + us + ftciteseerx + CiteSeerX + Science and more + + Someone + + + Someone + + + Science and more + + Science, and even more. + + The neighbour + + 2001 + 2001 + + text + + + 1 + + + application/pdf + + + application/pdf + + + http://example.org/ + + http://example.org + http://example.org + + en + + Under the example.org licence + 1 + + eng + + + +""" + + response = mock.Mock(text=xml_mock.encode('utf-8')) + results = base.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Science and more') + self.assertEqual(results[0]['content'], 'Science, and even more.')