@@ -0,0 +1,143 @@
1+# -*- coding: utf-8 -*-
2+from collections import defaultdict
3+from datetime import datetime
5+from searx.engines import yahoo_news
6+from searx.testing import SearxTestCase
9+class TestYahooNewsEngine(SearxTestCase):
11+ def test_request(self):
13+ dicto = defaultdict(dict)
15+ dicto['language'] = 'fr_FR'
16+ params = yahoo_news.request(query, dicto)
17+ self.assertIn('url', params)
18+ self.assertIn(query, params['url'])
19+ self.assertIn('news.search.yahoo.com', params['url'])
20+ self.assertIn('fr', params['url'])
21+ self.assertIn('cookies', params)
22+ self.assertIn('sB', params['cookies'])
23+ self.assertIn('fr', params['cookies']['sB'])
25+ dicto['language'] = 'all'
26+ params = yahoo_news.request(query, dicto)
27+ self.assertIn('cookies', params)
28+ self.assertIn('sB', params['cookies'])
29+ self.assertIn('en', params['cookies']['sB'])
30+ self.assertIn('en', params['url'])
32+ def test_response(self):
33+ self.assertRaises(AttributeError, yahoo_news.response, None)
34+ self.assertRaises(AttributeError, yahoo_news.response, [])
35+ self.assertRaises(AttributeError, yahoo_news.response, '')
36+ self.assertRaises(AttributeError, yahoo_news.response, '[]')
38+ response = mock.Mock(text='<html></html>')
39+ self.assertEqual(yahoo_news.response(response), [])
45+ <a class="yschttl spt" href="http://this.is.the.url" target="_blank">
51+ <span class="url">Business via Yahoo! Finance</span> <span class="timestamp">Feb 03 09:45am</span>
57+ response = mock.Mock(text=html)
58+ results = yahoo_news.response(response)
59+ self.assertEqual(type(results), list)
60+ self.assertEqual(len(results), 1)
61+ self.assertEqual(results[0]['title'], 'This is the title...')
62+ self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
63+ self.assertEqual(results[0]['content'], 'This is the content')
69+ <a class="yschttl spt" href="http://this.is.the.url" target="_blank">
75+ <span class="url">Business via Yahoo!</span> <span class="timestamp">2 hours, 22 minutes ago</span>
83+ <a class="yschttl spt" href="http://this.is.the.url" target="_blank">
89+ <span class="url">Business via Yahoo!</span> <span class="timestamp">22 minutes ago</span>
97+ <a class="yschttl spt" href="http://this.is.the.url" target="_blank">
103+ <span class="url">Business via Yahoo!</span> <span class="timestamp">Feb 03 09:45am 1900</span>
109+ response = mock.Mock(text=html)
110+ results = yahoo_news.response(response)
111+ self.assertEqual(type(results), list)
112+ self.assertEqual(len(results), 3)
113+ self.assertEqual(results[0]['title'], 'This is the title...')
114+ self.assertEqual(results[0]['url'], 'http://this.is.the.url/')
115+ self.assertEqual(results[0]['content'], 'This is the content')
116+ self.assertEqual(results[2]['publishedDate'].year, datetime.now().year)
119+ <li class="b_algo" u="0|5109|4755453613245655|UAGjXgIrPH5yh-o5oNHRx_3Zta87f_QO">
121+ <div class="sb_tlst">
123+ <a href="http://this.should.be.the.link/" h="ID=SERP,5124.1">
124+ <strong>This</strong> should be the title</a>
127+ <div class="sb_meta">
129+ <strong>this</strong>.meta.com</cite>
130+ <span class="c_tlbxTrg">
131+ <span class="c_tlbxH" H="BASE:CACHEDPAGEDEFAULT" K="SERP,5125.1">
136+ <strong>This</strong> should be the content.</p>
140+ response = mock.Mock(text=html)
141+ results = yahoo_news.response(response)
142+ self.assertEqual(type(results), list)
143+ self.assertEqual(len(results), 0)