# -*- coding: utf-8 -*- from collections import defaultdict import mock from searx.engines import google_news from searx.testing import SearxTestCase class TestGoogleNewsEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['language'] = 'fr_FR' dicto['time_range'] = 'w' params = google_news.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('fr', params['url']) dicto['language'] = 'all' params = google_news.request(query, dicto) self.assertIn('url', params) self.assertNotIn('fr', params['url']) def test_response(self): self.assertRaises(AttributeError, google_news.response, None) self.assertRaises(AttributeError, google_news.response, []) self.assertRaises(AttributeError, google_news.response, '') self.assertRaises(AttributeError, google_news.response, '[]') response = mock.Mock(text='{}') self.assertEqual(google_news.response(response), []) response = mock.Mock(text='{"data": []}') self.assertEqual(google_news.response(response), []) html = u"""