# -*- coding: utf-8 -*- from collections import defaultdict import mock from searx.engines import yahoo from searx.testing import SearxTestCase class TestYahooEngine(SearxTestCase): def test_parse_url(self): test_url = 'http://r.search.yahoo.com/_ylt=A0LEb9JUSKcAEGRXNyoA;_ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb' +\ '2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10/RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=' +\ 'dtcJsfP4mEeBOjnVfUQ-' url = yahoo.parse_url(test_url) self.assertEqual('https://this.is.the.url/', url) test_url = 'http://r.search.yahoo.com/_ylt=A0LElb9JUSKcAEGRXNyoA;_ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb' +\ '2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10/RU=https%3a%2f%2fthis.is.the.url%2f/RS=' +\ 'dtcJsfP4mEeBOjnVfUQ-' url = yahoo.parse_url(test_url) self.assertEqual('https://this.is.the.url/', url) test_url = 'https://this.is.the.url/' url = yahoo.parse_url(test_url) self.assertEqual('https://this.is.the.url/', url) def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['time_range'] = '' dicto['language'] = 'fr_FR' params = yahoo.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('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.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_response(self): self.assertRaises(AttributeError, yahoo.response, None) self.assertRaises(AttributeError, yahoo.response, []) self.assertRaises(AttributeError, yahoo.response, '') self.assertRaises(AttributeError, yahoo.response, '[]') response = mock.Mock(text='') self.assertEqual(yahoo.response(response), []) html = """
This is the content
This is the second content
This is the suggestion |
This is the content