from collections import defaultdict import mock from searx.engines import gigablast from searx.testing import SearxTestCase class TestGigablastEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 0 dicto['language'] = 'all' params = gigablast.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) self.assertTrue('gigablast.com' in params['url']) def test_response(self): self.assertRaises(AttributeError, gigablast.response, None) self.assertRaises(AttributeError, gigablast.response, []) self.assertRaises(AttributeError, gigablast.response, '') self.assertRaises(AttributeError, gigablast.response, '[]') response = mock.Mock(content='') self.assertEqual(gigablast.response(response), []) response = mock.Mock(content='') self.assertEqual(gigablast.response(response), []) xml = """ 5941888 1 <![CDATA[This should be the title]]> 90.5 145414002633 2660021087 2660021087 1320519373 1320519373 4294967295 0 """ response = mock.Mock(content=xml) results = gigablast.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.')