From 0a1a3e7371df02580ad923fa0a4c1f4a7c08d759 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Fri, 12 Jun 2015 19:54:03 +0200 Subject: [PATCH] Add a bit of testing to improve coverage --- searx/tests/engines/test_swisscows.py | 4 ++ searx/tests/engines/test_yahoo_news.py | 19 ++++++++- searx/tests/engines/test_youtube_noapi.py | 51 +++++++++++++++++++++++ 3 files changed, 73 insertions(+), 1 deletion(-) diff --git a/searx/tests/engines/test_swisscows.py b/searx/tests/engines/test_swisscows.py index 926ba885..3b4ce7b0 100644 --- a/searx/tests/engines/test_swisscows.py +++ b/searx/tests/engines/test_swisscows.py @@ -23,6 +23,10 @@ class TestSwisscowsEngine(SearxTestCase): self.assertTrue('uiLanguage=browser' in params['url']) self.assertTrue('region=browser' in params['url']) + dicto['category'] = 'images' + params = swisscows.request(query, dicto) + self.assertIn('image', params['url']) + def test_response(self): self.assertRaises(AttributeError, swisscows.response, None) self.assertRaises(AttributeError, swisscows.response, []) diff --git a/searx/tests/engines/test_yahoo_news.py b/searx/tests/engines/test_yahoo_news.py index 94d819d6..4d7fc0a1 100644 --- a/searx/tests/engines/test_yahoo_news.py +++ b/searx/tests/engines/test_yahoo_news.py @@ -29,6 +29,13 @@ class TestYahooNewsEngine(SearxTestCase): 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, []) @@ -57,7 +64,17 @@ class TestYahooNewsEngine(SearxTestCase): This is the content - +
  • +
    +

    + + +

    +
    +
    +
    +
  • + """ response = mock.Mock(text=html) results = yahoo_news.response(response) diff --git a/searx/tests/engines/test_youtube_noapi.py b/searx/tests/engines/test_youtube_noapi.py index b715ed2f..9fa8fd20 100644 --- a/searx/tests/engines/test_youtube_noapi.py +++ b/searx/tests/engines/test_youtube_noapi.py @@ -91,6 +91,57 @@ class TestYoutubeNoAPIEngine(SearxTestCase): self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/hqdefault.jpg') self.assertTrue('DIVZCPfAOeM' in results[0]['embedded']) + html = """ +
      +
    1. +
      +
      + + + +
      +
      +

      + - Durée : 11:35. +

      +
      +
        +
      • il y a 20 heures
      • +
      • 8 424 vues
      • +
      +
      +
      +
        +
      • + Nouveauté +
      • +
      • HD
      • +
      +
      +
      +
      +
      +
      +
      +
      +
      +
    2. +
    + """ + response = mock.Mock(text=html) + results = youtube_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + html = """