# -*- 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(content=b'')
self.assertEqual(base.response(response), [])
xml_mock = b"""
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(content=xml_mock)
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.')