diff options
Diffstat (limited to 'tests/unit')
25 files changed, 492 insertions, 279 deletions
diff --git a/tests/unit/engines/seedpeer_fixture.html b/tests/unit/engines/seedpeer_fixture.html new file mode 100644 index 000000000..28207bfad --- /dev/null +++ b/tests/unit/engines/seedpeer_fixture.html @@ -0,0 +1,110 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> + <html xmlns="http://www.w3.org/1999/xhtml"> + <head> + </head> + <body> + <div id="header"> + <div id="whoIsYou"> + <a href="/lang.php"><small>SeedPeer in your own language?</small></a> <a href="http://www.seedpeer.eu"><img src="/images/flags/uk.gif" width="16px" alt="Torrents EN" /></a> <a href="http://spanish.seedpeer.eu"><img src="/images/flags/es.gif" width="16px" alt="Torrents ES" /></a> <a href="http://german.seedpeer.eu"><img src="/images/flags/de.gif" width="16px" alt="Torrents DE" /></a> <a href="http://french.seedpeer.eu"><img src="/images/flags/fr.gif" width="16px" alt="Torrents FR" /></a> <a href="http://portuguese.seedpeer.eu"><img src="/images/flags/pt.gif" width="16px" alt="Torrents Portuguese" /></a> <a href="http://swedish.seedpeer.eu"><img src="/images/flags/se.gif" width="16px" alt="Torrents Sweden" /></a> + </div> + + <script type="text/javascript"> + whoIsYou(); + </script> + <div id="search"> + <form action="/search.php" method="get"> + <input id="topsearchbar" name="search" value="narcos season 2" /> + <input type="submit" class="searchbutton" value="Torrents" /> + <input style="color:#000" type="submit" class="searchbutton" name="usenet" value="Usenet Binaries" /> + </form> + <div id="suggestion"></div> + </div> + <div id="logo"><a href="/"><img src="/images/logo2.gif" alt="Seedpeer homepage" width="415" height="143" /></a></div> + <div id="subtext"><a href="/">Home</a> > <a href="/search.html">Torrent search</a> > Narcos season 2 | page 1</div> + </div> + <div id="nav"> + <ul> + <!-- + <li><font style="color:red;font-size:9px;font-weight:bold;">NEW</font><a title="Download TOP Games for FREE" rel="nofollow" href="http://www.bigrebelads.com/affiliate/index?ref=9301" target="_blank">FREE Games</a></li> + + --> + <li style="border-left:none" id="categories"><a title="Browse Torrent Categories" href="/browse.html">Categories</a> + <ul> + <li><a title="Browse Anime Torrents" href="/browse.html#6">Anime</a></li> + <li><a title="Browse Game Torrents" href="/browse.html#4">Games</a></li> + <li><a title="Browse Movie Torrents" href="/browse.html#1">Movies</a></li> + <li><a title="Browse Music Torrents" href="/browse.html#3">Music</a></li> + <li><a title="Browse Software Torrents" href="/browse.html#5">Software</a></li> + <li><a title="Browse TV Torrents" href="/browse.html#2">TV Shows</a></li> + <li><a title="Browse Other Torrents" href="/browse.html#7">Others</a></li> + </ul> + </li> + <li><a title="Upload A Torrents" href="/upload.html">Upload torrent</a></li> + <li id="verified"><a title="Verified Torrents" href="/verified.html">Verified</a></li> + <li id="searchoptions"><a title="Search Torrents" href="/search.html">Torrent search</a></li> + <li id="newsgroups"><a style="color:#212b3e" title="News Groups" href="/usenet.html">Usenet Binaries</a></li> + <li id="about" style="border-right:none"><a rel="nofollow" href="/faq.html">About Us</a> + <ul> + <li><a title="SeedPeer Statistics" href="/stats.html">Statistics</a></li> + <li><a title="Contact Us" href="/contact.html">Contact</a></li> + <li><a title="Frequently Asked Questions" href="/faq.html">FAQ</a></li> + <li><a title="SeedPeer API" href="http://api.seedpeer.eu">Our API</a></li> + <li><a title="SeedPeer Blog" href="/blog">Blog</a></li> + </ul> + </li> + <!--<li><a href="/toolbar.php">Our Toolbar</a></li>--> + </ul> + <div class="clear"></div> + </div> + <div id="body"><div id="pageTop"></div> + <div id="headerbox"><h1>Verified <font class="colored">Narcos season 2</font> torrents</h1></div><table width="100%"><tr><th> + <span style="float:right"> + <a href="/search/narcos-season-2/8/1.html"><img style="vertical-align:middle" src="/images/comments.gif" alt="comments" /></a> | + <a href="/search/narcos-season-2/7/1.html"><img style="vertical-align:middle" src="/images/ver.gif" alt="verified" /></a> + </span> + <a href="/search/narcos-season-2/1/1.html">Torrent name</a></th><th class="right"><a href="/search/narcos-season-2/2/1.html">Age</a></th><th class="right"><a href="/search/narcos-season-2/3/1.html">Size</a></th><th class="right"><a href="/search/narcos-season-2/4/1.html">Seeds</a></th><th class="right"><a href="/search/narcos-season-2/5/1.html">Peers</a></th><th class="center"><a href="/search/narcos-season-2/6/1.html">Health</a></th><td class="tableAd" rowspan="6"><iframe src="http://creative.wwwpromoter.com/13689?d=300x250" width="300" height="250" style="border: none;" frameborder="0" scrolling="no"></iframe></td></tr><tr class=""><td><a class="pblink" id="pblink_table_item_1" href="" data-tad="431726" data-last-search="narcos+season+2" target="_blank" rel="nofollow"><strong class='colored'>Narcos season 2</strong> Full Version</a></td><td class="right">20 hours</td><td class="right">681.3 MB</td><td class="right"><font color="green">28</font> </td><td class="right"><font color="navy">654</font> </td><td class="center"><img src="/images/h5.gif" alt="Health" /></td></tr><tr class="tdark"><td><a class="pblink" id="pblink_table_item_2" href="" data-tad="431727" data-url="narcos+season+2" target="_blank" rel="nofollow"><strong class='colored'>Narcos season 2</strong> Trusted Source</a></td><td class="right">12 hours</td><td class="right">787.1 MB</td><td class="right"><font color="green">64</font> </td><td class="right"><font color="navy">220</font> </td><td class="center"><img src="/images/h5.gif" alt="Health" /></td></tr><tr class=""><td><a class="pblink" id="pblink_table_item_3" href="" data-tad="431729" data-last-search="narcos+season+2" target="_blank" rel="nofollow"><strong class='colored'>Full Narcos season 2 Download</strong></a> <small><a class="pblink" id="pblink_table_item_4" href="" data-tad="431729" data-last-search="narcos+season+2" target="_blank" rel="nofollow">Usenet</a></small></td><td class="right">24 hours</td><td class="right">775.5 MB</td><td class="right"><font color="green">60</font> </td><td class="right"><font color="navy">236</font> </td><td class="center"><img src="/images/h5.gif" alt="Health" /></td></tr><tr class="tdark"><td><a class="pblink" id="pblink_table_item_5" href="" data-tad="431730" data-last-search="narcos+season+2" target="_blank" rel="nofollow"><strong class='colored'>Narcos season 2</strong> 2014 - DIRECT STREAMING</a> <small><a class="pblink" id="pblink_table_item_6" href="" data-tad="431729" data-last-search="narcos+season+2" target="_blank" rel="nofollow">Movies</a></small></td><td class="right">17 hours</td><td class="right">654.1 MB</td><td class="right"><font color="green">2</font> </td><td class="right"><font color="navy">391</font> </td><td class="center"><img src="/images/h5.gif" alt="Health" /></td></tr><tr class=""><td><a class="pblink" id="pblink_table_item_7" href="" data-tad="431731" data-last-search="narcos+season+2" target="_blank" rel="nofollow"><strong class='colored'>Narcos season 2</strong> 2014</a> <small><a class="pblink" id="pblink_table_item_8" href="" data-tad="431729" data-last-search="narcos+season+2" target="_blank" rel="nofollow">Movies</a></small></td><td class="right">20 hours</td><td class="right">754.5 MB</td><td class="right"><font color="green">21</font> </td><td class="right"><font color="navy">919</font> </td><td class="center"><img src="/images/h5.gif" alt="Health" /></td></tr></table><br /><br /><center><iframe src='http://creative.wwwpromoter.com/13689?d=728x90' width='728' height='90' style='border: none;' frameborder='0' scrolling='no'></iframe><center><span style="float:right;margin:1em .2em 0 0"><a title="Download at the speed of your connection" href="/usenet.php?search=narcos+season+2"><img src="/images/dlf.gif" alt="Search Binaries" /></a></span><div style="margin-bottom:1em;margin-right:290px" id="headerbox"><h1><a href="/searchfeed/narcos+season+2.xml" target="_blank" title="SeedPeer RSS Torrent Search Feed fornarcos season 2"><img src="/images/feedIcon.png" border="0" /></a> 2 <font class="colored">Narcos season 2</font> Torrents were found</h1></div><table width="100%"><tr><th> + <span style="float:right"> + <a href="/search/narcos-season-2/8/1.html"><img style="vertical-align:middle" src="/images/comments.gif" alt="comments" /></a> | + <a href="/search/narcos-season-2/7/1.html"><img style="vertical-align:middle" src="/images/ver.gif" alt="verified" /></a> + </span> + <a href="/search/narcos-season-2/1/1.html">Torrent name</a></th><th class="right"><a href="/search/narcos-season-2/2/1.html">Age</a></th><th class="right"><a href="/search/narcos-season-2/3/1.html">Size</a></th><th class="right"><a href="/search/narcos-season-2/4/1.html">Seeds</a></th><th class="right"><a href="/search/narcos-season-2/5/1.html">Peers</a></th><th class="center"><a href="/search/narcos-season-2/6/1.html">Health</a></th></tr><tr class=""><td><small class="comments"><a href="http://www.facebook.com/sharer.php?t=Download%20<strong class='colored'>Narcos</strong> <strong class='colored'>Season</strong> <strong class='colored'>2</strong> Complete 7<strong class='colored'>2</strong>0p WebRip EN-SUB x<strong class='colored'>2</strong>64-[MULVAcoded] S0<strong class='colored'>2</strong>%20 torrent&u=http://seedpeer.seedpeer.eu/details/11686840/Narcos-Season-2-Complete-720p-WebRip-EN-SUB-x264-[MULVAcoded]-S02.html"><img src="/images/facebook.png" alt="Add to Facebook" width="14" height="14" /></a></small><a href="/details/11686840/Narcos-Season-2-Complete-720p-WebRip-EN-SUB-x264-[MULVAcoded]-S02.html"><strong class='colored'>Narcos</strong> <strong class='colored'>Season</strong> <strong class='colored'>2</strong> Complete 7<strong class='colored'>2</strong>0p WebRip EN-SUB x<strong class='colored'>2</strong>64-[MULVAcoded] S0<strong class='colored'>2</strong> <small><a href="/browse.html#11686840"></a></small></a></td><td class="right">19 hours</td><td class="right">4.39 GB</td><td class="right"><font color="green">715</font> </td><td class="right"><font color="navy">183</font> </td><td class="center"><img src="/images/h5.gif" alt="Health" width="40" height="11" /></td></tr><tr class="tdark"><td><small class="comments"><a href="http://www.facebook.com/sharer.php?t=Download%20<strong class='colored'>Narcos</strong> - <strong class='colored'>Season</strong> <strong class='colored'>2</strong> - 7<strong class='colored'>2</strong>0p WEBRiP - x<strong class='colored'>2</strong>65 HEVC - ShAaNiG%20 torrent&u=http://seedpeer.seedpeer.eu/details/11685972/Narcos---Season-2---720p-WEBRiP---x265-HEVC---ShAaNiG.html"><img src="/images/facebook.png" alt="Add to Facebook" width="14" height="14" /></a></small><a href="/details/11685972/Narcos---Season-2---720p-WEBRiP---x265-HEVC---ShAaNiG.html"><strong class='colored'>Narcos</strong> - <strong class='colored'>Season</strong> <strong class='colored'>2</strong> - 7<strong class='colored'>2</strong>0p WEBRiP - x<strong class='colored'>2</strong>65 HEVC - ShAaNiG <small><a href="/browse.html#11685972"></a></small></a></td><td class="right">1 day</td><td class="right">2.48 GB</td><td class="right"><font color="green">861</font> </td><td class="right"><font color="navy">332</font> </td><td class="center"><img src="/images/h5.gif" alt="Health" width="40" height="11" /></td></tr></table><div id="headerbox"><h1>Related searches for: <font class="colored">Narcos season 2</font></h1></div><div id="search_suggestions"><br />Other suggested searches: </div><br /><a href="http://torrentz2.eu/search?f=narcos-season-2">Search for "narcos-season-2" on Torrentz2.eu</a><br /><a href="http://torrent-finder.info/show.php?q=narcos-season-2">Search for "narcos-season-2" on Torrent-Finder</a><br /><center><iframe src='http://creative.wwwpromoter.com/13689?d=300x250' width='300' height='250' style='border: none;' frameborder='0' scrolling='no'></iframe> <iframe src='http://creative.wwwpromoter.com/13689?d=300x250' width='300' height='250' style='border: none;' frameborder='0' scrolling='no'></iframe> <iframe src='http://creative.wwwpromoter.com/13689?d=300x250' width='300' height='250' style='border: none;' frameborder='0' scrolling='no'></iframe></center><div id="footer"> + <table width="100%"> + <tr> + <td width="30%"> + <h2>Torrents Download</h2> + <a href="/">Torrent search</a><br /> + <a href="/browse.html">Browse categories</a><br /> + <a href="/verified.html">Verified Torrents</a><br /> + <a href="/order-date.html">Today's torrents</a><br /> + <a href="/yesterday.html">Yesterday's torrents</a><br /> + <a href="/stats.html">Statistics</a><br /> + <br /> + <a href="/faq.html#copyright"><strong>Copyright & Removal</strong></a> + </td> + <td width="30%"><h2>Cool Stuff</h2> + <a href="/promotional.php">Promotional</a><br /> + <a href="/contact.html">Advertising Information</a><br /> + <strong><a href="/plugins.php" title="Add a search plugin to Firefox or Internet Explorer">Search Plugin <span style="color:red">*</span></a></strong><br /> + <a href="http://www.utorrent.com">µTorrent Client</a><br /> + <a href="/blog">Seedpeer Blog</a><br /> + </td> + <td width="30%"><h2>Links</h2> + <a href="http://www.sumotorrent.com" target="_blank"><strong>SumoTorrent</strong></a><br /> + <a href="http://www.torrent-finder.info" target="_blank"><strong>Torrent Finder</strong></a><br /> + <a href="http://www.torrentpond.com" target="_blank"><strong>TorrentPond</strong></a><br /> + <a href="https://www.limetorrents.cc" target="_blank">LimeTorrents.cc</a><br /> + <a href="http://www.torrents.to/" target="_blank">Torrents.to</a><br /> + <a href="http://www.torrentfunk.com" target="_blank">TorrentFunk</a><br /> + <a href="https://monova.org" target="_blank">Monova</a><br /> + <a href="http://www.torrentroom.com" target="_blank">TorrentRoom</a><br /> + <a href="http://www.katcr.co/" target="_blank">Kickass Torrents Community</a><br /> + </td> + <td width="10%"><div id="bottomlogo"></div></td> + </tr> + </table> + <br /> + <br /> + </div> + </div> + </body> + </html>
\ No newline at end of file diff --git a/tests/unit/engines/test_bing.py b/tests/unit/engines/test_bing.py index bce221440..886584229 100644 --- a/tests/unit/engines/test_bing.py +++ b/tests/unit/engines/test_bing.py @@ -14,14 +14,12 @@ class TestBingEngine(SearxTestCase): params = bing.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) + self.assertTrue('language%3AFR' in params['url']) self.assertTrue('bing.com' in params['url']) - self.assertTrue('SRCHHPGUSR' in params['cookies']) - self.assertTrue('fr' in params['cookies']['SRCHHPGUSR']) dicto['language'] = 'all' params = bing.request(query, dicto) - self.assertTrue('SRCHHPGUSR' in params['cookies']) - self.assertTrue('en' in params['cookies']['SRCHHPGUSR']) + self.assertTrue('language' not in params['url']) def test_response(self): self.assertRaises(AttributeError, bing.response, None) diff --git a/tests/unit/engines/test_bing_images.py b/tests/unit/engines/test_bing_images.py index 9d8ec18af..cc256f51e 100644 --- a/tests/unit/engines/test_bing_images.py +++ b/tests/unit/engines/test_bing_images.py @@ -13,6 +13,7 @@ class TestBingImagesEngine(SearxTestCase): dicto['pageno'] = 1 dicto['language'] = 'fr_FR' dicto['safesearch'] = 1 + dicto['time_range'] = '' params = bing_images.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) diff --git a/tests/unit/engines/test_bing_news.py b/tests/unit/engines/test_bing_news.py index a64d59b7b..b6793f7be 100644 --- a/tests/unit/engines/test_bing_news.py +++ b/tests/unit/engines/test_bing_news.py @@ -12,6 +12,7 @@ class TestBingNewsEngine(SearxTestCase): dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['language'] = 'fr_FR' + dicto['time_range'] = '' params = bing_news.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) @@ -22,6 +23,13 @@ class TestBingNewsEngine(SearxTestCase): params = bing_news.request(query, dicto) 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 = bing_news.request(query, dicto) + self.assertEqual({}, params['url']) + def test_response(self): self.assertRaises(AttributeError, bing_news.response, None) self.assertRaises(AttributeError, bing_news.response, []) diff --git a/tests/unit/engines/test_deezer.py b/tests/unit/engines/test_deezer.py index cfef852af..5b9f55c33 100644 --- a/tests/unit/engines/test_deezer.py +++ b/tests/unit/engines/test_deezer.py @@ -42,7 +42,7 @@ class TestDeezerEngine(SearxTestCase): self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'Title of track') self.assertEqual(results[0]['url'], 'https://www.deezer.com/track/1094042') - self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track') + self.assertEqual(results[0]['content'], 'Artist Name - Album Title - Title of track') self.assertTrue('100' in results[0]['embedded']) json = r""" diff --git a/tests/unit/engines/test_deviantart.py b/tests/unit/engines/test_deviantart.py index 75c59f760..bd2cf182f 100644 --- a/tests/unit/engines/test_deviantart.py +++ b/tests/unit/engines/test_deviantart.py @@ -7,8 +7,8 @@ from searx.testing import SearxTestCase class TestDeviantartEngine(SearxTestCase): def test_request(self): - query = 'test_query' dicto = defaultdict(dict) + query = 'test_query' dicto['pageno'] = 0 dicto['time_range'] = '' params = deviantart.request(query, dicto) @@ -16,6 +16,13 @@ class TestDeviantartEngine(SearxTestCase): self.assertTrue(query in params['url']) self.assertTrue('deviantart.com' in params['url']) + def test_no_url_in_request_year_time_range(self): + dicto = defaultdict(dict) + query = 'test_query' + 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, []) diff --git a/tests/unit/engines/test_digbt.py b/tests/unit/engines/test_digbt.py new file mode 100644 index 000000000..31a1b03a4 --- /dev/null +++ b/tests/unit/engines/test_digbt.py @@ -0,0 +1,61 @@ +from collections import defaultdict +import mock +from searx.engines import digbt +from searx.testing import SearxTestCase + + +class TestDigBTEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = digbt.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('digbt.org', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, digbt.response, None) + self.assertRaises(AttributeError, digbt.response, []) + self.assertRaises(AttributeError, digbt.response, '') + self.assertRaises(AttributeError, digbt.response, '[]') + + response = mock.Mock(content='<html></html>') + self.assertEqual(digbt.response(response), []) + + html = """ + <table class="table"> + <tr><td class="x-item"> + <div> + <a title="The Big Bang Theory" class="title" href="/The-Big-Bang-Theory-d2.html"> + The Big <span class="highlight">Bang</span> Theory + </a> + <span class="ctime"><span style="color:red;">4 hours ago</span></span> + </div> + <div class="files"> + <ul> + <li>The Big Bang Theory 2.9 GB</li> + <li>....</li> + </ul> + </div> + <div class="tail"> + Files: 1 Size: 2.9 GB Downloads: 1 Updated: <span style="color:red;">4 hours ago</span> + + <a class="title" href="magnet:?xt=urn:btih:a&dn=The+Big+Bang+Theory"> + <span class="glyphicon glyphicon-magnet"></span> magnet-link + </a> + + </div> + </td></tr> + </table> + """ + response = mock.Mock(content=html) + results = digbt.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'The Big Bang Theory') + self.assertEqual(results[0]['url'], 'https://digbt.org/The-Big-Bang-Theory-d2.html') + self.assertEqual(results[0]['content'], 'The Big Bang Theory 2.9 GB ....') + self.assertEqual(results[0]['filesize'], 3113851289) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:a&dn=The+Big+Bang+Theory') diff --git a/tests/unit/engines/test_duckduckgo.py b/tests/unit/engines/test_duckduckgo.py index cb866d396..734f2c39e 100644 --- a/tests/unit/engines/test_duckduckgo.py +++ b/tests/unit/engines/test_duckduckgo.py @@ -19,6 +19,13 @@ class TestDuckduckgoEngine(SearxTestCase): self.assertIn('duckduckgo.com', params['url']) self.assertIn('ch-de', params['url']) + def test_no_url_in_request_year_time_range(self): + dicto = defaultdict(dict) + query = 'test_query' + dicto['time_range'] = 'year' + params = duckduckgo.request(query, dicto) + self.assertEqual({}, params['url']) + def test_response(self): self.assertRaises(AttributeError, duckduckgo.response, None) self.assertRaises(AttributeError, duckduckgo.response, []) diff --git a/tests/unit/engines/test_flickr.py b/tests/unit/engines/test_flickr.py index 2d7472a92..be97647ce 100644 --- a/tests/unit/engines/test_flickr.py +++ b/tests/unit/engines/test_flickr.py @@ -52,7 +52,7 @@ class TestFlickrEngine(SearxTestCase): self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') self.assertTrue('o.jpg' in results[0]['img_src']) self.assertTrue('n.jpg' in results[0]['thumbnail_src']) - self.assertTrue('Owner' in results[0]['content']) + self.assertTrue('Owner' in results[0]['author']) self.assertTrue('Description' in results[0]['content']) json = r""" @@ -76,7 +76,7 @@ class TestFlickrEngine(SearxTestCase): self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') self.assertTrue('z.jpg' in results[0]['img_src']) self.assertTrue('z.jpg' in results[0]['thumbnail_src']) - self.assertTrue('Owner' in results[0]['content']) + self.assertTrue('Owner' in results[0]['author']) self.assertTrue('Description' in results[0]['content']) json = r""" @@ -100,7 +100,7 @@ class TestFlickrEngine(SearxTestCase): self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/66847915@N08/15751017054') self.assertTrue('o.jpg' in results[0]['img_src']) self.assertTrue('o.jpg' in results[0]['thumbnail_src']) - self.assertTrue('Owner' in results[0]['content']) + self.assertTrue('Owner' in results[0]['author']) self.assertTrue('Description' in results[0]['content']) json = r""" diff --git a/tests/unit/engines/test_flickr_noapi.py b/tests/unit/engines/test_flickr_noapi.py index 42f38f90b..5f8b069e3 100644 --- a/tests/unit/engines/test_flickr_noapi.py +++ b/tests/unit/engines/test_flickr_noapi.py @@ -15,6 +15,7 @@ class TestFlickrNoapiEngine(SearxTestCase): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 + dicto['time_range'] = '' params = flickr_noapi.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) @@ -144,7 +145,7 @@ class TestFlickrNoapiEngine(SearxTestCase): self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') self.assertIn('k.jpg', results[0]['img_src']) self.assertIn('n.jpg', results[0]['thumbnail_src']) - self.assertIn('Owner', results[0]['content']) + self.assertIn('Owner', results[0]['author']) # no n size, only the z size json = """ @@ -187,7 +188,7 @@ class TestFlickrNoapiEngine(SearxTestCase): self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') self.assertIn('z.jpg', results[0]['img_src']) self.assertIn('z.jpg', results[0]['thumbnail_src']) - self.assertIn('Owner', results[0]['content']) + self.assertIn('Owner', results[0]['author']) # no z or n size json = """ @@ -230,7 +231,7 @@ class TestFlickrNoapiEngine(SearxTestCase): self.assertEqual(results[0]['url'], 'https://www.flickr.com/photos/59729010@N00/14001294434') self.assertIn('o.jpg', results[0]['img_src']) self.assertIn('o.jpg', results[0]['thumbnail_src']) - self.assertIn('Owner', results[0]['content']) + self.assertIn('Owner', results[0]['author']) # no image test json = """ diff --git a/tests/unit/engines/test_google_news.py b/tests/unit/engines/test_google_news.py index 31d674121..6454dde47 100644 --- a/tests/unit/engines/test_google_news.py +++ b/tests/unit/engines/test_google_news.py @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- + from collections import defaultdict import mock from searx.engines import google_news @@ -11,16 +13,16 @@ class TestGoogleNewsEngine(SearxTestCase): dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['language'] = 'fr_FR' + dicto['time_range'] = 'w' params = google_news.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) - self.assertIn('googleapis.com', params['url']) self.assertIn('fr', params['url']) dicto['language'] = 'all' params = google_news.request(query, dicto) self.assertIn('url', params) - self.assertIn('en', params['url']) + self.assertNotIn('fr', params['url']) def test_response(self): self.assertRaises(AttributeError, google_news.response, None) @@ -34,103 +36,15 @@ class TestGoogleNewsEngine(SearxTestCase): response = mock.Mock(text='{"data": []}') self.assertEqual(google_news.response(response), []) - json = """ - { - "responseData": { - "results": [ - { - "GsearchResultClass": "GnewsSearch", - "clusterUrl": "http://news.google.com/news/story?ncl=d2d3t1LMDpNIj2MPPhdTT0ycN4sWM&hl=fr&ned=fr", - "content": "This is the content", - "unescapedUrl": "http://this.is.the.url", - "url": "http://this.is.the.url", - "title": "This is the title", - "titleNoFormatting": "This is the title", - "location": "", - "publisher": "Jeux Actu", - "publishedDate": "Fri, 30 Jan 2015 11:00:25 -0800", - "signedRedirectUrl": "http://news.google.com/", - "language": "fr", - "image": { - "url": "http://i.jeuxactus.com/datas/jeux/d/y/dying-light/vu/dying-light-54cc080b568fb.jpg", - "tbUrl": "http://t1.gstatic.com/images?q=tbn:ANd9GcSF4yYrs9Ycw23DGiOSAZ-5SEPXYwG3LNs", - "originalContextUrl": "http://www.jeuxactu.com/test-dying-light-sur-ps4-97208.htm", - "publisher": "Jeux Actu", - "tbWidth": 80, - "tbHeight": 30 - }, - "relatedStories": [ - { - "unescapedUrl": "http://www.jeuxvideo.com/test/415823/dying-light.htm", - "url": "http%3A%2F%2Fwww.jeuxvideo.com%2Ftest%2F415823%2Fdying-light.htm", - "title": "<b>Test</b> du jeu Dying Light - jeuxvideo.com", - "titleNoFormatting": "Test du jeu Dying Light - jeuxvideo.com", - "location": "", - "publisher": "JeuxVideo.com", - "publishedDate": "Fri, 30 Jan 2015 08:52:30 -0800", - "signedRedirectUrl": "http://news.google.com/news/url?sa=T&", - "language": "fr" - } - ] - } - ] - }, - "responseDetails": null, - "responseStatus": 200 - } - """ - response = mock.Mock(text=json) + html = u""" +<div class="g"> +<div class="ts _V6c _Zmc _XO _knc _d7c"><a class="top _vQb _mnc" href="http://this.is.the.url" onmousedown="return rwt(this,'','','','5','AFQjCNGixEtJGC3qTB9pYFLXlRj8XXwdiA','','0ahUKEwiG7O_M5-rQAhWDtRoKHd0RD5QQvIgBCCwwBA','','',event)"><img class="th _lub" id="news-thumbnail-image-52779299683347" src="data:image/jpeg;base64,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" alt="A(z) south témájának képe a következőből: CBC.ca" data-deferred="1" onload="google.aft&&google.aft(this)"></a><div class="_cnc"><h3 class="r _U6c"><a class="l _HId" href="http://this.is.the.url" onmousedown="return rwt(this,'','','','5','AFQjCNGixEtJGC3qTB9pYFLXlRj8XXwdiA','','0ahUKEwiG7O_M5-rQAhWDtRoKHd0RD5QQqQIILSgAMAQ','','',event)">Meet Thuli Madonsela — <em>South</em> Africa's conscience</a></h3><div class="slp"><span class="_tQb _IId">CBC.ca</span><span class="_v5">-</span><span class="f nsa _uQb">9 órával ezelőtt</span></div><div class="st"><em>South</em> African Public Protector</div></div><div class="_Xmc card-section"><a class="_sQb" href="http://www.news24.com/Columnists/Mpumelelo_Mkhabela/who-really-governs-south-africa-20161209" onmousedown="return rwt(this,'','','','5','AFQjCNHhc2MnYSZ5T4COqInzvgoju5k5bA','','0ahUKEwiG7O_M5-rQAhWDtRoKHd0RD5QQuogBCC4oATAE','','',event)">Who really governs <em>South</em> Africa?</a><br><span class="_Wmc _GId">Vélemény</span><span class="_v5">-</span><span class="_tQb _IId">News24</span><span class="_v5">-</span><span class="f nsa _uQb">2016. dec. 8.</span></div><div class="_Vmc"></div></div> +</div> + """ # noqa + response = mock.Mock(text=html) results = google_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]['title'], u'Meet Thuli Madonsela \u2014 South Africa\'s conscience') self.assertEqual(results[0]['url'], 'http://this.is.the.url') - self.assertEqual(results[0]['content'], 'This is the content') - - json = """ - { - "responseData": { - "results": [ - { - "GsearchResultClass": "GnewsSearch", - "clusterUrl": "http://news.google.com/news/story?ncl=d2d3t1LMDpNIj2MPPhdTT0ycN4sWM&hl=fr&ned=fr", - "content": "This is the content", - "unescapedUrl": "http://this.is.the.url", - "title": "This is the title", - "titleNoFormatting": "This is the title", - "location": "", - "publisher": "Jeux Actu", - "publishedDate": "Fri, 30 Jan 2015 11:00:25 -0800", - "signedRedirectUrl": "http://news.google.com/news/", - "language": "fr", - "image": { - "url": "http://i.jeuxactus.com/datas/jeux/d/y/dying-light/vu/dying-light-54cc080b568fb.jpg", - "tbUrl": "http://t1.gstatic.com/images?q=tbn:b_6f-OSAZ-5SEPXYwG3LNs", - "originalContextUrl": "http://www.jeuxactu.com/test-dying-light-sur-ps4-97208.htm", - "publisher": "Jeux Actu", - "tbWidth": 80, - "tbHeight": 30 - } - } - ] - }, - "responseDetails": null, - "responseStatus": 200 - } - """ - response = mock.Mock(text=json) - results = google_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) - - json = """ - { - "responseData": {}, - "responseDetails": null, - "responseStatus": 200 - } - """ - response = mock.Mock(text=json) - results = google_news.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) + self.assertEqual(results[0]['content'], 'South African Public Protector') diff --git a/tests/unit/engines/test_kickass.py b/tests/unit/engines/test_kickass.py index 4cfcaa63c..3a75c6697 100644 --- a/tests/unit/engines/test_kickass.py +++ b/tests/unit/engines/test_kickass.py @@ -14,7 +14,7 @@ class TestKickassEngine(SearxTestCase): params = kickass.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) - self.assertIn('kickass.to', params['url']) + self.assertIn('kickass.cd', params['url']) self.assertFalse(params['verify']) def test_response(self): @@ -84,7 +84,7 @@ class TestKickassEngine(SearxTestCase): </span> </div> </td> - <td class="nobr center">449 <span>bytes</span></td> + <td class="nobr center">449 bytes</td> <td class="center">4</td> <td class="center">2 years</td> <td class="green center">10</td> @@ -97,8 +97,8 @@ class TestKickassEngine(SearxTestCase): self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'https://kickass.to/url.html') - self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') + self.assertEqual(results[0]['url'], 'https://kickass.cd/url.html') + self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') self.assertEqual(results[0]['seed'], 10) self.assertEqual(results[0]['leech'], 1) self.assertEqual(results[0]['filesize'], 449) @@ -191,7 +191,7 @@ class TestKickassEngine(SearxTestCase): </span> </div> </td> - <td class="nobr center">1 <span>KB</span></td> + <td class="nobr center">1 KiB</td> <td class="center">4</td> <td class="center">2 years</td> <td class="green center">10</td> @@ -235,7 +235,7 @@ class TestKickassEngine(SearxTestCase): </span> </div> </td> - <td class="nobr center">1 <span>MB</span></td> + <td class="nobr center">1 MiB</td> <td class="center">4</td> <td class="center">2 years</td> <td class="green center">9</td> @@ -279,7 +279,7 @@ class TestKickassEngine(SearxTestCase): </span> </div> </td> - <td class="nobr center">1 <span>GB</span></td> + <td class="nobr center">1 GiB</td> <td class="center">4</td> <td class="center">2 years</td> <td class="green center">8</td> @@ -323,7 +323,7 @@ class TestKickassEngine(SearxTestCase): </span> </div> </td> - <td class="nobr center">1 <span>TB</span></td> + <td class="nobr center">1 TiB</td> <td class="center">4</td> <td class="center">2 years</td> <td class="green center">7</td> @@ -367,7 +367,7 @@ class TestKickassEngine(SearxTestCase): </span> </div> </td> - <td class="nobr center">z <span>bytes</span></td> + <td class="nobr center">z bytes</td> <td class="center">r</td> <td class="center">2 years</td> <td class="green center">a</td> @@ -380,17 +380,17 @@ class TestKickassEngine(SearxTestCase): self.assertEqual(type(results), list) self.assertEqual(len(results), 5) self.assertEqual(results[0]['title'], 'This should be the title') - self.assertEqual(results[0]['url'], 'https://kickass.to/url.html') - self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') + self.assertEqual(results[0]['url'], 'https://kickass.cd/url.html') + self.assertEqual(results[0]['content'], 'Posted by riri in Other > Unsorted') self.assertEqual(results[0]['seed'], 10) self.assertEqual(results[0]['leech'], 1) self.assertEqual(results[0]['files'], 4) self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETURL&dn=test') self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/53917.torrent?title=test') - self.assertEqual(results[0]['filesize'], 1024) - self.assertEqual(results[1]['filesize'], 1048576) - self.assertEqual(results[2]['filesize'], 1073741824) - self.assertEqual(results[3]['filesize'], 1099511627776) + self.assertEqual(results[0]['filesize'], 1000) + self.assertEqual(results[1]['filesize'], 1000000) + self.assertEqual(results[2]['filesize'], 1000000000) + self.assertEqual(results[3]['filesize'], 1000000000000) self.assertEqual(results[4]['seed'], 0) self.assertEqual(results[4]['leech'], 0) self.assertEqual(results[4]['files'], None) diff --git a/tests/unit/engines/test_pdbe.py b/tests/unit/engines/test_pdbe.py new file mode 100644 index 000000000..7aa8e2655 --- /dev/null +++ b/tests/unit/engines/test_pdbe.py @@ -0,0 +1,109 @@ +import mock +from collections import defaultdict +from searx.engines import pdbe +from searx.testing import SearxTestCase + + +class TestPdbeEngine(SearxTestCase): + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + params = pdbe.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue('ebi.ac.uk' in params['url']) + self.assertTrue('data' in params) + self.assertTrue('q' in params['data']) + self.assertTrue(query in params['data']['q']) + self.assertTrue('wt' in params['data']) + self.assertTrue('json' in params['data']['wt']) + self.assertTrue('method' in params) + self.assertTrue(params['method'] == 'POST') + + def test_response(self): + self.assertRaises(AttributeError, pdbe.response, None) + self.assertRaises(AttributeError, pdbe.response, []) + self.assertRaises(AttributeError, pdbe.response, '') + self.assertRaises(AttributeError, pdbe.response, '[]') + + json = """ +{ + "response": { + "docs": [ + { + "citation_title": "X-ray crystal structure of ferric Aplysia limacina myoglobin in different liganded states.", + "citation_year": 1993, + "entry_author_list": [ + "Conti E, Moser C, Rizzi M, Mattevi A, Lionetti C, Coda A, Ascenzi P, Brunori M, Bolognesi M" + ], + "journal": "J. Mol. Biol.", + "journal_page": "498-508", + "journal_volume": "233", + "pdb_id": "2fal", + "status": "REL", + "title": "X-RAY CRYSTAL STRUCTURE OF FERRIC APLYSIA LIMACINA MYOGLOBIN IN DIFFERENT LIGANDED STATES" + } + ], + "numFound": 1, + "start": 0 + }, + "responseHeader": { + "QTime": 0, + "params": { + "q": "2fal", + "wt": "json" + }, + "status": 0 + } +} +""" + + response = mock.Mock(text=json) + results = pdbe.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], + 'X-RAY CRYSTAL STRUCTURE OF FERRIC APLYSIA LIMACINA MYOGLOBIN IN DIFFERENT LIGANDED STATES') + self.assertEqual(results[0]['url'], pdbe.pdbe_entry_url.format(pdb_id='2fal')) + self.assertEqual(results[0]['img_src'], pdbe.pdbe_preview_url.format(pdb_id='2fal')) + self.assertTrue('Conti E' in results[0]['content']) + self.assertTrue('X-ray crystal structure of ferric Aplysia limacina myoglobin in different liganded states.' in + results[0]['content']) + self.assertTrue('1993' in results[0]['content']) + + # Testing proper handling of PDB entries marked as obsolete + json = """ +{ + "response": { + "docs": [ + { + "citation_title": "Obsolete entry test", + "citation_year": 2016, + "entry_author_list": ["Doe J"], + "journal": "J. Obs.", + "journal_page": "1-2", + "journal_volume": "1", + "pdb_id": "xxxx", + "status": "OBS", + "title": "OBSOLETE ENTRY TEST", + "superseded_by": "yyyy" + } + ], + "numFound": 1, + "start": 0 + }, + "responseHeader": { + "QTime": 0, + "params": { + "q": "xxxx", + "wt": "json" + }, + "status": 0 + } +} +""" + response = mock.Mock(text=json) + results = pdbe.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'OBSOLETE ENTRY TEST (OBSOLETE)') + self.assertTrue(results[0]['content'].startswith('<em>This entry has been superseded by')) diff --git a/tests/unit/engines/test_searchcode_doc.py b/tests/unit/engines/test_searchcode_doc.py index 7228613ed..d02bb7a44 100644 --- a/tests/unit/engines/test_searchcode_doc.py +++ b/tests/unit/engines/test_searchcode_doc.py @@ -56,9 +56,6 @@ class TestSearchcodeDocEngine(SearxTestCase): self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], '[Type] Namespace test') self.assertEqual(results[0]['url'], 'http://url') - self.assertIn('Synopsis', results[0]['content']) - self.assertIn('Type', results[0]['content']) - self.assertIn('test', results[0]['content']) self.assertIn('Description', results[0]['content']) json = r""" diff --git a/tests/unit/engines/test_seedpeer.py b/tests/unit/engines/test_seedpeer.py new file mode 100644 index 000000000..37b2de8e4 --- /dev/null +++ b/tests/unit/engines/test_seedpeer.py @@ -0,0 +1,51 @@ +import mock +from collections import defaultdict +from searx.engines import seedpeer +from searx.testing import SearxTestCase +from datetime import datetime + + +class TestSeedPeerEngine(SearxTestCase): + + html = '' + with open('./tests/unit/engines/seedpeer_fixture.html') as fixture: + html += fixture.read() + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = seedpeer.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('seedpeer.eu', params['url']) + + def test_response_raises_attr_error_on_empty_response(self): + self.assertRaises(AttributeError, seedpeer.response, None) + self.assertRaises(AttributeError, seedpeer.response, []) + self.assertRaises(AttributeError, seedpeer.response, '') + self.assertRaises(AttributeError, seedpeer.response, '[]') + + def test_response_returns_empty_list(self): + response = mock.Mock(text='<html></html>') + self.assertEqual(seedpeer.response(response), []) + + def test_response_returns_all_results(self): + response = mock.Mock(text=self.html) + results = seedpeer.response(response) + self.assertTrue(isinstance(results, list)) + self.assertEqual(len(results), 2) + + def test_response_returns_correct_results(self): + response = mock.Mock(text=self.html) + results = seedpeer.response(response) + self.assertEqual( + results[0]['title'], 'Narcos - Season 2 - 720p WEBRiP - x265 HEVC - ShAaNiG ' + ) + self.assertEqual( + results[0]['url'], + 'http://www.seedpeer.eu/details/11685972/Narcos---Season-2---720p-WEBRiP---x265-HEVC---ShAaNiG.html' + ) + self.assertEqual(results[0]['content'], '2.48 GB, 1 day') + self.assertEqual(results[0]['seed'], '861') + self.assertEqual(results[0]['leech'], '332') diff --git a/tests/unit/engines/test_spotify.py b/tests/unit/engines/test_spotify.py index fd274abbd..e37c344d2 100644 --- a/tests/unit/engines/test_spotify.py +++ b/tests/unit/engines/test_spotify.py @@ -90,7 +90,7 @@ class TestSpotifyEngine(SearxTestCase): self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'Title of track') self.assertEqual(results[0]['url'], 'https://open.spotify.com/track/2GzvFiedqW8hgqUpWcASZa') - self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track') + self.assertEqual(results[0]['content'], 'Artist Name - Album Title - Title of track') self.assertIn('1000', results[0]['embedded']) json = """ diff --git a/tests/unit/engines/test_vimeo.py b/tests/unit/engines/test_vimeo.py index 50b1cb563..c86b50a14 100644 --- a/tests/unit/engines/test_vimeo.py +++ b/tests/unit/engines/test_vimeo.py @@ -22,80 +22,15 @@ class TestVimeoEngine(SearxTestCase): self.assertRaises(AttributeError, vimeo.response, '') self.assertRaises(AttributeError, vimeo.response, '[]') - response = mock.Mock(text='<html></html>') - self.assertEqual(vimeo.response(response), []) + json = u""" +{"filtered":{"total":274641,"page":1,"per_page":18,"paging":{"next":"?sizes=590x332&page=2","previous":null,"first":"?sizes=590x332&page=1","last":"?sizes=590x332&page=15258"},"data":[{"is_staffpick":false,"is_featured":true,"type":"clip","clip":{"uri":"\\/videos\\/106557563","name":"Hot Rod Revue: The South","link":"https:\\/\\/vimeo.com\\/106557563","duration":4069,"created_time":"2014-09-19T03:38:04+00:00","privacy":{"view":"ptv"},"pictures":{"sizes":[{"width":"590","height":"332","link":"https:\\/\\/i.vimeocdn.com\\/video\\/489717884_590x332.jpg?r=pad","link_with_play_button":"https:\\/\\/i.vimeocdn.com\\/filter\\/overlay?src0=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F489717884_590x332.jpg&src1=http%3A%2F%2Ff.vimeocdn.com%2Fp%2Fimages%2Fcrawler_play.png"}]},"stats":{"plays":null},"metadata":{"connections":{"comments":{"total":0},"likes":{"total":5}},"interactions":[]},"user":{"name":"Cal Thorley","link":"https:\\/\\/vimeo.com\\/calthorley","pictures":{"sizes":[{"width":30,"height":30,"link":"https:\\/\\/i.vimeocdn.com\\/portrait\\/2545308_30x30?r=pad"},{"width":75,"height":75,"link":"https:\\/\\/i.vimeocdn.com\\/portrait\\/2545308_75x75?r=pad"},{"width":100,"height":100,"link":"https:\\/\\/i.vimeocdn.com\\/portrait\\/2545308_100x100?r=pad"},{"width":300,"height":300,"link":"https:\\/\\/i.vimeocdn.com\\/portrait\\/2545308_300x300?r=pad"}]}}}}]}}; - html = """ - <div id="browse_content" class="results_grid" data-search-id="696d5f8366914ec4ffec33cf7652de384976d4f4"> - <ul class="js-browse_list clearfix browse browse_videos browse_videos_thumbnails kane" - data-stream="c2VhcmNoOjo6ZGVzYzp7InF1ZXJ5IjoidGVzdCJ9"> - <li data-position="7" data-result-id="clip_79600943"> - <div class="clip_thumbnail"> - <a href="/videoid" class="js-result_url"> - <div class="thumbnail_wrapper"> - <img src="http://image.url.webp" class="js-clip_thumbnail_image"> - <div class="overlay overlay_clip_meta"> - <div class="meta_data_footer"> - <span class="clip_upload_date"> - <time datetime="2013-11-17T08:49:09-05:00" - title="dimanche 17 novembre 2013 08:49">Il y a 1 an</time> - </span> - <span class="clip_likes"> - <img src="https://f.vimeocdn.com/images_v6/svg/heart-icon.svg">2 215 - </span> - <span class="clip_comments"> - <img src="https://f.vimeocdn.com/images_v6/svg/comment-icon.svg">75 - </span> - <span class="overlay meta_data_footer clip_duration">01:12</span> - </div> - </div> - </div> - <span class="title">This is the title</span> - </a> - </div> - <div class="clip_thumbnail_attribution"> - <a href="/fedorshmidt"> - <img src="https://i.vimeocdn.com/portrait/6628061_100x100.jpg" class="avatar"> - <span class="display_name">Fedor Shmidt</span> - </a> - <span class="plays">2,1M lectures</span> - </div> - </li> - </ul> - </div> - """ - response = mock.Mock(text=html) +""" # noqa + response = mock.Mock(text=json) results = vimeo.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://vimeo.com/videoid') + self.assertEqual(results[0]['title'], u'Hot Rod Revue: The South') + self.assertEqual(results[0]['url'], 'https://vimeo.com/106557563') self.assertEqual(results[0]['content'], '') - self.assertEqual(results[0]['thumbnail'], 'http://image.url.webp') - self.assertIn('/videoid', results[0]['embedded']) - - html = """ - <ol class="js-browse_list clearfix browse browse_videos browse_videos_thumbnails kane" - data-stream="c2VhcmNoOjo6ZGVzYzp7InF1ZXJ5IjoidGVzdCJ9"> - <li id="clip_100785455" data-start-page="/search/page:1/sort:relevant/" data-position="1"> - <a href="/videoid" title="Futurama 3d (test shot)"> - <img src="http://image.url.webp" - srcset="http://i.vimeocdn.com/video/482375085_590x332.webp 2x" alt="" - class="thumbnail thumbnail_lg_wide"> - <div class="data"> - <p class="title"> - This is the title - </p> - <p class="meta"> - <time datetime="2014-07-15T04:16:27-04:00" - title="mardi 15 juillet 2014 04:16">Il y a 6 mois</time> - </p> - </div> - </a> - </li> - </ol> - """ - response = mock.Mock(text=html) - results = vimeo.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) + self.assertEqual(results[0]['thumbnail'], 'https://i.vimeocdn.com/video/489717884_590x332.jpg?r=pad') diff --git a/tests/unit/engines/test_wolframalpha_api.py b/tests/unit/engines/test_wolframalpha_api.py index 76404e192..64a64ceb3 100644 --- a/tests/unit/engines/test_wolframalpha_api.py +++ b/tests/unit/engines/test_wolframalpha_api.py @@ -103,7 +103,8 @@ class TestWolframAlphaAPIEngine(SearxTestCase): self.assertEqual(referer_url, results[0]['urls'][0]['url']) self.assertEqual('Wolfram|Alpha', results[0]['urls'][0]['title']) self.assertEqual(referer_url, results[1]['url']) - self.assertEqual('Wolfram|Alpha', results[1]['title']) + self.assertEqual('Wolfram|Alpha (input_plaintext)', results[1]['title']) + self.assertIn('result_plaintext', results[1]['content']) # test calc xml = """<?xml version='1.0' encoding='UTF-8'?> @@ -161,4 +162,5 @@ class TestWolframAlphaAPIEngine(SearxTestCase): self.assertEqual(referer_url, results[0]['urls'][0]['url']) self.assertEqual('Wolfram|Alpha', results[0]['urls'][0]['title']) self.assertEqual(referer_url, results[1]['url']) - self.assertEqual('Wolfram|Alpha', results[1]['title']) + self.assertEqual('Wolfram|Alpha (integral_plaintext)', results[1]['title']) + self.assertIn('integral_plaintext', results[1]['content']) diff --git a/tests/unit/engines/test_wolframalpha_noapi.py b/tests/unit/engines/test_wolframalpha_noapi.py index a8f73470e..982edd9f2 100644 --- a/tests/unit/engines/test_wolframalpha_noapi.py +++ b/tests/unit/engines/test_wolframalpha_noapi.py @@ -140,7 +140,8 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase): self.assertEqual(referer_url, results[0]['urls'][0]['url']) self.assertEqual('Wolfram|Alpha', results[0]['urls'][0]['title']) self.assertEqual(referer_url, results[1]['url']) - self.assertEqual('Wolfram|Alpha', results[1]['title']) + self.assertEqual('Wolfram|Alpha (input_plaintext)', results[1]['title']) + self.assertIn('result_plaintext', results[1]['content']) # test calc json = r""" @@ -219,4 +220,5 @@ class TestWolframAlphaNoAPIEngine(SearxTestCase): self.assertEqual(referer_url, results[0]['urls'][0]['url']) self.assertEqual('Wolfram|Alpha', results[0]['urls'][0]['title']) self.assertEqual(referer_url, results[1]['url']) - self.assertEqual('Wolfram|Alpha', results[1]['title']) + self.assertEqual('Wolfram|Alpha (integral_plaintext)', results[1]['title']) + self.assertIn('integral_plaintext', results[1]['content']) diff --git a/tests/unit/engines/test_www500px.py b/tests/unit/engines/test_www500px.py index 8df15b945..e50601da0 100644 --- a/tests/unit/engines/test_www500px.py +++ b/tests/unit/engines/test_www500px.py @@ -22,62 +22,13 @@ class TestWww500pxImagesEngine(SearxTestCase): self.assertRaises(AttributeError, www500px.response, '') self.assertRaises(AttributeError, www500px.response, '[]') - response = mock.Mock(text='<html></html>') - self.assertEqual(www500px.response(response), []) - - html = """ - <div class="photo"> - <a href="/this.should.be.the.url" data-ga-category="Photo Thumbnail" data-ga-action="Title"> - <img src="https://image.url/3.jpg?v=0" /> - </a> - <div class="details"> - <div class="inside"> - <div class="title"> - <a href="/photo/64312705/branch-out-by-oliver-turpin?feature="> - This is the title - </a> - </div> - <div class="info"> - <a href="/ChronicleUK" data-ga-action="Image" data-ga-category="Photo Thumbnail"> - This is the content - </a> - </div> - <div class="rating">44.8</div> - </div> - </div> - </div> - """ - response = mock.Mock(text=html) + json = """ +{"current_page":1,"total_pages":1000,"total_items":862178,"photos":[{"id":64531569,"user_id":111147,"name":"Grand Canyon Afternoon","description":"Looking west on a very windy winter afternoon.","camera":"Canon EOS 5D Mark II","lens":"EF24-105mm f/4L IS USM","focal_length":"28","iso":"200","shutter_speed":"1/1250","aperture":"6.3","times_viewed":4809,"rating":48.5,"status":1,"created_at":"2014-03-22T03:44:46-04:00","category":8,"location":null,"latitude":36.0323916666667,"longitude":-111.85273,"taken_at":"2014-02-27T14:10:43-05:00","hi_res_uploaded":2,"for_sale":true,"width":5476,"height":3651,"votes_count":108,"favorites_count":35,"comments_count":5,"nsfw":false,"sales_count":0,"for_sale_date":null,"highest_rating":91.9,"highest_rating_date":"2014-03-22T22:34:54-04:00","license_type":0,"converted":31,"collections_count":10,"crop_version":0,"privacy":false,"profile":true,"image_url":["https://drscdn.500px.org/photo/64531569/w%3D70_h%3D70/449d50817f28d85395e23bbb415b3cdb?v=0","https://drscdn.500px.org/photo/64531569/q%3D50_w%3D140_h%3D140/3e3e123734a596644ede78105268bdb2?v=0","https://drscdn.500px.org/photo/64531569/q%3D80_h%3D300/2ce2f61714aebdca710967dfdc3efb04","https://drscdn.500px.org/photo/64531569/q%3D80_h%3D450/c8ec030441f2c68b9bd40a114903348a","https://drscdn.500px.org/photo/64531569/q%3D80_h%3D600/ab6562d0581b359679ecc8ef2e939396","https://drscdn.500px.org/photo/64531569/q%3D80_m%3D1000/bd7dbc54a505e041a8c9a70dfa434272","https://drscdn.500px.org/photo/64531569/q%3D80_m%3D1500/eb4d7f8f6a32d3e5c168c2cb55d29c12","https://drscdn.500px.org/photo/64531569/q%3D80_m%3D2000/d519f91b8a568e7357a8a7fa1aabbe74","https://drscdn.500px.org/photo/64531569/m%3D2048/4c52fb18cc2b2b6f91a0d04609786507","https://drscdn.500px.org/photo/64531569/m%3D900/fb620ae39569ab4a421e9170a94b1a0f","https://drscdn.500px.org/photo/64531569/m%3D900_s%3D1_k%3D1_a%3D1/02b95ce64db090c1f94f890960974612?v=0"],"images":[{"size":1,"url":"https://drscdn.500px.org/photo/64531569/w%3D70_h%3D70/449d50817f28d85395e23bbb415b3cdb?v=0","https_url":"https://drscdn.500px.org/photo/64531569/w%3D70_h%3D70/449d50817f28d85395e23bbb415b3cdb?v=0","format":"jpeg"},{"size":2,"url":"https://drscdn.500px.org/photo/64531569/q%3D50_w%3D140_h%3D140/3e3e123734a596644ede78105268bdb2?v=0","https_url":"https://drscdn.500px.org/photo/64531569/q%3D50_w%3D140_h%3D140/3e3e123734a596644ede78105268bdb2?v=0","format":"jpeg"},{"size":4,"url":"https://drscdn.500px.org/photo/64531569/m%3D900/fb620ae39569ab4a421e9170a94b1a0f","https_url":"https://drscdn.500px.org/photo/64531569/m%3D900/fb620ae39569ab4a421e9170a94b1a0f","format":"jpeg"},{"size":14,"url":"https://drscdn.500px.org/photo/64531569/m%3D900_s%3D1_k%3D1_a%3D1/02b95ce64db090c1f94f890960974612?v=0","https_url":"https://drscdn.500px.org/photo/64531569/m%3D900_s%3D1_k%3D1_a%3D1/02b95ce64db090c1f94f890960974612?v=0","format":"jpeg"},{"size":31,"url":"https://drscdn.500px.org/photo/64531569/q%3D80_h%3D450/c8ec030441f2c68b9bd40a114903348a","https_url":"https://drscdn.500px.org/photo/64531569/q%3D80_h%3D450/c8ec030441f2c68b9bd40a114903348a","format":"jpeg"},{"size":32,"url":"https://drscdn.500px.org/photo/64531569/q%3D80_h%3D300/2ce2f61714aebdca710967dfdc3efb04","https_url":"https://drscdn.500px.org/photo/64531569/q%3D80_h%3D300/2ce2f61714aebdca710967dfdc3efb04","format":"jpeg"},{"size":33,"url":"https://drscdn.500px.org/photo/64531569/q%3D80_h%3D600/ab6562d0581b359679ecc8ef2e939396","https_url":"https://drscdn.500px.org/photo/64531569/q%3D80_h%3D600/ab6562d0581b359679ecc8ef2e939396","format":"jpeg"},{"size":34,"url":"https://drscdn.500px.org/photo/64531569/q%3D80_m%3D1000/bd7dbc54a505e041a8c9a70dfa434272","https_url":"https://drscdn.500px.org/photo/64531569/q%3D80_m%3D1000/bd7dbc54a505e041a8c9a70dfa434272","format":"jpeg"},{"size":35,"url":"https://drscdn.500px.org/photo/64531569/q%3D80_m%3D1500/eb4d7f8f6a32d3e5c168c2cb55d29c12","https_url":"https://drscdn.500px.org/photo/64531569/q%3D80_m%3D1500/eb4d7f8f6a32d3e5c168c2cb55d29c12","format":"jpeg"},{"size":36,"url":"https://drscdn.500px.org/photo/64531569/q%3D80_m%3D2000/d519f91b8a568e7357a8a7fa1aabbe74","https_url":"https://drscdn.500px.org/photo/64531569/q%3D80_m%3D2000/d519f91b8a568e7357a8a7fa1aabbe74","format":"jpeg"},{"size":2048,"url":"https://drscdn.500px.org/photo/64531569/m%3D2048/4c52fb18cc2b2b6f91a0d04609786507","https_url":"https://drscdn.500px.org/photo/64531569/m%3D2048/4c52fb18cc2b2b6f91a0d04609786507","format":"jpeg"}],"url":"/photo/64531569/grand-canyon-afternoon-by-todd-hakala","positive_votes_count":108,"converted_bits":31,"tags":["landscape","river","arizona","canyon","grand","colorado","south","southwest","az","west","rim","CanonGetaway"],"watermark":false,"image_format":"jpeg","licensing_requested":false,"licensing_suggested":false,"is_free_photo":false,"user":{"id":111147,"username":"ToddHakala","firstname":"Todd","lastname":"Hakala","city":"Albuquerque","country":"US","usertype":0,"fullname":"Todd Hakala","userpic_url":"https://pacdn.500px.org/111147/ea167926a64ce9b32e44cbec61e3af4f75b762cb/1.jpg?2","userpic_https_url":"https://pacdn.500px.org/111147/ea167926a64ce9b32e44cbec61e3af4f75b762cb/1.jpg?2","cover_url":"https://pacdn.500px.org/111147/ea167926a64ce9b32e44cbec61e3af4f75b762cb/cover_2048.jpg?8","upgrade_status":1,"store_on":true,"affection":5217,"avatars":{"default":{"https":"https://pacdn.500px.org/111147/ea167926a64ce9b32e44cbec61e3af4f75b762cb/1.jpg?2"},"large":{"https":"https://pacdn.500px.org/111147/ea167926a64ce9b32e44cbec61e3af4f75b762cb/2.jpg?2"},"small":{"https":"https://pacdn.500px.org/111147/ea167926a64ce9b32e44cbec61e3af4f75b762cb/3.jpg?2"},"tiny":{"https":"https://pacdn.500px.org/111147/ea167926a64ce9b32e44cbec61e3af4f75b762cb/4.jpg?2"}},"followers_count":171}}]} + """ # noqa + response = mock.Mock(text=json) results = www500px.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://500px.com/this.should.be.the.url') - self.assertEqual(results[0]['content'], 'This is the content') - self.assertEqual(results[0]['thumbnail_src'], 'https://image.url/3.jpg?v=0') - self.assertEqual(results[0]['img_src'], 'https://image.url/2048.jpg') - - html = """ - <a href="/this.should.be.the.url" data-ga-category="Photo Thumbnail" data-ga-action="Title"> - <img src="https://image.url/3.jpg?v=0" /> - </a> - <div class="details"> - <div class="inside"> - <div class="title"> - <a href="/photo/64312705/branch-out-by-oliver-turpin?feature="> - This is the title - </a> - </div> - <div class="info"> - <a href="/ChronicleUK" data-ga-action="Image" data-ga-category="Photo Thumbnail"> - Oliver Turpin - </a> - </div> - <div class="rating">44.8</div> - </div> - </div> - """ - response = mock.Mock(text=html) - results = www500px.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 0) + self.assertEqual(results[0]['title'], u'Grand Canyon Afternoon') + self.assertEqual(results[0]['url'], 'https://500px.com/photo/64531569/grand-canyon-afternoon-by-todd-hakala') + self.assertEqual(results[0]['content'], u'Looking west on a very windy winter afternoon.') diff --git a/tests/unit/engines/test_yahoo.py b/tests/unit/engines/test_yahoo.py index 1226f92ab..303295e2f 100644 --- a/tests/unit/engines/test_yahoo.py +++ b/tests/unit/engines/test_yahoo.py @@ -46,6 +46,13 @@ class TestYahooEngine(SearxTestCase): 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, []) diff --git a/tests/unit/engines/test_youtube_noapi.py b/tests/unit/engines/test_youtube_noapi.py index 9fa8fd20e..41dcbb749 100644 --- a/tests/unit/engines/test_youtube_noapi.py +++ b/tests/unit/engines/test_youtube_noapi.py @@ -11,11 +11,31 @@ class TestYoutubeNoAPIEngine(SearxTestCase): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 0 + dicto['time_range'] = '' params = youtube_noapi.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('youtube.com', params['url']) + def test_time_range_search(self): + dicto = defaultdict(dict) + query = 'test_query' + dicto['time_range'] = 'year' + params = youtube_noapi.request(query, dicto) + self.assertIn('&sp=EgIIBQ%253D%253D', params['url']) + + dicto['time_range'] = 'month' + params = youtube_noapi.request(query, dicto) + self.assertIn('&sp=EgIIBA%253D%253D', params['url']) + + dicto['time_range'] = 'week' + params = youtube_noapi.request(query, dicto) + self.assertIn('&sp=EgIIAw%253D%253D', params['url']) + + dicto['time_range'] = 'day' + params = youtube_noapi.request(query, dicto) + self.assertIn('&sp=EgIIAg%253D%253D', params['url']) + def test_response(self): self.assertRaises(AttributeError, youtube_noapi.response, None) self.assertRaises(AttributeError, youtube_noapi.response, []) diff --git a/tests/unit/test_answerers.py b/tests/unit/test_answerers.py new file mode 100644 index 000000000..bd8789a7e --- /dev/null +++ b/tests/unit/test_answerers.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- + +from mock import Mock + +from searx.answerers import answerers +from searx.testing import SearxTestCase + + +class AnswererTest(SearxTestCase): + + def test_unicode_input(self): + query = Mock() + unicode_payload = u'árvíztűrő tükörfúrógép' + for answerer in answerers: + query.query = u'{} {}'.format(answerer.keywords[0], unicode_payload) + self.assertTrue(isinstance(answerer.answer(query), list)) diff --git a/tests/unit/test_plugins.py b/tests/unit/test_plugins.py index 98d39ec14..c9e65dfcb 100644 --- a/tests/unit/test_plugins.py +++ b/tests/unit/test_plugins.py @@ -6,9 +6,8 @@ from mock import Mock def get_search_mock(query, **kwargs): - return {'search': Mock(query=query, - result_container=Mock(answers=set()), - **kwargs)} + return Mock(search_query=Mock(query=query, **kwargs), + result_container=Mock(answers=set())) class PluginStoreTest(SearxTestCase): @@ -52,23 +51,39 @@ class SelfIPTest(SearxTestCase): request = Mock(user_plugins=store.plugins, remote_addr='127.0.0.1') request.headers.getlist.return_value = [] - ctx = get_search_mock(query='ip') - store.call('post_search', request, ctx) - self.assertTrue('127.0.0.1' in ctx['search'].result_container.answers) + search = get_search_mock(query='ip', pageno=1) + store.call('post_search', request, search) + self.assertTrue('127.0.0.1' in search.result_container.answers) + + search = get_search_mock(query='ip', pageno=2) + store.call('post_search', request, search) + self.assertFalse('127.0.0.1' in search.result_container.answers) # User agent test request = Mock(user_plugins=store.plugins, user_agent='Mock') request.headers.getlist.return_value = [] - ctx = get_search_mock(query='user-agent') - store.call('post_search', request, ctx) - self.assertTrue('Mock' in ctx['search'].result_container.answers) + search = get_search_mock(query='user-agent', pageno=1) + store.call('post_search', request, search) + self.assertTrue('Mock' in search.result_container.answers) + + search = get_search_mock(query='user-agent', pageno=2) + store.call('post_search', request, search) + self.assertFalse('Mock' in search.result_container.answers) + + search = get_search_mock(query='user-agent', pageno=1) + store.call('post_search', request, search) + self.assertTrue('Mock' in search.result_container.answers) + + search = get_search_mock(query='user-agent', pageno=2) + store.call('post_search', request, search) + self.assertFalse('Mock' in search.result_container.answers) - ctx = get_search_mock(query='user-agent') - store.call('post_search', request, ctx) - self.assertTrue('Mock' in ctx['search'].result_container.answers) + search = get_search_mock(query='What is my User-Agent?', pageno=1) + store.call('post_search', request, search) + self.assertTrue('Mock' in search.result_container.answers) - ctx = get_search_mock(query='What is my User-Agent?') - store.call('post_search', request, ctx) - self.assertTrue('Mock' in ctx['search'].result_container.answers) + search = get_search_mock(query='What is my User-Agent?', pageno=2) + store.call('post_search', request, search) + self.assertFalse('Mock' in search.result_container.answers) diff --git a/tests/unit/test_webapp.py b/tests/unit/test_webapp.py index 1762d66b6..1ef1f56c3 100644 --- a/tests/unit/test_webapp.py +++ b/tests/unit/test_webapp.py @@ -5,6 +5,7 @@ from mock import Mock from urlparse import ParseResult from searx import webapp from searx.testing import SearxTestCase +from searx.search import Search class ViewsTestCase(SearxTestCase): @@ -41,10 +42,10 @@ class ViewsTestCase(SearxTestCase): results_number=lambda: 3, results_length=lambda: len(self.test_results)) - webapp.Search.search = search_mock + Search.search = search_mock def get_current_theme_name_mock(override=None): - return 'default' + return 'legacy' webapp.get_current_theme_name = get_current_theme_name_mock @@ -58,7 +59,7 @@ class ViewsTestCase(SearxTestCase): def test_index_html(self): result = self.app.post('/', data={'q': 'test'}) self.assertIn( - '<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/default/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz" rel="noreferrer">Second <span class="highlight">Test</span></a></h3>', # noqa + '<h3 class="result_title"><img width="14" height="14" class="favicon" src="/static/themes/legacy/img/icons/icon_youtube.ico" alt="youtube" /><a href="http://second.test.xyz" rel="noreferrer">Second <span class="highlight">Test</span></a></h3>', # noqa result.data ) self.assertIn( |