@@ -0,0 +1,154 @@
1+# -*- coding: utf-8 -*-
2+from collections import defaultdict
4+from searx.engines import yahoo
5+from searx.testing import SearxTestCase
8+class TestYahooEngine(SearxTestCase):
10+ def test_parse_url(self):
11+ test_url = 'http://r.search.yahoo.com/_ylt=A0LEb9JUSKcAEGRXNyoA;_ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb' +\
12+ '2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10/RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=' +\
13+ 'dtcJsfP4mEeBOjnVfUQ-'
14+ url = yahoo.parse_url(test_url)
15+ self.assertEqual('https://this.is.the.url/', url)
17+ test_url = 'http://r.search.yahoo.com/_ylt=A0LElb9JUSKcAEGRXNyoA;_ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb' +\
18+ '2xvA2Jm2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10/RU=https%3a%2f%2fthis.is.the.url%2f/RS=' +\
19+ 'dtcJsfP4mEeBOjnVfUQ-'
20+ url = yahoo.parse_url(test_url)
21+ self.assertEqual('https://this.is.the.url/', url)
23+ test_url = 'https://this.is.the.url/'
24+ url = yahoo.parse_url(test_url)
25+ self.assertEqual('https://this.is.the.url/', url)
27+ def test_request(self):
29+ dicto = defaultdict(dict)
31+ dicto['language'] = 'fr_FR'
32+ params = yahoo.request(query, dicto)
33+ self.assertIn('url', params)
34+ self.assertIn(query, params['url'])
35+ self.assertIn('search.yahoo.com', params['url'])
36+ self.assertIn('fr', params['url'])
37+ self.assertIn('cookies', params)
38+ self.assertIn('sB', params['cookies'])
39+ self.assertIn('fr', params['cookies']['sB'])
41+ dicto['language'] = 'all'
42+ params = yahoo.request(query, dicto)
43+ self.assertIn('cookies', params)
44+ self.assertIn('sB', params['cookies'])
45+ self.assertIn('en', params['cookies']['sB'])
46+ self.assertIn('en', params['url'])
48+ def test_response(self):
49+ self.assertRaises(AttributeError, yahoo.response, None)
50+ self.assertRaises(AttributeError, yahoo.response, [])
51+ self.assertRaises(AttributeError, yahoo.response, '')
52+ self.assertRaises(AttributeError, yahoo.response, '[]')
54+ response = mock.Mock(text='<html></html>')
55+ self.assertEqual(yahoo.response(response), [])
61+ <a id="link-1" class="yschttl spt" href="http://r.search.yahoo.com/_ylt=A0LEVzClb9JUSKcAEGRXNyoA;
62+ _ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb2xvA2JmMQR2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10
63+ /RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=dtcJsfP4mEeBOjnVfUQ-"target="_blank" data-bk="5063.1">
64+ <b>This</b> is the title
68+ <span class="url" dir="ltr">www.<b>test</b>.com</span>
70+ <b>This</b> is the content
73+ <div id="satat" data-bns="Yahoo" data-bk="124.1">
79+ <a id="srpnat0" class="" href="https://search.yahoo.com/search=rs-bottom" >
81+ <b></b>This is <b>the suggestion</b>
90+ response = mock.Mock(text=html)
91+ results = yahoo.response(response)
92+ self.assertEqual(type(results), list)
93+ self.assertEqual(len(results), 2)
94+ self.assertEqual(results[0]['title'], 'This is the title')
95+ self.assertEqual(results[0]['url'], 'https://this.is.the.url/')
96+ self.assertEqual(results[0]['content'], 'This is the content')
97+ self.assertEqual(results[1]['suggestion'], 'This is the suggestion')
103+ <a id="link-1" class="yschttl spt" href="http://r.search.yahoo.com/_ylt=A0LEVzClb9JUSKcAEGRXNyoA;
104+ _ylu=X3oDMTEzZm1qazYwBHNlYwNzcgRwb3MDMQRjb2xvA2JmMQR2dGlkA1NNRTcwM18x/RV=2/RE=1423106085/RO=10
105+ /RU=https%3a%2f%2fthis.is.the.url%2f/RK=0/RS=dtcJsfP4mEeBOjnVfUQ-"target="_blank" data-bk="5063.1">
106+ <b>This</b> is the title
110+ <span class="url" dir="ltr">www.<b>test</b>.com</span>
112+ <b>This</b> is the content
118+ <a id="link-1" class="yschttl spt">
119+ <b>This</b> is the title
123+ <span class="url" dir="ltr">www.<b>test</b>.com</span>
125+ <b>This</b> is the content
133+ <span class="url" dir="ltr">www.<b>test</b>.com</span>
135+ <b>This</b> is the content
139+ response = mock.Mock(text=html)
140+ results = yahoo.response(response)
141+ self.assertEqual(type(results), list)
142+ self.assertEqual(len(results), 1)
143+ self.assertEqual(results[0]['title'], 'This is the title')
144+ self.assertEqual(results[0]['url'], 'https://this.is.the.url/')
145+ self.assertEqual(results[0]['content'], 'This is the content')
148+ <li class="b_algo" u="0|5109|4755453613245655|UAGjXgIrPH5yh-o5oNHRx_3Zta87f_QO">
151+ response = mock.Mock(text=html)
152+ results = yahoo.response(response)
153+ self.assertEqual(type(results), list)
154+ self.assertEqual(len(results), 0)