# -*- coding: utf-8 -*- from collections import defaultdict import mock import lxml from searx.engines import google from searx.testing import SearxTestCase class TestGoogleEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['language'] = 'fr_FR' params = google.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('google.com', params['url']) self.assertNotIn('PREF', params['cookies']) self.assertIn('fr', params['headers']['Accept-Language']) dicto['language'] = 'all' params = google.request(query, dicto) self.assertIn('en', params['headers']['Accept-Language']) self.assertIn('PREF', params['cookies']) def test_response(self): self.assertRaises(AttributeError, google.response, None) self.assertRaises(AttributeError, google.response, []) self.assertRaises(AttributeError, google.response, '') self.assertRaises(AttributeError, google.response, '[]') response = mock.Mock(text='') self.assertEqual(google.response(response), []) html = """