@@ -0,0 +1,136 @@
1+from collections import defaultdict
3+from searx.engines import google_news
4+from searx.testing import SearxTestCase
7+class TestGoogleNewsEngine(SearxTestCase):
9+ def test_request(self):
11+ dicto = defaultdict(dict)
13+ dicto['language'] = 'fr_FR'
14+ params = google_news.request(query, dicto)
15+ self.assertIn('url', params)
16+ self.assertIn(query, params['url'])
17+ self.assertIn('googleapis.com', params['url'])
18+ self.assertIn('fr', params['url'])
20+ dicto['language'] = 'all'
21+ params = google_news.request(query, dicto)
22+ self.assertIn('url', params)
23+ self.assertIn('en', params['url'])
25+ def test_response(self):
26+ self.assertRaises(AttributeError, google_news.response, None)
27+ self.assertRaises(AttributeError, google_news.response, [])
28+ self.assertRaises(AttributeError, google_news.response, '')
29+ self.assertRaises(AttributeError, google_news.response, '[]')
31+ response = mock.Mock(text='{}')
32+ self.assertEqual(google_news.response(response), [])
34+ response = mock.Mock(text='{"data": []}')
35+ self.assertEqual(google_news.response(response), [])
42+ "GsearchResultClass": "GnewsSearch",
43+ "clusterUrl": "http://news.google.com/news/story?ncl=d2d3t1LMDpNIj2MPPhdTT0ycN4sWM&hl=fr&ned=fr",
44+ "content": "This is the content",
45+ "unescapedUrl": "http://this.is.the.url",
46+ "url": "http://this.is.the.url",
47+ "title": "This is the title",
48+ "titleNoFormatting": "This is the title",
50+ "publisher": "Jeux Actu",
51+ "publishedDate": "Fri, 30 Jan 2015 11:00:25 -0800",
52+ "signedRedirectUrl": "http://news.google.com/",
55+ "url": "http://i.jeuxactus.com/datas/jeux/d/y/dying-light/vu/dying-light-54cc080b568fb.jpg",
56+ "tbUrl": "http://t1.gstatic.com/images?q=tbn:ANd9GcSF4yYrs9Ycw23DGiOSAZ-5SEPXYwG3LNs",
57+ "originalContextUrl": "http://www.jeuxactu.com/test-dying-light-sur-ps4-97208.htm",
58+ "publisher": "Jeux Actu",
64+ "unescapedUrl": "http://www.jeuxvideo.com/test/415823/dying-light.htm",
65+ "url": "http%3A%2F%2Fwww.jeuxvideo.com%2Ftest%2F415823%2Fdying-light.htm",
66+ "title": "<b>Test</b> du jeu Dying Light - jeuxvideo.com",
67+ "titleNoFormatting": "Test du jeu Dying Light - jeuxvideo.com",
69+ "publisher": "JeuxVideo.com",
70+ "publishedDate": "Fri, 30 Jan 2015 08:52:30 -0800",
71+ "signedRedirectUrl": "http://news.google.com/news/url?sa=T&",
78+ "responseDetails": null,
79+ "responseStatus": 200
82+ response = mock.Mock(text=json)
83+ results = google_news.response(response)
84+ self.assertEqual(type(results), list)
85+ self.assertEqual(len(results), 1)
86+ self.assertEqual(results[0]['title'], 'This is the title')
87+ self.assertEqual(results[0]['url'], 'http://this.is.the.url')
88+ self.assertEqual(results[0]['content'], 'This is the content')
95+ "GsearchResultClass": "GnewsSearch",
96+ "clusterUrl": "http://news.google.com/news/story?ncl=d2d3t1LMDpNIj2MPPhdTT0ycN4sWM&hl=fr&ned=fr",
97+ "content": "This is the content",
98+ "unescapedUrl": "http://this.is.the.url",
99+ "title": "This is the title",
100+ "titleNoFormatting": "This is the title",
102+ "publisher": "Jeux Actu",
103+ "publishedDate": "Fri, 30 Jan 2015 11:00:25 -0800",
104+ "signedRedirectUrl": "http://news.google.com/news/",
107+ "url": "http://i.jeuxactus.com/datas/jeux/d/y/dying-light/vu/dying-light-54cc080b568fb.jpg",
108+ "tbUrl": "http://t1.gstatic.com/images?q=tbn:b_6f-OSAZ-5SEPXYwG3LNs",
109+ "originalContextUrl": "http://www.jeuxactu.com/test-dying-light-sur-ps4-97208.htm",
110+ "publisher": "Jeux Actu",
117+ "responseDetails": null,
118+ "responseStatus": 200
121+ response = mock.Mock(text=json)
122+ results = google_news.response(response)
123+ self.assertEqual(type(results), list)
124+ self.assertEqual(len(results), 0)
129+ "responseDetails": null,
130+ "responseStatus": 200
133+ response = mock.Mock(text=json)
134+ results = google_news.response(response)
135+ self.assertEqual(type(results), list)
136+ self.assertEqual(len(results), 0)