diff options
| author | Mathieu Brunot <mathieu.brunot@monogramm.io> | 2019-10-16 19:30:02 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-10-16 19:30:02 +0200 |
| commit | a51b2b6c20c1346748c09aec051d78f6822c580c (patch) | |
| tree | 5f08fadc14de64e86c5582ebbdc928e4abe7475b /tests/unit | |
| parent | 4d17d453bf99641797dcbfa1f1a35dd5b21dcab4 (diff) | |
| parent | 12f42d1572311a56401637ac5c7dc66008eb979c (diff) | |
Merge branch 'master' into feature/accessibility
Diffstat (limited to 'tests/unit')
| -rw-r--r-- | tests/unit/engines/test_deviantart.py | 71 | ||||
| -rw-r--r-- | tests/unit/engines/test_digg.py | 85 | ||||
| -rw-r--r-- | tests/unit/engines/test_startpage.py | 123 | ||||
| -rw-r--r-- | tests/unit/engines/test_www1x.py | 43 |
4 files changed, 25 insertions, 297 deletions
diff --git a/tests/unit/engines/test_deviantart.py b/tests/unit/engines/test_deviantart.py index bd2cf182f..a31151037 100644 --- a/tests/unit/engines/test_deviantart.py +++ b/tests/unit/engines/test_deviantart.py @@ -22,74 +22,3 @@ class TestDeviantartEngine(SearxTestCase): dicto['time_range'] = 'year' params = deviantart.request(query, dicto) self.assertEqual({}, params['url']) - - def test_response(self): - self.assertRaises(AttributeError, deviantart.response, None) - self.assertRaises(AttributeError, deviantart.response, []) - self.assertRaises(AttributeError, deviantart.response, '') - self.assertRaises(AttributeError, deviantart.response, '[]') - - response = mock.Mock(text='<html></html>') - self.assertEqual(deviantart.response(response), []) - - response = mock.Mock(status_code=302) - self.assertEqual(deviantart.response(response), []) - - html = """ - <div id="page-1-results" class="page-results results-page-thumb torpedo-container"> - <span class="thumb wide" href="http://amai911.deviantart.com/art/Horse-195212845" - data-super-full-width="900" data-super-full-height="600"> - <a class="torpedo-thumb-link" href="https://url.of.image"> - <img data-sigil="torpedo-img" src="https://url.of.thumbnail" /> - </a> - <span class="info"><span class="title-wrap"><span class="title">Title of image</span></span> - </div> - """ - response = mock.Mock(text=html) - results = deviantart.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title of image') - self.assertEqual(results[0]['url'], 'https://url.of.image') - self.assertNotIn('content', results[0]) - self.assertEqual(results[0]['thumbnail_src'], 'https://url.of.thumbnail') - - html = """ - <span class="tt-fh-tc" style="width: 202px;"> - <span class="tt-bb" style="width: 202px;"> - </span> - <span class="shadow"> - <a class="thumb" href="http://url.of.result/2nd.part.of.url" - title="Behoimi BE Animation Test by test-0, Jan 4, - 2010 in Digital Art > Animation"> <i></i> - <img width="200" height="200" alt="Test" - src="http://url.of.thumbnail" data-src="http://th08.deviantart.net/test.jpg"> - </a> - </span> - <!-- ^TTT --> - </span> - <span class="details"> - <a href="http://test-0.deviantart.com/art/Test" class="t" - title="Behoimi BE Animation Test by test-0, Jan 4, 2010"> - <span class="tt-fh-oe">Title of image</span> </a> - <small> - <span class="category"> - <span class="age"> - 5 years ago - </span> - in <a title="Behoimi BE Animation Test by test-0, Jan 4, 2010" - href="http://www.deviantart.com/browse/all/digitalart/animation/">Animation</a> - </span> - <div class="commentcount"> - <a href="http://test-0.deviantart.com/art/Test#comments"> - <span class="iconcommentsstats"></span>9 Comments</a> - </div> - <a class="mlt-link" href="http://www.deviantart.com/morelikethis/149167425"> - <span class="mlt-icon"></span> <span class="mlt-text">More Like This</span> </a> - </span> - </small> <!-- TTT$ --> - """ - response = mock.Mock(text=html) - results = deviantart.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_digg.py b/tests/unit/engines/test_digg.py index 6e7c9cc99..8bc4c67c2 100644 --- a/tests/unit/engines/test_digg.py +++ b/tests/unit/engines/test_digg.py @@ -14,88 +14,3 @@ class TestDiggEngine(SearxTestCase): self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('digg.com', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, digg.response, None) - self.assertRaises(AttributeError, digg.response, []) - self.assertRaises(AttributeError, digg.response, '') - self.assertRaises(AttributeError, digg.response, '[]') - - response = mock.Mock(text='{}') - self.assertEqual(digg.response(response), []) - - response = mock.Mock(text='{"data": []}') - self.assertEqual(digg.response(response), []) - - json = """ - { - "status": "ok", - "num": 10, - "next_position": 20, - "html": "<article itemscope itemtype=\\"http://schema.org/Article\\" - class=\\"story-container digg-story-el hentry entry story-1sRANah col-1\\" - data-content-id=\\"1sRANah\\" data-contenturl=\\"http://url.of.link\\" - data-position=\\"0\\" data-diggs=\\"24\\" data-tweets=\\"69\\" - data-digg-score=\\"1190\\"> <div class=\\"story-image story-image-thumb\\"> - <a data-position=\\"0\\" data-content-id=\\"1sRANah\\" - class=\\"story-link\\" href=\\"http://www.thedailybeast.com/\\" - target=\\"_blank\\"><img class=\\"story-image-img\\" - src=\\"http://url.of.image.jpeg\\" width=\\"312\\" height=\\"170\\" - alt=\\"\\" /> </a> </div> <div class=\\"story-content\\"><header - class=\\"story-header\\"> <div itemprop=\\"alternativeHeadline\\" - class=\\"story-kicker\\" >Kicker</div> <h2 itemprop=\\"headline\\" - class=\\"story-title entry-title\\"><a class=\\"story-title-link story-link\\" - rel=\\"bookmark\\" itemprop=\\"url\\" href=\\"http://www.thedailybeast.com/\\" - target=\\"_blank\\">Title of article</h2> <div class=\\"story-meta\\"> - <div class=\\"story-score \\"> - <div class=\\"story-score-diggscore diggscore-1sRANah\\">1190</div> - <div class=\\"story-score-details\\"> <div class=\\"arrow\\"></div> - <ul class=\\"story-score-details-list\\"> <li - class=\\"story-score-detail story-score-diggs\\"><span - class=\\"label\\">Diggs:</span> <span class=\\"count diggs-1sRANah\\">24</span> - </li> <li class=\\"story-score-detail story-score-twitter\\"><span - class=\\"label\\">Tweets:</span> <span class=\\"count tweets-1sRANah\\">69</span> - </li> <li class=\\"story-score-detail story-score-facebook\\"><span - class=\\"label\\">Facebook Shares:</span> <span - class=\\"count fb_shares-1sRANah\\">1097</span></li> </ul> </div> </div> - <span class=\\"story-meta-item story-source\\"> <a - itemprop=\\"publisher copyrightHolder sourceOrganization provider\\" - class=\\"story-meta-item-link story-source-link\\" - href=\\"/source/thedailybeast.com\\">The Daily Beast </a> </span> - <span class=\\"story-meta-item story-tag first-tag\\"> <a - itemprop=\\"keywords\\" rel=\\"tag\\" - class=\\"story-meta-item-link story-tag-link\\" href=\\"/tag/news\\">News</a> - </span> <abbr class=\\"published story-meta-item story-timestamp\\" - title=\\"2014-10-18 14:53:45\\"> <time datetime=\\"2014-10-18 14:53:45\\">18 Oct 2014</time> - </abbr> </div> </header> </div> <ul class=\\"story-actions\\"> <li - class=\\"story-action story-action-digg btn-story-action-container\\"> - <a class=\\"target digg-1sRANah\\" href=\\"#\\">Digg</a></li> <li - class=\\"story-action story-action-save btn-story-action-container\\"> - <a class=\\"target save-1sRANah\\" href=\\"#\\">Save</a></li> <li - class=\\"story-action story-action-share\\"><a - class=\\"target share-facebook\\" href=\\"https://www.facebook.com/\\">Facebook</a></li> - <li class=\\"story-action story-action-share\\"><a class=\\"target share-twitter\\" - href=\\"https://twitter.com/\\">Twitter</a></li> </ul> </article>" - } - """ - json = json.replace('\r\n', '').replace('\n', '').replace('\r', '') - response = mock.Mock(text=json) - results = digg.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['title'], 'Title of article') - self.assertEqual(results[0]['url'], 'http://url.of.link') - self.assertEqual(results[0]['thumbnail'], 'http://url.of.image.jpeg') - self.assertEqual(results[0]['content'], '') - - json = """ - { - "status": "error", - "num": 10, - "next_position": 20 - } - """ - response = mock.Mock(text=json) - results = digg.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) diff --git a/tests/unit/engines/test_startpage.py b/tests/unit/engines/test_startpage.py index a4704ce22..ac4454738 100644 --- a/tests/unit/engines/test_startpage.py +++ b/tests/unit/engines/test_startpage.py @@ -18,12 +18,9 @@ class TestStartpageEngine(SearxTestCase): self.assertIn('data', params) self.assertIn('query', params['data']) self.assertIn(query, params['data']['query']) - self.assertIn('with_language', params['data']) - self.assertIn('lang_fr', params['data']['with_language']) dicto['language'] = 'all' params = startpage.request(query, dicto) - self.assertNotIn('with_language', params['data']) def test_response(self): self.assertRaises(AttributeError, startpage.response, None) @@ -35,33 +32,32 @@ class TestStartpageEngine(SearxTestCase): self.assertEqual(startpage.response(response), []) html = """ - <li class="search-result search-item"> - <h3> - <a href='http://this.should.be.the.link/' id='title_2' name='title_2' > - This should be the title +<div class="w-gl__result"> + <a + class="w-gl__result-title" + href="http://this.should.be.the.link/" + data-onw="1" + rel="noopener noreferrer" + target="_blank"> + + <h3>This should be the title</h3> </a> - <span id='title_stars_2' name='title_stars_2'> </span> - </h3> - <p class="search-item__body"> - This should be the content. - </p> - <p> - <span class='url'>www.speed<b>test</b>.net/fr/ - </span> - - - <A class="proxy" id="proxy_link" HREF="https://ixquick-proxy.com/do/spg/proxy?ep=&edata=&ek=&ekdata=" - class='proxy'> - Navigation avec Ixquick Proxy - </A> - - - <A HREF="https://ixquick-proxy.com/do/spg/highlight.pl?l=francais&c=hf&cat=web&q=test&rl=NONE&rid= - &hlq=https://startpage.com/do/search&mtabp=-1&mtcmd=process_search&mtlanguage=francais&mtengine0= - &mtcat=web&u=http:%2F%2Fwww.speedtest.net%2Ffr%2F" class='proxy'> - Mis en surbrillance - </A> - </p> - </li> - """ + <div class="w-gl__result-second-line-container"> + <div class="w-gl__result-url-container"> + <a + class="w-gl__result-url" + href="http://this.should.be.the.link/" + rel="noopener noreferrer" + target="_blank">https://www.cnbc.com/2019/10/12/dj-zedd-banned-in-china-for-liking-a-south-park-tweet.html</a> + </div> + <a + class="w-gl__anonymous-view-url" + href="https://eu-browse.startpage.com/do/proxy?ep=556b554d576b6f5054554546423167764b5445616455554d5342675441774659495246304848774f5267385453304941486b5949546c63704e33774f526b705544565647516d4a61554246304847674f4a556f6957415a4f436b455042426b6b4f7a64535a52784a56514a4f45307743446c567250445a4f4c52514e5677554e46776b4b545563704c7931554c5167465467644f42464d4f4255426f4d693152624634525741305845526c595746636b626d67494e42705743466c515252634f4267456e597a7346596b7856435134465345634f564249794b5752785643315863546769515773764a5163494c5877505246315865456f5141426b4f41774167596d6c5a4e30395758773442465251495677596c624770665a6b786344466b4151455663425249794d6a78525a55554157516f4342556766526b51314b57514e&ek=4q58686o5047786n6343527259445247576p6o38&ekdata=84abd523dc13cba5c65164d04d7d7263" + target="_blank">Anonymous View</a> + </div> + <p class="w-gl__description">This should be the content.</p> + </div> + """ # noqa response = mock.Mock(text=html.encode('utf-8')) results = startpage.response(response) self.assertEqual(type(results), list) @@ -69,72 +65,3 @@ class TestStartpageEngine(SearxTestCase): self.assertEqual(results[0]['title'], 'This should be the title') self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') self.assertEqual(results[0]['content'], 'This should be the content.') - - html = """ - <li class="search-result search-item"> - <h3> - <a href='http://www.google.com/aclk?sa=l&ai=C' id='title_2' name='title_2' > - This should be the title - </a> - <span id='title_stars_2' name='title_stars_2'> </span> - </h3> - <p class="search-item__body"> - This should be the content. - </p> - <p> - <span class='url'>www.speed<b>test</b>.net/fr/ - </span> - - - <A class="proxy" id="proxy_link" HREF="https://ixquick-proxy.com/do/spg/proxy?ep=&edata=&ek=&ekdata=" - class='proxy'> - Navigation avec Ixquick Proxy - </A> - - - <A HREF="https://ixquick-proxy.com/do/spg/highlight.pl?l=francais&c=hf&cat=web&q=test&rl=NONE&rid= - &hlq=https://startpage.com/do/search&mtabp=-1&mtcmd=process_search&mtlanguage=francais&mtengine0= - &mtcat=web&u=http:%2F%2Fwww.speedtest.net%2Ffr%2F" class='proxy'> - Mis en surbrillance - </A> - </p> - </li> - <li class="search-result search-item"> - <h3> - <span id='title_stars_2' name='title_stars_2'> </span> - </h3> - <p class="search-item__body"> - This should be the content. - </p> - <p> - <span class='url'>www.speed<b>test</b>.net/fr/ - </span> - </p> - </li> - <li class="search-result search-item"> - <h3> - <a href='http://this.should.be.the.link/' id='title_2' name='title_2' > - This should be the title - </a> - <span id='title_stars_2' name='title_stars_2'> </span> - </h3> - <p> - <span class='url'>www.speed<b>test</b>.net/fr/ - </span> - - - <A class="proxy" id="proxy_link" HREF="https://ixquick-proxy.com/do/spg/proxy?ep=&edata=&ek=&ekdata=" - class='proxy'> - Navigation avec Ixquick Proxy - </A> - - - <A HREF="https://ixquick-proxy.com/do/spg/highlight.pl?l=francais&c=hf&cat=web&q=test&rl=NONE&rid= - &hlq=https://startpage.com/do/search&mtabp=-1&mtcmd=process_search&mtlanguage=francais&mtengine0= - &mtcat=web&u=http:%2F%2Fwww.speedtest.net%2Ffr%2F" class='proxy'> - Mis en surbrillance - </A> - </p> - </li> - """ - response = mock.Mock(text=html.encode('utf-8')) - results = startpage.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['content'], '') diff --git a/tests/unit/engines/test_www1x.py b/tests/unit/engines/test_www1x.py index 9df8de6bf..40f5200fd 100644 --- a/tests/unit/engines/test_www1x.py +++ b/tests/unit/engines/test_www1x.py @@ -12,46 +12,3 @@ class TestWww1xEngine(SearxTestCase): self.assertTrue('url' in params) self.assertTrue(query in params['url']) self.assertTrue('1x.com' in params['url']) - - def test_response(self): - self.assertRaises(AttributeError, www1x.response, None) - self.assertRaises(AttributeError, www1x.response, []) - self.assertRaises(AttributeError, www1x.response, '') - self.assertRaises(AttributeError, www1x.response, '[]') - - response = mock.Mock(text='<html></html>') - self.assertEqual(www1x.response(response), []) - html = """ - <?xml version="1.0" encoding="UTF-8"?><!DOCTYPE characters - [ - <!ELEMENT characters (character*) > - <!ELEMENT character (#PCDATA ) > - - <!ENTITY iexcl "¡" > - <!ENTITY cent "¢" > - <!ENTITY pound "£" > - ] - ><root><searchresult><![CDATA[<table border="0" cellpadding="0" cellspacing="0" width="100%"> - <tr> - <td style="min-width: 220px;" valign="top"> - <div style="font-size: 30px; margin: 0px 0px 20px 0px;">Photos</div> - <div> - <a href="/photo/123456" class="dynamiclink"> -<img border="0" class="searchresult" src="/images/user/testimage-123456.jpg" style="width: 125px; height: 120px;"> - </a> - <a title="sjoerd lammers street photography" href="/member/sjoerdlammers" class="dynamiclink"> -<img border="0" class="searchresult" src="/images/profile/60c48b394c677d2fa4d9e7d263aabf44-square.jpg"> - </a> - </div> - </td> - </table> - ]]></searchresult></root> - """ - response = mock.Mock(text=html) - results = www1x.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) - self.assertEqual(results[0]['url'], 'https://1x.com/photo/123456') - self.assertEqual(results[0]['thumbnail_src'], 'https://1x.com/images/user/testimage-123456.jpg') - self.assertEqual(results[0]['content'], '') - self.assertEqual(results[0]['template'], 'images.html') |