From d081eee3f8c6b5eba39ee07916850f06aeee8658 Mon Sep 17 00:00:00 2001 From: jibe-b Date: Fri, 22 Sep 2017 22:26:37 +0200 Subject: [PATCH] [add] unit_test for base engine --- tests/unit/engines/test_base.py | 91 +++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/unit/engines/test_base.py diff --git a/tests/unit/engines/test_base.py b/tests/unit/engines/test_base.py new file mode 100644 index 000000000..e008b034c --- /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.')