From 52ccaa7acc0eeeb452938a2a8758906430ece077 Mon Sep 17 00:00:00 2001 From: Adam Tauber Date: Sat, 21 Dec 2019 21:15:09 +0100 Subject: [mod] remove useless engine unit tests These tests are not able to detect engine errors if the upstream site changes. --- tests/unit/engines/test_yahoo.py | 190 --------------------------------------- 1 file changed, 190 deletions(-) delete mode 100644 tests/unit/engines/test_yahoo.py (limited to 'tests/unit/engines/test_yahoo.py') diff --git a/tests/unit/engines/test_yahoo.py b/tests/unit/engines/test_yahoo.py deleted file mode 100644 index e52c1109e..000000000 --- a/tests/unit/engines/test_yahoo.py +++ /dev/null @@ -1,190 +0,0 @@ -# -*- 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): - yahoo.supported_languages = ['en', 'fr', 'zh-CHT', 'zh-CHS'] - 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'] = 'zh' - params = yahoo.request(query, dicto) - self.assertIn('zh_chs', params['url']) - self.assertIn('zh_chs', params['cookies']['sB']) - - dicto['language'] = 'zh-TW' - params = yahoo.request(query, dicto) - self.assertIn('zh_cht', params['url']) - self.assertIn('zh_cht', 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_no_url_in_request_year_time_range(self): - dicto = defaultdict(dict) - query = 'test_query' - dicto['time_range'] = 'year' - params = yahoo.request(query, dicto) - self.assertEqual({}, 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 = """ -
    -
  1. -
    - -
    -

    This is the content -

    -
    -
    -
  2. -
  3. -
    -
    -
    -
    -

    This is the second content

    -
    -
    -
  4. -
-
-
-

Also Try

- - - - - -
This is the suggestion -
-
- """ - response = mock.Mock(text=html) - results = yahoo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 2) - self.assertEqual(results[0]['title'], 'This is the title') - self.assertEqual(results[0]['url'], 'https://this.is.the.url/') - self.assertEqual(results[0]['content'], 'This is the content') - self.assertEqual(results[1]['suggestion'], 'This is the suggestion') - - html = """ -
    -
  1. -
    - -
    -

    This is the content -

    -
    -
    -
  2. -
- """ - response = mock.Mock(text=html) - results = yahoo.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'], 'https://this.is.the.url/') - self.assertEqual(results[0]['content'], 'This is the content') - - html = """ -
  • -
  • - """ - response = mock.Mock(text=html) - results = yahoo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - def test_fetch_supported_languages(self): - html = """""" - response = mock.Mock(text=html) - results = yahoo._fetch_supported_languages(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - html = """ - -
    -
    - - - - - - - -
    -
    - - """ - response = mock.Mock(text=html) - languages = yahoo._fetch_supported_languages(response) - self.assertEqual(type(languages), list) - self.assertEqual(len(languages), 3) - self.assertIn('ar', languages) - self.assertIn('zh-CHS', languages) - self.assertIn('zh-CHT', languages) -- cgit v1.2.3