# -*- coding: utf-8 -*- from collections import defaultdict from datetime import datetime import mock from searx.engines import yahoo_news from searx.testing import SearxTestCase class TestYahooNewsEngine(SearxTestCase): def test_request(self): yahoo_news.supported_languages = ['en', 'fr'] query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['language'] = 'fr-FR' params = yahoo_news.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('news.search.yahoo.com', params['url']) self.assertIn('fr', params['url']) self.assertIn('cookies', params) self.assertIn('sB', params['cookies']) self.assertIn('fr', params['cookies']['sB']) dicto['language'] = 'all' params = yahoo_news.request(query, dicto) self.assertIn('cookies', params) self.assertIn('sB', params['cookies']) self.assertIn('en', params['cookies']['sB']) self.assertIn('en', params['url']) def test_sanitize_url(self): url = "test.url" self.assertEqual(url, yahoo_news.sanitize_url(url)) url = "www.yahoo.com/;_ylt=test" self.assertEqual("www.yahoo.com/", yahoo_news.sanitize_url(url)) def test_response(self): self.assertRaises(AttributeError, yahoo_news.response, None) self.assertRaises(AttributeError, yahoo_news.response, []) self.assertRaises(AttributeError, yahoo_news.response, '') self.assertRaises(AttributeError, yahoo_news.response, '[]') response = mock.Mock(text='') self.assertEqual(yahoo_news.response(response), []) html = """