From d14e2781b28e77207ab841dd52db0835ee55fcf2 Mon Sep 17 00:00:00 2001 From: misnyo Date: Fri, 25 Aug 2017 00:52:35 +0200 Subject: [fix]torrentz search engine fixed for new version --- tests/unit/engines/test_torrentz.py | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/engines/test_torrentz.py b/tests/unit/engines/test_torrentz.py index 2f836f73e..06c6fa30c 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='') @@ -30,13 +30,11 @@ class TestTorrentzEngine(SearxTestCase): books ebooks
- 1 - - 4 months - - 30 MB - 14 - 1 + 1 + 5 hours + 30 MB + 14 + 1
@@ -48,13 +46,11 @@ class TestTorrentzEngine(SearxTestCase): books ebooks
- 1 - - 4 months - - 30MB - 5,555 - 1,234,567 + 1 + 5 hours + 30MB + 5,555 + 1,234,567
@@ -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(2017, 8, 24, 19, 32, 4)) 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) -- cgit v1.2.3 From 2098e1b7ff39fb24bbc2ad7f1800992f1748eba0 Mon Sep 17 00:00:00 2001 From: misnyo Date: Fri, 25 Aug 2017 01:11:02 +0200 Subject: [fix]torrentz unit_tests timezone fix --- tests/unit/engines/test_torrentz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/engines/test_torrentz.py b/tests/unit/engines/test_torrentz.py index 06c6fa30c..271758da0 100644 --- a/tests/unit/engines/test_torrentz.py +++ b/tests/unit/engines/test_torrentz.py @@ -67,7 +67,7 @@ class TestTorrentzEngine(SearxTestCase): 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(2017, 8, 24, 19, 32, 4)) + self.assertEqual(r['publishedDate'], datetime(2017, 8, 24, 17, 32, 4)) self.assertEqual(r['seed'], 14) self.assertEqual(r['leech'], 1) self.assertEqual(r['filesize'], 30 * 1024 * 1024) -- cgit v1.2.3 From bf3f9a91fa3a07864f316ddd3a463ad45bd3d25d Mon Sep 17 00:00:00 2001 From: misnyo Date: Tue, 29 Aug 2017 17:54:41 +0200 Subject: [fix]torrentz unit_tests timezone fix --- tests/unit/engines/test_torrentz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/engines/test_torrentz.py b/tests/unit/engines/test_torrentz.py index 271758da0..f483bf68c 100644 --- a/tests/unit/engines/test_torrentz.py +++ b/tests/unit/engines/test_torrentz.py @@ -67,7 +67,7 @@ class TestTorrentzEngine(SearxTestCase): 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(2017, 8, 24, 17, 32, 4)) + self.assertEqual(r['publishedDate'], datetime.fromtimestamp(1503595924)) self.assertEqual(r['seed'], 14) self.assertEqual(r['leech'], 1) self.assertEqual(r['filesize'], 30 * 1024 * 1024) -- cgit v1.2.3 From f139f9cfdbc8d77eb61724eca253dc1e6ad72ce7 Mon Sep 17 00:00:00 2001 From: misnyo Date: Wed, 30 Aug 2017 16:47:56 +0200 Subject: [mod]blekko images removed --- tests/unit/engines/test_blekko_images.py | 71 -------------------------------- 1 file changed, 71 deletions(-) delete mode 100644 tests/unit/engines/test_blekko_images.py (limited to 'tests/unit') 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') -- cgit v1.2.3 From 0607b167f85acc6c0ab4c641f14b53cb4190e445 Mon Sep 17 00:00:00 2001 From: misnyo Date: Wed, 30 Aug 2017 18:53:00 +0200 Subject: [fix] faroo json api and image layout fixed --- tests/unit/engines/test_faroo.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'tests/unit') 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 = """ {} -- cgit v1.2.3 From 3182ba7069b2aa2fba1a1b7879bd5f234a4d2868 Mon Sep 17 00:00:00 2001 From: misnyo Date: Thu, 31 Aug 2017 17:48:07 +0200 Subject: [fix] google news dom xpath fix --- tests/unit/engines/test_google_news.py | 62 ++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 6 deletions(-) (limited to 'tests/unit') 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""" -
-
A(z) south témájának képe a következőből: CBC.ca

Meet Thuli Madonsela — South Africa's conscience

CBC.ca-9 órával ezelőtt
South African Public Protector
Who really governs South Africa?
Vélemény-News24-2016. dec. 8.
+

Search Results

+
+
+
+ +
+
+
+

