diff options
author | Apply55gx <Apply55gx@users.noreply.github.com> | 2017-10-25 10:44:28 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-25 10:44:28 +0200 |
commit | d800e3fcfa44bc0be7262092815b2d2020a9d9f3 (patch) | |
tree | 0bdc64b3e15592e2fdeeaa40f21cbcc8039b7949 /tests | |
parent | 18a4e7035f72a3c31239ae0bd1ee67cc2ad354b8 (diff) | |
parent | b34124fd8a6b020136ca9656acdb01afceabe96f (diff) | |
download | searxng-d800e3fcfa44bc0be7262092815b2d2020a9d9f3.tar.gz searxng-d800e3fcfa44bc0be7262092815b2d2020a9d9f3.zip |
Merge pull request #1 from asciimoo/master
-
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/engines/test_base.py | 91 | ||||
-rw-r--r-- | tests/unit/engines/test_bing_images.py | 42 | ||||
-rw-r--r-- | tests/unit/engines/test_bing_videos.py | 2 | ||||
-rw-r--r-- | tests/unit/engines/test_blekko_images.py | 71 | ||||
-rw-r--r-- | tests/unit/engines/test_faroo.py | 7 | ||||
-rw-r--r-- | tests/unit/engines/test_google_news.py | 62 | ||||
-rw-r--r-- | tests/unit/engines/test_nyaa.py | 124 | ||||
-rw-r--r-- | tests/unit/engines/test_swisscows.py | 6 | ||||
-rw-r--r-- | tests/unit/engines/test_torrentz.py | 32 |
9 files changed, 297 insertions, 140 deletions
diff --git a/tests/unit/engines/test_base.py b/tests/unit/engines/test_base.py new file mode 100644 index 000000000..e008b034c --- /dev/null +++ b/tests/unit/engines/test_base.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import base +from searx.testing import SearxTestCase + + +class TestBaseEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = base.request(query, dicto) + self.assertIn('url', params) + self.assertIn('base-search.net', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, base.response, None) + self.assertRaises(AttributeError, base.response, []) + self.assertRaises(AttributeError, base.response, '') + self.assertRaises(AttributeError, base.response, '[]') + + response = mock.Mock(text='<response></response>') + self.assertEqual(base.response(response), []) + + xml_mock = """<?xml version="1.0"?> +<response> + <lst name="responseHeader"> + <int name="status">0</int> + <int name="QTime">1</int> + </lst> + <result name="response" numFound="1" start="0"> + <doc> + <date name="dchdate">2000-01-01T01:01:01Z</date> + <str name="dcdocid">1</str> + <str name="dccontinent">cna</str> + <str name="dccountry">us</str> + <str name="dccollection">ftciteseerx</str> + <str name="dcprovider">CiteSeerX</str> + <str name="dctitle">Science and more</str> + <arr name="dccreator"> + <str>Someone</str> + </arr> + <arr name="dcperson"> + <str>Someone</str> + </arr> + <arr name="dcsubject"> + <str>Science and more</str> + </arr> + <str name="dcdescription">Science, and even more.</str> + <arr name="dccontributor"> + <str>The neighbour</str> + </arr> + <str name="dcdate">2001</str> + <int name="dcyear">2001</int> + <arr name="dctype"> + <str>text</str> + </arr> + <arr name="dctypenorm"> + <str>1</str> + </arr> + <arr name="dcformat"> + <str>application/pdf</str> + </arr> + <arr name="dccontenttype"> + <str>application/pdf</str> + </arr> + <arr name="dcidentifier"> + <str>http://example.org/</str> + </arr> + <str name="dclink">http://example.org</str> + <str name="dcsource">http://example.org</str> + <arr name="dclanguage"> + <str>en</str> + </arr> + <str name="dcrights">Under the example.org licence</str> + <int name="dcoa">1</int> + <arr name="dclang"> + <str>eng</str> + </arr> + </doc> + </result> +</response>""" + + response = mock.Mock(text=xml_mock.encode('utf-8')) + results = base.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Science and more') + self.assertEqual(results[0]['content'], 'Science, and even more.') diff --git a/tests/unit/engines/test_bing_images.py b/tests/unit/engines/test_bing_images.py index 287f13499..3f3006124 100644 --- a/tests/unit/engines/test_bing_images.py +++ b/tests/unit/engines/test_bing_images.py @@ -8,10 +8,12 @@ from searx.testing import SearxTestCase class TestBingImagesEngine(SearxTestCase): def test_request(self): + bing_images.supported_languages = ['fr-FR', 'en-US'] + query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 - dicto['language'] = 'fr_FR' + dicto['language'] = 'fr-FR' dicto['safesearch'] = 1 dicto['time_range'] = '' params = bing_images.request(query, dicto) @@ -19,12 +21,19 @@ class TestBingImagesEngine(SearxTestCase): self.assertTrue(query in params['url']) self.assertTrue('bing.com' in params['url']) self.assertTrue('SRCHHPGUSR' in params['cookies']) - self.assertTrue('fr' in params['cookies']['SRCHHPGUSR']) + self.assertTrue('DEMOTE' in params['cookies']['SRCHHPGUSR']) + self.assertTrue('_EDGE_S' in params['cookies']) + self.assertTrue('fr-fr' in params['cookies']['_EDGE_S']) + + dicto['language'] = 'fr' + params = bing_images.request(query, dicto) + self.assertTrue('_EDGE_S' in params['cookies']) + self.assertTrue('fr-fr' in params['cookies']['_EDGE_S']) dicto['language'] = 'all' params = bing_images.request(query, dicto) - self.assertIn('SRCHHPGUSR', params['cookies']) - self.assertIn('en', params['cookies']['SRCHHPGUSR']) + self.assertTrue('_EDGE_S' in params['cookies']) + self.assertTrue('en-us' in params['cookies']['_EDGE_S']) def test_response(self): self.assertRaises(AttributeError, bing_images.response, None) @@ -82,3 +91,28 @@ class TestBingImagesEngine(SearxTestCase): self.assertEqual(results[0]['content'], '') self.assertEqual(results[0]['thumbnail_src'], 'thumb_url') self.assertEqual(results[0]['img_src'], 'img_url') + + def test_fetch_supported_languages(self): + html = """ + <div> + <div id="region-section-content"> + <ul class="b_vList"> + <li> + <a href="https://bing...&setmkt=de-DE&s...">Germany</a> + <a href="https://bing...&setmkt=nb-NO&s...">Norway</a> + </li> + </ul> + <ul class="b_vList"> + <li> + <a href="https://bing...&setmkt=es-AR&s...">Argentina</a> + </li> + </ul> + </div> + </div> + """ + response = mock.Mock(text=html) + languages = list(bing_images._fetch_supported_languages(response)) + self.assertEqual(len(languages), 3) + self.assertIn('de-DE', languages) + self.assertIn('no-NO', languages) + self.assertIn('es-AR', languages) diff --git a/tests/unit/engines/test_bing_videos.py b/tests/unit/engines/test_bing_videos.py index 011b5410a..118754b25 100644 --- a/tests/unit/engines/test_bing_videos.py +++ b/tests/unit/engines/test_bing_videos.py @@ -8,6 +8,8 @@ from searx.testing import SearxTestCase class TestBingVideosEngine(SearxTestCase): def test_request(self): + bing_videos.supported_languages = ['fr-FR', 'en-US'] + query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 diff --git a/tests/unit/engines/test_blekko_images.py b/tests/unit/engines/test_blekko_images.py deleted file mode 100644 index beb0853e3..000000000 --- a/tests/unit/engines/test_blekko_images.py +++ /dev/null @@ -1,71 +0,0 @@ -from collections import defaultdict -import mock -from searx.engines import blekko_images -from searx.testing import SearxTestCase - - -class TestBlekkoImagesEngine(SearxTestCase): - - def test_request(self): - query = 'test_query' - dicto = defaultdict(dict) - dicto['pageno'] = 0 - dicto['safesearch'] = 1 - params = blekko_images.request(query, dicto) - self.assertIn('url', params) - self.assertIn(query, params['url']) - self.assertIn('blekko.com', params['url']) - self.assertIn('page', params['url']) - - dicto['pageno'] = 1 - params = blekko_images.request(query, dicto) - self.assertNotIn('page', params['url']) - - def test_response(self): - self.assertRaises(AttributeError, blekko_images.response, None) - self.assertRaises(AttributeError, blekko_images.response, []) - self.assertRaises(AttributeError, blekko_images.response, '') - self.assertRaises(AttributeError, blekko_images.response, '[]') - - response = mock.Mock(text='[]') - self.assertEqual(blekko_images.response(response), []) - - json = """ - [ - { - "c": 1, - "page_url": "http://result_url.html", - "title": "Photo title", - "tn_url": "http://ts1.mm.bing.net/th?id=HN.608050619474382748&pid=15.1", - "url": "http://result_image.jpg" - }, - { - "c": 2, - "page_url": "http://companyorange.simpsite.nl/OSM", - "title": "OSM", - "tn_url": "http://ts2.mm.bing.net/th?id=HN.608048068264919461&pid=15.1", - "url": "http://simpsite.nl/userdata2/58985/Home/OSM.bmp" - }, - { - "c": 3, - "page_url": "http://invincible.webklik.nl/page/osm", - "title": "OSM", - "tn_url": "http://ts1.mm.bing.net/th?id=HN.608024514657649476&pid=15.1", - "url": "http://www.webklik.nl/user_files/2009_09/65324/osm.gif" - }, - { - "c": 4, - "page_url": "http://www.offshorenorway.no/event/companyDetail/id/12492", - "title": "Go to OSM Offshore AS homepage", - "tn_url": "http://ts2.mm.bing.net/th?id=HN.608054265899847285&pid=15.1", - "url": "http://www.offshorenorway.no/firmalogo/OSM-logo.png" - } - ] - """ - response = mock.Mock(text=json) - results = blekko_images.response(response) - self.assertEqual(type(results), list) - self.assertEqual(len(results), 4) - self.assertEqual(results[0]['title'], 'Photo title') - self.assertEqual(results[0]['url'], 'http://result_url.html') - self.assertEqual(results[0]['img_src'], 'http://result_image.jpg') diff --git a/tests/unit/engines/test_faroo.py b/tests/unit/engines/test_faroo.py index acebdda86..ebcde39a7 100644 --- a/tests/unit/engines/test_faroo.py +++ b/tests/unit/engines/test_faroo.py @@ -40,9 +40,6 @@ class TestFarooEngine(SearxTestCase): response = mock.Mock(text='{"data": []}') self.assertEqual(faroo.response(response), []) - response = mock.Mock(text='{"data": []}', status_code=401) - self.assertRaises(Exception, faroo.response, response) - response = mock.Mock(text='{"data": []}', status_code=429) self.assertRaises(Exception, faroo.response, response) @@ -98,14 +95,14 @@ class TestFarooEngine(SearxTestCase): response = mock.Mock(text=json) results = faroo.response(response) self.assertEqual(type(results), list) - self.assertEqual(len(results), 4) + 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[1]['title'], 'This is the title2') self.assertEqual(results[1]['url'], 'http://this.is.the.url2/') self.assertEqual(results[1]['content'], 'This is the content2') - self.assertEqual(results[3]['img_src'], 'http://upload.wikimedia.org/optimized.jpg') + self.assertEqual(results[2]['thumbnail'], 'http://upload.wikimedia.org/optimized.jpg') json = """ {} diff --git a/tests/unit/engines/test_google_news.py b/tests/unit/engines/test_google_news.py index 6454dde47..20a75af48 100644 --- a/tests/unit/engines/test_google_news.py +++ b/tests/unit/engines/test_google_news.py @@ -37,14 +37,64 @@ class TestGoogleNewsEngine(SearxTestCase): self.assertEqual(google_news.response(response), []) 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,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBwgHBgkIBwgKCgkLDRYPDQwMDRsUFRAWIB0iIiAdHx8kKDQsJCYxJx8fLT0tMTU3Ojo6Iys/RD84QzQ5OjcBCgoKDQwNGg8PGjclHyU3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3Nzc3N//AABEIAGQAZAMBIgACEQEDEQH/xAAbAAACAwEBAQAAAAAAAAAAAAAFBgADBAIBB//EADsQAAIBAwIEAwUGBAUFAAAAAAECAwAEEQUhBhIxURNBYRQiMnGBFSORobHBB1Ji4UKS0fDxFiQzNYL/xAAYAQEBAQEBAAAAAAAAAAAAAAACAwEEAP/EACERAAMBAAICAgMBAAAAAAAAAAABAhEhMQMSE2EEQVEi/9oADAMBAAIRAxEAPwDSkKr8JFWIzwnMTlSepFdiBgMiuxEdid6B7QbrEr8qE4L4wGNCIT7u/WifE0eIosHBz0oWnugCjQ4BfEipJHbpK/JG0gDP/KO9XT6Lw7BGDHrofIBIJQ4NXalAs8IDJnFLepS21pmOOFXl679FoY66ZTcNwWxtGzaaqwOf8JFcXupSSr4cupSOp6gnGaDQahJESQwU/wBIxXbX0l0jl+VgduYjJrfj/ofc9MluueV1z3xV2jlX1AlDkY61TY3MAk5LuJSnm4G4+nnTFb2ltEweFRvuCO1ebw8uTYNnQ9iDTtDKJYY8DflFJg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XEjM0kw8R89yd6lSpiCfCcEV7fXdpcxq8TWUjjujAggr2NXcJ3k08F9pcpDWslpJNyEfA6gEFe29SpQZqAgbmAY9TvXAY5YZOCRUqV79ifRthucRhXgglxsGkTmIHbNSpUrAn//2Q==" 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> +<h2 class="hd">Search Results</h2> +<div data-async-context="query:searx" id="ires"> + <div eid="oC2oWcGXCafR6ASkwoCwDA" id="rso"> + <div class="_NId"> + <!--m--> + <div class="g _cy"> + <div class="ts _JGs _JHs _tJs _KGs _jHs"> + <div class="_hJs"> + <h3 class="r _gJs"> + <a class="l _PMs" href="https://example.com/" onmousedown="return rwt(this,'','','','11','AFQjCNEyehpzD5cJK1KUfXBx9RmsbqqG9g','','0ahUKEwjB58OR54HWAhWnKJoKHSQhAMY4ChCpAggiKAAwAA','','',event)">Example title</a> + </h3> + <div class="slp"> + <span class="_OHs _PHs"> + Mac & i</span> + <span class="_QGs"> + -</span> + <span class="f nsa _QHs"> + Mar 21, 2016</span> + </div> + <div class="st">Example description</div> + </div> + </div> + </div> + <div class="g _cy"> + <div class="ts _JGs _JHs _oGs _KGs _jHs"> + <a class="top _xGs _SHs" href="https://example2.com/" onmousedown="return rwt(this,'','','','12','AFQjCNHObfH7sYmLWI1SC-YhWXKZFRzRjw','','0ahUKEwjB58OR54HWAhWnKJoKHSQhAMY4ChC8iAEIJDAB','','',event)"> + <img class="th _RGs" src="https://example2.com/image.jpg" alt="Story image for searx from Golem.de" onload="typeof google==='object'&&google.aft&&google.aft(this)"> + </a> + <div class="_hJs"> + <h3 class="r _gJs"> + <a class="l _PMs" href="https://example2.com/" onmousedown="return rwt(this,'','','','12','AFQjCNHObfH7sYmLWI1SC-YhWXKZFRzRjw','','0ahUKEwjB58OR54HWAhWnKJoKHSQhAMY4ChCpAgglKAAwAQ','','',event)">Example title 2</a> + </h3> + <div class="slp"> + <span class="_OHs _PHs"> + Golem.de</span> + <span class="_QGs"> + -</span> + <span class="f nsa _QHs"> + Oct 4, 2016</span> + </div> + <div class="st">Example description 2</div> + </div> + </div> + </div> + </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'], u'Meet Thuli Madonsela \u2014 South Africa\'s conscience') - self.assertEqual(results[0]['url'], 'http://this.is.the.url') - self.assertEqual(results[0]['content'], 'South African Public Protector') + self.assertEqual(len(results), 2) + self.assertEqual(results[0]['title'], u'Example title') + self.assertEqual(results[0]['url'], 'https://example.com/') + self.assertEqual(results[0]['content'], 'Example description') + self.assertEqual(results[1]['title'], u'Example title 2') + self.assertEqual(results[1]['url'], 'https://example2.com/') + self.assertEqual(results[1]['content'], 'Example description 2') + self.assertEqual(results[1]['img_src'], 'https://example2.com/image.jpg') diff --git a/tests/unit/engines/test_nyaa.py b/tests/unit/engines/test_nyaa.py index db412e1cc..6dcafc6b7 100644 --- a/tests/unit/engines/test_nyaa.py +++ b/tests/unit/engines/test_nyaa.py @@ -13,38 +13,92 @@ class TestNyaaEngine(SearxTestCase): params = nyaa.request(query, dic) self.assertTrue('url' in params) self.assertTrue(query in params['url']) - self.assertTrue('nyaa.se' in params['url']) + self.assertTrue('nyaa.si' in params['url']) def test_response(self): resp = mock.Mock(text='<html></html>') self.assertEqual(nyaa.response(resp), []) html = """ - <table class="tlist"> - <tbody> - <tr class="trusted tlistrow"> - <td class="tlisticon"> - <a href="//www.nyaa.se" title="English-translated Anime"> - <img src="//files.nyaa.se" alt="English-translated Anime"> - </a> - </td> - <td class="tlistname"> - <a href="//www.nyaa.se/?page3"> - Sample torrent title - </a> - </td> - <td class="tlistdownload"> - <a href="//www.nyaa.se/?page_dl" title="Download"> - <img src="//files.nyaa.se/www-dl.png" alt="DL"> - </a> - </td> - <td class="tlistsize">10 MiB</td> - <td class="tlistsn">1</td> - <td class="tlistln">3</td> - <td class="tlistdn">666</td> - <td class="tlistmn">0</td> - </tr> - </tbody> + <table class="table table-bordered table-hover table-striped torrent-list"> + <thead> + <tr> + <th class="hdr-category text-center" style="width:80px;"> + <div>Category</div> + </th> + <th class="hdr-name" style="width:auto;"> + <div>Name</div> + </th> + <th class="hdr-comments sorting text-center" title="Comments" style="width:50px;"> + <a href="/?f=0&c=0_0&q=Death+Parade&s=comments&o=desc"></a> + <i class="fa fa-comments-o"></i> + </th> + <th class="hdr-link text-center" style="width:70px;"> + <div>Link</div> + </th> + <th class="hdr-size sorting text-center" style="width:100px;"> + <a href="/?f=0&c=0_0&q=Death+Parade&s=size&o=desc"></a> + <div>Size</div> + </th> + <th class="hdr-date sorting_desc text-center" title="In local time" style="width:140px;"> + <a href="/?f=0&c=0_0&q=Death+Parade&s=id&o=asc"></a> + <div>Date</div> + </th> + <th class="hdr-seeders sorting text-center" title="Seeders" style="width:50px;"> + <a href="/?f=0&c=0_0&q=Death+Parade&s=seeders&o=desc"></a> + <i class="fa fa-arrow-up" aria-hidden="true"></i> + </th> + <th class="hdr-leechers sorting text-center" title="Leechers" style="width:50px;"> + <a href="/?f=0&c=0_0&q=Death+Parade&s=leechers&o=desc"></a> + <i class="fa fa-arrow-down" aria-hidden="true"></i> + </th> + <th class="hdr-downloads sorting text-center" title="Completed downloads" style="width:50px;"> + <a href="/?f=0&c=0_0&q=Death+Parade&s=downloads&o=desc"></a> + <i class="fa fa-check" aria-hidden="true"></i> + </th> + </tr> + </thead> + <tbody> + <tr class="default"> + <td style="padding:0 4px;"> + <a href="/?c=1_2" title="Anime - English-translated"> + <img src="/static/img/icons/nyaa/1_2.png" alt="Anime - English-translated"> + </a> + </td> + <td colspan="2"> + <a href="/view/1" title="Sample title 1">Sample title 1</a> + </td> + <td class="text-center" style="white-space: nowrap;"> + <a href="/download/1.torrent"><i class="fa fa-fw fa-download"></i></a> + <a href="magnet:?xt=urn:btih:2"><i class="fa fa-fw fa-magnet"></i></a> + </td> + <td class="text-center">723.7 MiB</td> + <td class="text-center" data-timestamp="1503307456" title="1 week 3 + days 9 hours 44 minutes 39 seconds ago">2017-08-21 11:24</td> + <td class="text-center" style="color: green;">1</td> + <td class="text-center" style="color: red;">3</td> + <td class="text-center">12</td> + </tr> + <tr class="default"> + <td style="padding:0 4px;"> + <a href="/?c=1_2" title="Anime - English-translated"> + <img src="/static/img/icons/nyaa/1_2.png" alt="Anime - English-translated"> + </a> + </td> + <td colspan="2"> + <a href="/view/2" title="Sample title 2">Sample title 2</a> + </td> + <td class="text-center" style="white-space: nowrap;"> + <a href="magnet:?xt=urn:btih:2"><i class="fa fa-fw fa-magnet"></i></a> + </td> + <td class="text-center">8.2 GiB</td> + <td class="text-center" data-timestamp="1491608400" title="4 months 3 + weeks 4 days 19 hours 28 minutes 55 seconds ago">2017-04-08 01:40</td> + <td class="text-center" style="color: green;">10</td> + <td class="text-center" style="color: red;">1</td> + <td class="text-center">206</td> + </tr> + </tbody> </table> """ @@ -52,15 +106,19 @@ class TestNyaaEngine(SearxTestCase): results = nyaa.response(resp) self.assertEqual(type(results), list) - self.assertEqual(len(results), 1) + self.assertEqual(len(results), 2) r = results[0] - self.assertTrue(r['url'].find('www.nyaa.se/?page3') >= 0) - self.assertTrue(r['torrentfile'].find('www.nyaa.se/?page_dl') >= 0) - self.assertTrue(r['content'].find('English-translated Anime') >= 0) - self.assertTrue(r['content'].find('Downloaded 666 times.') >= 0) + self.assertTrue(r['url'].find('1') >= 0) + self.assertTrue(r['torrentfile'].find('1.torrent') >= 0) + self.assertTrue(r['content'].find('Anime - English-translated') >= 0) + self.assertTrue(r['content'].find('Downloaded 12 times.') >= 0) - self.assertEqual(r['title'], 'Sample torrent title') + self.assertEqual(r['title'], 'Sample title 1') self.assertEqual(r['seed'], 1) self.assertEqual(r['leech'], 3) - self.assertEqual(r['filesize'], 10 * 1024 * 1024) + self.assertEqual(r['filesize'], 723700000) + + r = results[1] + self.assertTrue(r['url'].find('2') >= 0) + self.assertTrue(r['magnetlink'].find('magnet:') >= 0) diff --git a/tests/unit/engines/test_swisscows.py b/tests/unit/engines/test_swisscows.py index 53890be78..492526f94 100644 --- a/tests/unit/engines/test_swisscows.py +++ b/tests/unit/engines/test_swisscows.py @@ -139,9 +139,9 @@ class TestSwisscowsEngine(SearxTestCase): <div id="regions-popup"> <div> <ul> - <li><a data-val="browser"></a></li> - <li><a data-val="de-CH"></a></li> - <li><a data-val="fr-CH"></a></li> + <li><a data-search-language="browser"></a></li> + <li><a data-search-language="de-CH"></a></li> + <li><a data-search-language="fr-CH"></a></li> </ul> </div> </div> diff --git a/tests/unit/engines/test_torrentz.py b/tests/unit/engines/test_torrentz.py index 2f836f73e..f483bf68c 100644 --- a/tests/unit/engines/test_torrentz.py +++ b/tests/unit/engines/test_torrentz.py @@ -14,7 +14,7 @@ class TestTorrentzEngine(SearxTestCase): params = torrentz.request(query, dic) self.assertTrue('url' in params) self.assertTrue(query in params['url']) - self.assertTrue('torrentz.eu' in params['url']) + self.assertTrue('torrentz2.eu' in params['url']) def test_response(self): resp = mock.Mock(text='<html></html>') @@ -30,13 +30,11 @@ class TestTorrentzEngine(SearxTestCase): books ebooks </dt> <dd> - <span class="v">1</span> - <span class="a"> - <span title="Sun, 22 Nov 2015 03:01:42">4 months</span> - </span> - <span class="s">30 MB</span> - <span class="u">14</span> - <span class="d">1</span> + <span>1</span> + <span title="1503595924">5 hours</span> + <span>30 MB</span> + <span>14</span> + <span>1</span> </dd> </dl> @@ -48,13 +46,11 @@ class TestTorrentzEngine(SearxTestCase): books ebooks </dt> <dd> - <span class="v">1</span> - <span class="a"> - <span title="Sun, 2124091j0j190gm42">4 months</span> - </span> - <span class="s">30MB</span> - <span class="u">5,555</span> - <span class="d">1,234,567</span> + <span>1</span> + <span title="1503595924 aaa">5 hours</span> + <span>30MB</span> + <span>5,555</span> + <span>1,234,567</span> </dd> </dl> </div> @@ -68,10 +64,10 @@ class TestTorrentzEngine(SearxTestCase): # testing against the first result r = results[0] - self.assertEqual(r['url'], 'https://torrentz.eu/4362e08b1d80e1820fb2550b752f9f3126fe76d6') + self.assertEqual(r['url'], 'https://torrentz2.eu/4362e08b1d80e1820fb2550b752f9f3126fe76d6') self.assertEqual(r['title'], 'Completely valid info books ebooks') # 22 Nov 2015 03:01:42 - self.assertEqual(r['publishedDate'], datetime(2015, 11, 22, 3, 1, 42)) + self.assertEqual(r['publishedDate'], datetime.fromtimestamp(1503595924)) self.assertEqual(r['seed'], 14) self.assertEqual(r['leech'], 1) self.assertEqual(r['filesize'], 30 * 1024 * 1024) @@ -79,7 +75,7 @@ class TestTorrentzEngine(SearxTestCase): # testing against the second result r = results[1] - self.assertEqual(r['url'], 'https://torrentz.eu/poaskdpokaspod') + self.assertEqual(r['url'], 'https://torrentz2.eu/poaskdpokaspod') self.assertEqual(r['title'], 'Invalid hash and date and filesize books ebooks') self.assertEqual(r['seed'], 5555) self.assertEqual(r['leech'], 1234567) |