From 53979a7bf7669c803c2a493fbf136519f6a293e6 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sat, 2 Jan 2016 11:14:49 +0100 Subject: [mod] remove buildout/makefile infrastructure --- tests/unit/engines/test_yahoo_news.py | 149 ++++++++++++++++++++++++++++++++++ 1 file changed, 149 insertions(+) create mode 100644 tests/unit/engines/test_yahoo_news.py (limited to 'tests/unit/engines/test_yahoo_news.py') diff --git a/tests/unit/engines/test_yahoo_news.py b/tests/unit/engines/test_yahoo_news.py new file mode 100644 index 000000000..4d7fc0a10 --- /dev/null +++ b/tests/unit/engines/test_yahoo_news.py @@ -0,0 +1,149 @@ +# -*- 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): + 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 = """ +
    +
  1. + +
    + Business via Yahoo! + May 01 10:00 AM +
    +
    + This is the content +
    +
  2. +
  3. +
    +

    + + +

    +
    +
    +
    +
  4. +
+ """ + response = mock.Mock(text=html) + results = yahoo_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'This is the title...') + self.assertEqual(results[0]['url'], 'http://this.is.the.url/') + self.assertEqual(results[0]['content'], 'This is the content') + + html = """ +
    +
  1. + +
    + Business via Yahoo! + 2 hours, 22 minutes ago +
    +
    + This is the content +
    +
  2. +
  3. + +
    + Business via Yahoo! + 22 minutes ago +
    +
    + This is the content +
    +
  4. +
  5. + +
    + Business via Yahoo! + Feb 03 09:45AM 1900 +
    +
    + This is the content +
    +
  6. +
+ """ + response = mock.Mock(text=html) + results = yahoo_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 3) + self.assertEqual(results[0]['title'], 'This is the title...') + self.assertEqual(results[0]['url'], 'http://this.is.the.url/') + self.assertEqual(results[0]['content'], 'This is the content') + self.assertEqual(results[2]['publishedDate'].year, datetime.now().year) -- cgit v1.2.3