+ Example title +

+
+ + Mac & i + + - + + Mar 21, 2016 +
+
Example description
+
+
+
+
+
+ + Story image for searx from Golem.de + +
+

+ Example title 2 +

+
+ + Golem.de + + - + + Oct 4, 2016 +
+
Example description 2
+
+
+
+
+
+ + """ # 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') -- cgit v1.2.3 From 01330f71cd60cab6c1ce9a19c28c2729f2d02344 Mon Sep 17 00:00:00 2001 From: misnyo Date: Thu, 31 Aug 2017 21:32:30 +0200 Subject: [fix] nyaa.si fixed --- tests/unit/engines/test_nyaa.py | 124 +++++++++++++++++++++++++++++----------- 1 file changed, 91 insertions(+), 33 deletions(-) (limited to 'tests/unit') 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='') self.assertEqual(nyaa.response(resp), []) html = """ - - - - - - - - - - - - - +
- - English-translated Anime - - - - Sample torrent title - - - - DL - - 10 MiB136660
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
Category
+
+
Name
+
+ + + +
Link
+
+ +
Size
+
+ +
Date
+
+ + + + + + + + +
+ + Anime - English-translated + + + Sample title 1 + + + + 723.7 MiB2017-08-21 11:241312
+ + Anime - English-translated + + + Sample title 2 + + + 8.2 GiB2017-04-08 01:40101206
""" @@ -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) -- cgit v1.2.3 From d081eee3f8c6b5eba39ee07916850f06aeee8658 Mon Sep 17 00:00:00 2001 From: jibe-b Date: Fri, 22 Sep 2017 22:26:37 +0200 Subject: [add] unit_test for base engine --- tests/unit/engines/test_base.py | 91 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 tests/unit/engines/test_base.py (limited to 'tests/unit') 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='') + self.assertEqual(base.response(response), []) + + xml_mock = """ + + + 0 + 1 + + + + 2000-01-01T01:01:01Z + 1 + cna + us + ftciteseerx + CiteSeerX + Science and more + + Someone + + + Someone + + + Science and more + + Science, and even more. + + The neighbour + + 2001 + 2001 + + text + + + 1 + + + application/pdf + + + application/pdf + + + http://example.org/ + + http://example.org + http://example.org + + en + + Under the example.org licence + 1 + + eng + + + +""" + + 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.') -- cgit v1.2.3 From a524dbb823e88482a762d56ac1ed352641f3f0c3 Mon Sep 17 00:00:00 2001 From: marc Date: Tue, 10 Oct 2017 16:49:49 -0500 Subject: [fix] language support for bing images and videos --- tests/unit/engines/test_bing_images.py | 12 ++++++++---- tests/unit/engines/test_bing_videos.py | 2 ++ 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/engines/test_bing_images.py b/tests/unit/engines/test_bing_images.py index 287f13499..8b0bdb39d 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,14 @@ 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'] = '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' in params['cookies']['_EDGE_S']) def test_response(self): self.assertRaises(AttributeError, bing_images.response, None) 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 -- cgit v1.2.3 From 44085e31d0ccf140f307389bd42654f5ada8667f Mon Sep 17 00:00:00 2001 From: marc Date: Tue, 10 Oct 2017 16:52:41 -0500 Subject: update engines_languages.json and languages.py Also, fix fetch_languages.py so it can run on python3. --- tests/unit/engines/test_swisscows.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests/unit') 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):
    -
  • -
  • -
  • +
  • +
  • +
-- cgit v1.2.3 From 54f0ab1f3bd6bcd05eb2108a3a2eeaf5bd71ab61 Mon Sep 17 00:00:00 2001 From: marc Date: Tue, 10 Oct 2017 17:30:43 -0500 Subject: test fetch langauges function on bing images --- tests/unit/engines/test_bing_images.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/engines/test_bing_images.py b/tests/unit/engines/test_bing_images.py index 8b0bdb39d..3f3006124 100644 --- a/tests/unit/engines/test_bing_images.py +++ b/tests/unit/engines/test_bing_images.py @@ -25,10 +25,15 @@ class TestBingImagesEngine(SearxTestCase): 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.assertTrue('_EDGE_S' in params['cookies']) - self.assertTrue('en' in params['cookies']['_EDGE_S']) + self.assertTrue('en-us' in params['cookies']['_EDGE_S']) def test_response(self): self.assertRaises(AttributeError, bing_images.response, None) @@ -86,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 = """ +
+
+ + +
+
+ """ + 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) -- cgit v1.2.3