From 525af2a031b787e22c3e310e61bfcd5fd1737bca Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sun, 25 Jan 2015 20:14:37 +0100 Subject: Add bing in the test units --- searx/tests/engines/test_bing.py | 90 ++++++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 91 insertions(+) create mode 100644 searx/tests/engines/test_bing.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_bing.py b/searx/tests/engines/test_bing.py new file mode 100644 index 000000000..52a049f01 --- /dev/null +++ b/searx/tests/engines/test_bing.py @@ -0,0 +1,90 @@ +from collections import defaultdict +import mock +from searx.engines import bing +from searx.testing import SearxTestCase + + +class TestBingEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'fr_FR' + params = bing.request(query, dicto) + self.assertTrue('url' in params) + 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']) + + dicto['language'] = 'all' + params = bing.request(query, dicto) + self.assertTrue('SRCHHPGUSR' in params['cookies']) + self.assertTrue('en' in params['cookies']['SRCHHPGUSR']) + + def test_response(self): + self.assertRaises(AttributeError, bing.response, None) + self.assertRaises(AttributeError, bing.response, []) + self.assertRaises(AttributeError, bing.response, '') + self.assertRaises(AttributeError, bing.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(bing.response(response), []) + + response = mock.Mock(content='') + self.assertEqual(bing.response(response), []) + + html = """ +
+
+ +
this.meta.com + + + + +
+

This should be the content.

+
+
+ """ + response = mock.Mock(content=html) + results = bing.response(response) + 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'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') + + html = """ +
  • +
    + +
    this.meta.com + + + + +
    +

    This should be the content.

    +
    +
  • + """ + response = mock.Mock(content=html) + results = bing.response(response) + 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'], 'http://this.should.be.the.link/') + self.assertEqual(results[0]['content'], 'This should be the content.') diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 1ffdbe529..970131b48 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,2 +1,3 @@ +from searx.tests.engines.test_bing import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_github import * # noqa -- cgit v1.2.3 From 0f52cc75424b4b376b7b950801c9a91d4e24e282 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sun, 25 Jan 2015 22:12:34 +0100 Subject: Deezer's unit test --- searx/tests/engines/test_deezer.py | 56 ++++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 57 insertions(+) create mode 100644 searx/tests/engines/test_deezer.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_deezer.py b/searx/tests/engines/test_deezer.py new file mode 100644 index 000000000..e0b81e3d6 --- /dev/null +++ b/searx/tests/engines/test_deezer.py @@ -0,0 +1,56 @@ +from collections import defaultdict +import mock +from searx.engines import deezer +from searx.testing import SearxTestCase + + +class TestDeezerEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = deezer.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('deezer.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, deezer.response, None) + self.assertRaises(AttributeError, deezer.response, []) + self.assertRaises(AttributeError, deezer.response, '') + self.assertRaises(AttributeError, deezer.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(deezer.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(deezer.response(response), []) + + json = """ + {"data":[ + {"id":100, "title":"Title of track", + "link":"http:\/\/www.deezer.com\/track\/1094042","duration":232, + "artist":{"id":200,"name":"Artist Name", + "link":"http:\/\/www.deezer.com\/artist\/1217","type":"artist"}, + "album":{"id":118106,"title":"Album Title","type":"album"},"type":"track"} + ]} + """ + response = mock.Mock(text=json) + results = deezer.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of track') + self.assertEqual(results[0]['url'], 'http://www.deezer.com/track/1094042') + self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track') + + json = """ + {"data":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.deezer.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = deezer.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 970131b48..45c9d7e28 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,3 +1,4 @@ from searx.tests.engines.test_bing import * # noqa +from searx.tests.engines.test_deezer import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_github import * # noqa -- cgit v1.2.3 From 192f255e13e3a38cd572b08a2aff4b6117ff0960 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sun, 25 Jan 2015 22:33:02 +0100 Subject: Mixcloud's unit test --- searx/tests/engines/test_deezer.py | 1 + searx/tests/engines/test_mixcloud.py | 67 ++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 3 files changed, 69 insertions(+) create mode 100644 searx/tests/engines/test_mixcloud.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_deezer.py b/searx/tests/engines/test_deezer.py index e0b81e3d6..c8c2c90f2 100644 --- a/searx/tests/engines/test_deezer.py +++ b/searx/tests/engines/test_deezer.py @@ -43,6 +43,7 @@ class TestDeezerEngine(SearxTestCase): self.assertEqual(results[0]['title'], 'Title of track') self.assertEqual(results[0]['url'], 'http://www.deezer.com/track/1094042') self.assertEqual(results[0]['content'], 'Artist Name • Album Title • Title of track') + self.assertTrue('100' in results[0]['embedded']) json = """ {"data":[ diff --git a/searx/tests/engines/test_mixcloud.py b/searx/tests/engines/test_mixcloud.py new file mode 100644 index 000000000..a2ea47cf9 --- /dev/null +++ b/searx/tests/engines/test_mixcloud.py @@ -0,0 +1,67 @@ +from collections import defaultdict +import mock +from searx.engines import mixcloud +from searx.testing import SearxTestCase + + +class TestMixcloudEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = mixcloud.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('mixcloud.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, mixcloud.response, None) + self.assertRaises(AttributeError, mixcloud.response, []) + self.assertRaises(AttributeError, mixcloud.response, '') + self.assertRaises(AttributeError, mixcloud.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(mixcloud.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(mixcloud.response(response), []) + + json = """ + {"data":[ + { + "user": { + "url": "http://www.mixcloud.com/user/", + "username": "user", + "name": "User", + "key": "/user/" + }, + "key": "/user/this-is-the-url/", + "created_time": "2014-11-14T13:30:02Z", + "audio_length": 3728, + "slug": "this-is-the-url", + "name": "Title of track", + "url": "http://www.mixcloud.com/user/this-is-the-url/", + "updated_time": "2014-11-14T13:14:10Z" + } + ]} + """ + response = mock.Mock(text=json) + results = mixcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of track') + self.assertEqual(results[0]['url'], 'http://www.mixcloud.com/user/this-is-the-url/') + self.assertEqual(results[0]['content'], 'User') + self.assertTrue('http://www.mixcloud.com/user/this-is-the-url/' in results[0]['embedded']) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.mixcloud.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = mixcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 45c9d7e28..b42b1b89c 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -2,3 +2,4 @@ from searx.tests.engines.test_bing import * # noqa from searx.tests.engines.test_deezer import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_github import * # noqa +from searx.tests.engines.test_mixcloud import * # noqa -- cgit v1.2.3 From 8f040e30adbbd615155a5075bec28ccadff10eff Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Mon, 26 Jan 2015 17:36:10 +0100 Subject: Flickr's test unit --- searx/tests/engines/test_flickr.py | 142 +++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 143 insertions(+) create mode 100644 searx/tests/engines/test_flickr.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_flickr.py b/searx/tests/engines/test_flickr.py new file mode 100644 index 000000000..8b39e922f --- /dev/null +++ b/searx/tests/engines/test_flickr.py @@ -0,0 +1,142 @@ +from collections import defaultdict +import mock +from searx.engines import flickr +from searx.testing import SearxTestCase + + +class TestFlickrEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = flickr.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('flickr.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, flickr.response, None) + self.assertRaises(AttributeError, flickr.response, []) + self.assertRaises(AttributeError, flickr.response, '') + self.assertRaises(AttributeError, flickr.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(flickr.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(flickr.response(response), []) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "photo": [ + { "id": "15751017054", "owner": "66847915@N08", + "secret": "69c22afc40", "server": "7285", "farm": 8, + "title": "Photo title", "ispublic": 1, + "isfriend": 0, "isfamily": 0, + "description": { "_content": "Description" }, + "ownername": "Owner", + "url_o": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_9178e0f963_o.jpg", + "height_o": "2100", "width_o": "2653", + "url_n": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_n.jpg", + "height_n": "253", "width_n": "320", + "url_z": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_z.jpg", + "height_z": "507", "width_z": "640" } + ] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Photo title') + 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('Description' in results[0]['content']) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "photo": [ + { "id": "15751017054", "owner": "66847915@N08", + "secret": "69c22afc40", "server": "7285", "farm": 8, + "title": "Photo title", "ispublic": 1, + "isfriend": 0, "isfamily": 0, + "description": { "_content": "Description" }, + "ownername": "Owner", + "url_z": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_z.jpg", + "height_z": "507", "width_z": "640" } + ] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Photo title') + 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('Description' in results[0]['content']) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "photo": [ + { "id": "15751017054", "owner": "66847915@N08", + "secret": "69c22afc40", "server": "7285", "farm": 8, + "title": "Photo title", "ispublic": 1, + "isfriend": 0, "isfamily": 0, + "description": { "_content": "Description" }, + "ownername": "Owner", + "url_o": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_9178e0f963_o.jpg", + "height_o": "2100", "width_o": "2653" } + ] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Photo title') + 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('Description' in results[0]['content']) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "photo": [ + { "id": "15751017054", "owner": "66847915@N08", + "secret": "69c22afc40", "server": "7285", "farm": 8, + "title": "Photo title", "ispublic": 1, + "isfriend": 0, "isfamily": 0, + "description": { "_content": "Description" }, + "ownername": "Owner", + "url_n": "https:\/\/farm8.staticflickr.com\/7285\/15751017054_69c22afc40_n.jpg", + "height_n": "253", "width_n": "320" } + ] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { "photos": { "page": 1, "pages": "41001", "perpage": 100, "total": "4100032", + "toto": [] }, "stat": "ok" } + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.flickr.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = flickr.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index b42b1b89c..35280a329 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,5 +1,6 @@ from searx.tests.engines.test_bing import * # noqa from searx.tests.engines.test_deezer import * # noqa from searx.tests.engines.test_dummy import * # noqa +from searx.tests.engines.test_flickr import * # noqa from searx.tests.engines.test_github import * # noqa from searx.tests.engines.test_mixcloud import * # noqa -- cgit v1.2.3 From 4dba3739fb3b98572cbd51adab226376b5844105 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Mon, 26 Jan 2015 18:24:08 +0100 Subject: Youtube's unit test --- searx/tests/engines/test_youtube.py | 204 ++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 205 insertions(+) create mode 100644 searx/tests/engines/test_youtube.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_youtube.py b/searx/tests/engines/test_youtube.py new file mode 100644 index 000000000..434305228 --- /dev/null +++ b/searx/tests/engines/test_youtube.py @@ -0,0 +1,204 @@ +from collections import defaultdict +import mock +from searx.engines import youtube +from searx.testing import SearxTestCase + + +class TestYoutubeEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'fr_FR' + params = youtube.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('youtube.com' in params['url']) + self.assertTrue('fr' in params['url']) + + dicto['language'] = 'all' + params = youtube.request(query, dicto) + self.assertFalse('fr' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, youtube.response, None) + self.assertRaises(AttributeError, youtube.response, []) + self.assertRaises(AttributeError, youtube.response, '') + self.assertRaises(AttributeError, youtube.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(youtube.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(youtube.response(response), []) + + json = """ + {"feed":{"entry":[{ + "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}, + "published":{"$t":"2015-01-23T21:25:00.000Z"}, + "updated":{"$t":"2015-01-26T14:38:15.000Z"}, + "title":{"$t":"Title", + "type":"text"},"content":{"$t":"Description","type":"text"}, + "link":[{"rel":"alternate","type":"text/html", + "href":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata"}, + {"rel":"http://gdata.youtube.com/schemas/2007#video.related", + "type":"application/atom+xml", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"}, + {"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html", + "href":"https://m.youtube.com/details?v=DIVZCPfAOeM"}, + {"rel":"self","type":"application/atom+xml", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}], + "author":[{"name":{"$t":"Cauet"}, + "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }], + "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments", + "countHint":8} }, + "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy", + "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}], + "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata", + "type":"application/x-shockwave-flash","medium":"video", + "isDefault":"true","expression":"full","duration":354,"yt$format":5}, + {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", + "type":"video/3gpp","medium":"video","expression":"full","duration":354, + "yt$format":1}, + {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", + "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}], + "media$description":{"$t":"Desc","type":"plain"}, + "media$keywords":{}, + "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}], + "media$thumbnail":[{"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg", + "height":360,"width":480,"time":"00:02:57"}, + {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/1.jpg","height":90,"width":120,"time":"00:01:28.500"}, + {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/2.jpg","height":90,"width":120,"time":"00:02:57"}, + {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/3.jpg","height":90,"width":120,"time":"00:04:25.500"}], + "media$title":{"$t":"Title","type":"plain"}, + "yt$duration":{"seconds":"354"} }, + "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533, + "rel":"http://schemas.google.com/g/2005#overall"}, + "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} } + ] + } + } + """ + response = mock.Mock(text=json) + results = youtube.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM') + self.assertEqual(results[0]['content'], 'Description') + self.assertEqual(results[0]['thumbnail'], 'https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg') + self.assertTrue('DIVZCPfAOeM' in results[0]['embedded']) + + json = """ + {"feed":{"entry":[{ + "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}, + "published":{"$t":"2015-01-23T21:25:00.000Z"}, + "updated":{"$t":"2015-01-26T14:38:15.000Z"}, + "title":{"$t":"Title", + "type":"text"},"content":{"$t":"Description","type":"text"}, + "link":[{"rel":"http://gdata.youtube.com/schemas/2007#video.related", + "type":"application/atom+xml", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"}, + {"rel":"self","type":"application/atom+xml", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}], + "author":[{"name":{"$t":"Cauet"}, + "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }], + "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments", + "countHint":8} }, + "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy", + "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}], + "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata", + "type":"application/x-shockwave-flash","medium":"video", + "isDefault":"true","expression":"full","duration":354,"yt$format":5}, + {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", + "type":"video/3gpp","medium":"video","expression":"full","duration":354, + "yt$format":1}, + {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", + "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}], + "media$description":{"$t":"Desc","type":"plain"}, + "media$keywords":{}, + "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}], + "media$thumbnail":[{"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/0.jpg", + "height":360,"width":480,"time":"00:02:57"}, + {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/1.jpg","height":90,"width":120,"time":"00:01:28.500"}, + {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/2.jpg","height":90,"width":120,"time":"00:02:57"}, + {"url":"https://i.ytimg.com/vi/DIVZCPfAOeM/3.jpg","height":90,"width":120,"time":"00:04:25.500"}], + "media$title":{"$t":"Title","type":"plain"}, + "yt$duration":{"seconds":"354"} }, + "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533, + "rel":"http://schemas.google.com/g/2005#overall"}, + "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} } + ] + } + } + """ + response = mock.Mock(text=json) + results = youtube.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + {"feed":{"entry":[{ + "id":{"$t":"http://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}, + "published":{"$t":"2015-01-23T21:25:00.000Z"}, + "updated":{"$t":"2015-01-26T14:38:15.000Z"}, + "title":{"$t":"Title", + "type":"text"},"content":{"$t":"Description","type":"text"}, + "link":[{"rel":"alternate","type":"text/html", + "href":"https://www.youtube.com/watch?v=DIVZCPfAOeM"}, + {"rel":"http://gdata.youtube.com/schemas/2007#video.related", + "type":"application/atom+xml", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/related"}, + {"rel":"http://gdata.youtube.com/schemas/2007#mobile","type":"text/html", + "href":"https://m.youtube.com/details?v=DIVZCPfAOeM"}, + {"rel":"self","type":"application/atom+xml", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM"}], + "author":[{"name":{"$t":"Cauet"}, + "uri":{"$t":"https://gdata.youtube.com/feeds/api/users/cauetofficiel"} }], + "gd$comments":{"gd$feedLink":{"rel":"http://gdata.youtube.com/schemas/2007#comments", + "href":"https://gdata.youtube.com/feeds/api/videos/DIVZCPfAOeM/comments", + "countHint":8} }, + "media$group":{"media$category":[{"$t":"Comedy","label":"Comedy", + "scheme":"http://gdata.youtube.com/schemas/2007/categories.cat"}], + "media$content":[{"url":"https://www.youtube.com/v/DIVZCPfAOeM?version=3&f=videos&app=youtube_gdata", + "type":"application/x-shockwave-flash","medium":"video", + "isDefault":"true","expression":"full","duration":354,"yt$format":5}, + {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYDSANFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", + "type":"video/3gpp","medium":"video","expression":"full","duration":354, + "yt$format":1}, + {"url":"rtsp://r1---sn-cg07luel.c.youtube.com/CiILENy73wIaGQnjOcD3CFmFDBMYESARFEgGUgZ2aWRlb3MM/0/0/0/video.3gp", + "type":"video/3gpp","medium":"video","expression":"full","duration":354,"yt$format":6}], + "media$description":{"$t":"Desc","type":"plain"}, + "media$keywords":{}, + "media$player":[{"url":"https://www.youtube.com/watch?v=DIVZCPfAOeM&feature=youtube_gdata_player"}], + "media$title":{"$t":"Title","type":"plain"}, + "yt$duration":{"seconds":"354"} }, + "gd$rating":{"average":4.932159,"max":5,"min":1,"numRaters":1533, + "rel":"http://schemas.google.com/g/2005#overall"}, + "yt$statistics":{"favoriteCount":"0","viewCount":"92464"} } + ] + } + } + """ + response = mock.Mock(text=json) + results = youtube.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'https://www.youtube.com/watch?v=DIVZCPfAOeM') + self.assertEqual(results[0]['content'], 'Description') + self.assertEqual(results[0]['thumbnail'], '') + self.assertTrue('DIVZCPfAOeM' in results[0]['embedded']) + + json = """ + {"toto":{"entry":[] + } + } + """ + response = mock.Mock(text=json) + results = youtube.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 35280a329..b99c30070 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -4,3 +4,4 @@ from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa from searx.tests.engines.test_github import * # noqa from searx.tests.engines.test_mixcloud import * # noqa +from searx.tests.engines.test_youtube import * # noqa -- cgit v1.2.3 From cfe81d741cdd2517c4587071e4afbdd0adb923bd Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Tue, 27 Jan 2015 20:03:33 +0100 Subject: A bit of utils unit tests --- searx/tests/test_utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'searx/tests') diff --git a/searx/tests/test_utils.py b/searx/tests/test_utils.py index 817fd4372..abe411c2b 100644 --- a/searx/tests/test_utils.py +++ b/searx/tests/test_utils.py @@ -10,6 +10,11 @@ class TestUtils(SearxTestCase): self.assertIsNotNone(utils.gen_useragent()) self.assertTrue(utils.gen_useragent().startswith('Mozilla')) + def test_searx_useragent(self): + self.assertIsInstance(utils.searx_useragent(), str) + self.assertIsNotNone(utils.searx_useragent()) + self.assertTrue(utils.searx_useragent().startswith('searx')) + def test_highlight_content(self): self.assertEqual(utils.highlight_content(0, None), None) self.assertEqual(utils.highlight_content(None, None), None) @@ -29,6 +34,23 @@ class TestUtils(SearxTestCase): query = 'a test' self.assertEqual(utils.highlight_content(content, query), content) + def test_html_to_text(self): + html = """ + + """ + self.assertIsInstance(utils.html_to_text(html), unicode) + self.assertIsNotNone(utils.html_to_text(html)) + self.assertEqual(utils.html_to_text(html), "Test text") + class TestHTMLTextExtractor(SearxTestCase): -- cgit v1.2.3 From eca5de73a7f38958d3ba14930b42aaa5a5fbf989 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Tue, 27 Jan 2015 22:37:11 +0100 Subject: Searchcode code's test unit --- searx/tests/engines/test_searchcode_code.py | 75 +++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 76 insertions(+) create mode 100644 searx/tests/engines/test_searchcode_code.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_searchcode_code.py b/searx/tests/engines/test_searchcode_code.py new file mode 100644 index 000000000..c0ac2025c --- /dev/null +++ b/searx/tests/engines/test_searchcode_code.py @@ -0,0 +1,75 @@ +from collections import defaultdict +import mock +from searx.engines import searchcode_code +from searx.testing import SearxTestCase + + +class TestSearchcodeCodeEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = searchcode_code.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('searchcode.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, searchcode_code.response, None) + self.assertRaises(AttributeError, searchcode_code.response, []) + self.assertRaises(AttributeError, searchcode_code.response, '') + self.assertRaises(AttributeError, searchcode_code.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(searchcode_code.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(searchcode_code.response(response), []) + + json = """ + { + "matchterm": "test", + "previouspage": null, + "searchterm": "test", + "query": "test", + "total": 1000, + "page": 0, + "nextpage": 1, + "results": [ + { + "repo": "https://repo", + "linescount": 1044, + "location": "/tests", + "name": "Name", + "url": "https://url", + "md5hash": "ecac6e479edd2b9406c9e08603cec655", + "lines": { + "1": "// Test 011", + "2": "// Source: " + }, + "id": 51223527, + "filename": "File.CPP" + } + ] + } + """ + response = mock.Mock(text=json) + results = searchcode_code.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Name - File.CPP') + self.assertEqual(results[0]['url'], 'https://url') + self.assertEqual(results[0]['repository'], 'https://repo') + self.assertEqual(results[0]['code_language'], 'cpp') + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.searchcode_code.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = searchcode_code.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index b99c30070..e7648bc08 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -4,4 +4,5 @@ from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa from searx.tests.engines.test_github import * # noqa from searx.tests.engines.test_mixcloud import * # noqa +from searx.tests.engines.test_searchcode_code import * # noqa from searx.tests.engines.test_youtube import * # noqa -- cgit v1.2.3 From 0f81aa8410623e790f4ad01b32e2b37f6258356a Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Tue, 27 Jan 2015 22:38:56 +0100 Subject: Searchcode doc's test unit --- searx/tests/engines/test_searchcode_doc.py | 73 ++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 74 insertions(+) create mode 100644 searx/tests/engines/test_searchcode_doc.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_searchcode_doc.py b/searx/tests/engines/test_searchcode_doc.py new file mode 100644 index 000000000..b9dcf380b --- /dev/null +++ b/searx/tests/engines/test_searchcode_doc.py @@ -0,0 +1,73 @@ +from collections import defaultdict +import mock +from searx.engines import searchcode_doc +from searx.testing import SearxTestCase + + +class TestSearchcodeDocEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = searchcode_doc.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('searchcode.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, searchcode_doc.response, None) + self.assertRaises(AttributeError, searchcode_doc.response, []) + self.assertRaises(AttributeError, searchcode_doc.response, '') + self.assertRaises(AttributeError, searchcode_doc.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(searchcode_doc.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(searchcode_doc.response(response), []) + + json = """ + { + "matchterm": "test", + "previouspage": null, + "searchterm": "test", + "query": "test", + "total": 60, + "page": 0, + "nextpage": 1, + "results": [ + { + "synopsis": "Synopsis", + "displayname": null, + "name": "test", + "url": "http://url", + "type": "Type", + "icon": null, + "namespace": "Namespace", + "description": "Description" + } + ] + } + """ + response = mock.Mock(text=json) + results = searchcode_doc.response(response) + self.assertEqual(type(results), list) + 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 = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.searchcode_doc.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = searchcode_doc.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index e7648bc08..f46e3dc2a 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -5,4 +5,5 @@ from searx.tests.engines.test_flickr import * # noqa from searx.tests.engines.test_github import * # noqa from searx.tests.engines.test_mixcloud import * # noqa from searx.tests.engines.test_searchcode_code import * # noqa +from searx.tests.engines.test_searchcode_doc import * # noqa from searx.tests.engines.test_youtube import * # noqa -- cgit v1.2.3 From 92368a410749a4a057b476eb10c524f0fc133a0b Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Tue, 27 Jan 2015 23:20:57 +0100 Subject: Dailymotion's unit test --- searx/tests/engines/test_dailymotion.py | 74 +++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 75 insertions(+) create mode 100644 searx/tests/engines/test_dailymotion.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_dailymotion.py b/searx/tests/engines/test_dailymotion.py new file mode 100644 index 000000000..4c31ff5d5 --- /dev/null +++ b/searx/tests/engines/test_dailymotion.py @@ -0,0 +1,74 @@ +from collections import defaultdict +import mock +from searx.engines import dailymotion +from searx.testing import SearxTestCase + + +class TestDailymotionEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + dicto['language'] = 'fr_FR' + params = dailymotion.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('dailymotion.com' in params['url']) + self.assertTrue('fr' in params['url']) + + dicto['language'] = 'all' + params = dailymotion.request(query, dicto) + self.assertTrue('en' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, dailymotion.response, None) + self.assertRaises(AttributeError, dailymotion.response, []) + self.assertRaises(AttributeError, dailymotion.response, '') + self.assertRaises(AttributeError, dailymotion.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(dailymotion.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(dailymotion.response(response), []) + + json = """ + { + "page": 1, + "limit": 5, + "explicit": false, + "total": 289487, + "has_more": true, + "list": [ + { + "created_time": 1422173451, + "title": "Title", + "description": "Description", + "duration": 81, + "url": "http://www.url", + "thumbnail_360_url": "http://thumbnail", + "id": "x2fit7q" + } + ] + } + """ + response = mock.Mock(text=json) + results = dailymotion.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://www.url') + self.assertEqual(results[0]['content'], 'Description') + self.assertIn('x2fit7q', results[0]['embedded']) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.dailymotion.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = dailymotion.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index f46e3dc2a..64d220bcd 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,4 +1,5 @@ from searx.tests.engines.test_bing import * # noqa +from searx.tests.engines.test_dailymotion import * # noqa from searx.tests.engines.test_deezer import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa -- cgit v1.2.3 From 1d255061c7422045ef912a471500513832e0319f Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Thu, 29 Jan 2015 00:26:12 +0100 Subject: Digg's unit test --- searx/tests/engines/test_digg.py | 57 ++++++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 58 insertions(+) create mode 100644 searx/tests/engines/test_digg.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_digg.py b/searx/tests/engines/test_digg.py new file mode 100644 index 000000000..7e9006c0d --- /dev/null +++ b/searx/tests/engines/test_digg.py @@ -0,0 +1,57 @@ +from collections import defaultdict +import mock +from searx.engines import digg +from searx.testing import SearxTestCase + + +class TestDiggEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = digg.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('digg.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, digg.response, None) + self.assertRaises(AttributeError, digg.response, []) + self.assertRaises(AttributeError, digg.response, '') + self.assertRaises(AttributeError, digg.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(digg.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(digg.response(response), []) + + json = """ + { + "status": "ok", + "num": 10, + "next_position": 20, + "html": "" + } + """ + response = mock.Mock(text=json) + results = digg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of article') + self.assertEqual(results[0]['url'], 'http://url.of.link') + self.assertEqual(results[0]['thumbnail'], 'http://url.of.image.jpeg') + self.assertEqual(results[0]['content'], '') + + json = """ + { + "status": "error", + "num": 10, + "next_position": 20 + } + """ + response = mock.Mock(text=json) + results = digg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 64d220bcd..309e83f16 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,6 +1,7 @@ from searx.tests.engines.test_bing import * # noqa from searx.tests.engines.test_dailymotion import * # noqa from searx.tests.engines.test_deezer import * # noqa +from searx.tests.engines.test_digg import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa from searx.tests.engines.test_github import * # noqa -- cgit v1.2.3 From d4957045513d6fb32dcffbc7ea87483479a8cb6e Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Thu, 29 Jan 2015 01:13:33 +0100 Subject: Deviant Art's unit test --- searx/tests/engines/test_deviantart.py | 118 +++++++++++++++++++++++++++++++++ searx/tests/engines/test_digg.py | 46 ++++++++++++- searx/tests/test_engines.py | 1 + 3 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 searx/tests/engines/test_deviantart.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_deviantart.py b/searx/tests/engines/test_deviantart.py new file mode 100644 index 000000000..9cf68d0b8 --- /dev/null +++ b/searx/tests/engines/test_deviantart.py @@ -0,0 +1,118 @@ +from collections import defaultdict +import mock +from searx.engines import deviantart +from searx.testing import SearxTestCase + + +class TestDeviantartEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = deviantart.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('deviantart.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, deviantart.response, None) + self.assertRaises(AttributeError, deviantart.response, []) + self.assertRaises(AttributeError, deviantart.response, '') + self.assertRaises(AttributeError, deviantart.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(deviantart.response(response), []) + + response = mock.Mock(status_code=302) + self.assertEqual(deviantart.response(response), []) + + html = """ +
    + + + + + + + Test + + + + + + + Title of image + + + + 5 years ago + + in Animation + + + + More Like This + + + +
    + """ + response = mock.Mock(text=html) + results = deviantart.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title of image') + self.assertEqual(results[0]['url'], 'http://url.of.result/2nd.part.of.url') + self.assertNotIn('content', results[0]) + self.assertEqual(results[0]['thumbnail_src'], 'http://url.of.thumbnail') + + html = """ + + + + + + Test + + + + + + + Title of image + + + + 5 years ago + + in Animation + + + + More Like This + + + """ + response = mock.Mock(text=html) + results = deviantart.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/engines/test_digg.py b/searx/tests/engines/test_digg.py index 7e9006c0d..6e7c9cc99 100644 --- a/searx/tests/engines/test_digg.py +++ b/searx/tests/engines/test_digg.py @@ -32,9 +32,53 @@ class TestDiggEngine(SearxTestCase): "status": "ok", "num": 10, "next_position": 20, - "html": "" + "html": "" } """ + json = json.replace('\r\n', '').replace('\n', '').replace('\r', '') response = mock.Mock(text=json) results = digg.response(response) self.assertEqual(type(results), list) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 309e83f16..561b436ff 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,6 +1,7 @@ from searx.tests.engines.test_bing import * # noqa from searx.tests.engines.test_dailymotion import * # noqa from searx.tests.engines.test_deezer import * # noqa +from searx.tests.engines.test_deviantart import * # noqa from searx.tests.engines.test_digg import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa -- cgit v1.2.3 From dad0434f34f04ada2b4b0961bbb714e25c752677 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Thu, 29 Jan 2015 20:15:52 +0100 Subject: Bing images' unit test --- searx/tests/engines/test_bing_images.py | 268 ++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 269 insertions(+) create mode 100644 searx/tests/engines/test_bing_images.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_bing_images.py b/searx/tests/engines/test_bing_images.py new file mode 100644 index 000000000..59c134623 --- /dev/null +++ b/searx/tests/engines/test_bing_images.py @@ -0,0 +1,268 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import bing_images +from searx.testing import SearxTestCase + + +class TestBingImagesEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = bing_images.request(query, dicto) + self.assertTrue('url' in params) + 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']) + + dicto['language'] = 'all' + params = bing_images.request(query, dicto) + self.assertIn('SRCHHPGUSR', params['cookies']) + self.assertIn('en', params['cookies']['SRCHHPGUSR']) + + def test_response(self): + self.assertRaises(AttributeError, bing_images.response, None) + self.assertRaises(AttributeError, bing_images.response, []) + self.assertRaises(AttributeError, bing_images.response, '') + self.assertRaises(AttributeError, bing_images.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(bing_images.response(response), []) + + response = mock.Mock(content='') + self.assertEqual(bing_images.response(response), []) + + html = """ +
    + + + +
    + """ + html = html.replace('\r\n', '').replace('\n', '').replace('\r', '') + response = mock.Mock(content=html) + results = bing_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Test Query') + self.assertEqual(results[0]['url'], 'http://www.page.url/') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['thumbnail_src'], 'http://ts1.mm.bing.net/th?id=HN.608003696942779811') + self.assertEqual(results[0]['img_src'], 'http://test.url/Test%20Query.jpg') + + html = """ + + + + """ + response = mock.Mock(content=html) + results = bing_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + html = """ +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    +
    + + + +
    + """ + html = html.replace('\r\n', '').replace('\n', '').replace('\r', '') + response = mock.Mock(content=html) + results = bing_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 10) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 561b436ff..fab911d13 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,4 +1,5 @@ from searx.tests.engines.test_bing import * # noqa +from searx.tests.engines.test_bing_images import * # noqa from searx.tests.engines.test_dailymotion import * # noqa from searx.tests.engines.test_deezer import * # noqa from searx.tests.engines.test_deviantart import * # noqa -- cgit v1.2.3 From efde2c21c8656ad21b24980b516ddbbf2e209523 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Thu, 29 Jan 2015 20:56:57 +0100 Subject: Bing news' unit test I have no idea why coverage tell 97% and 2 misses in branches. If anyone has an idea... --- searx/tests/engines/test_bing_news.py | 236 ++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 237 insertions(+) create mode 100644 searx/tests/engines/test_bing_news.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_bing_news.py b/searx/tests/engines/test_bing_news.py new file mode 100644 index 000000000..f22b80e87 --- /dev/null +++ b/searx/tests/engines/test_bing_news.py @@ -0,0 +1,236 @@ +from collections import defaultdict +import mock +from searx.engines import bing_news +from searx.testing import SearxTestCase + + +class TestBingNewsEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + params = bing_news.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('bing.com', params['url']) + self.assertIn('fr', params['url']) + self.assertIn('_FP', params['cookies']) + self.assertIn('en', params['cookies']['_FP']) + + dicto['language'] = 'all' + params = bing_news.request(query, dicto) + self.assertIn('en', params['url']) + self.assertIn('_FP', params['cookies']) + self.assertIn('en', params['cookies']['_FP']) + + def test_response(self): + self.assertRaises(AttributeError, bing_news.response, None) + self.assertRaises(AttributeError, bing_news.response, []) + self.assertRaises(AttributeError, bing_news.response, '') + self.assertRaises(AttributeError, bing_news.response, '[]') + + response = mock.Mock(content='') + self.assertEqual(bing_news.response(response), []) + + response = mock.Mock(content='') + self.assertEqual(bing_news.response(response), []) + + html = """ +
    + +
    + + + +
    +
    +
    + Article Content + + metronews.fr +  · + 44 minutes ago + +
    +
    +
    + """ + response = mock.Mock(content=html) + results = bing_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Title') + self.assertEqual(results[0]['url'], 'http://url.of.article/') + self.assertEqual(results[0]['content'], 'Article Content') + + html = """ +
    + +
    + + + +
    +
    +
    + Article Content + + metronews.fr +  · + 44 minutes ago + +
    +
    +
    +
    + +
    + + + +
    +
    +
    + Article Content + + metronews.fr +  · + 3 hours, 44 minutes ago + +
    +
    +
    +
    + +
    + + + +
    +
    +
    + Article Content + + metronews.fr +  · + 44 hours ago + +
    +
    +
    +
    + +
    + + + +
    +
    +
    + Article Content + + metronews.fr +  · + 2 days ago + +
    +
    +
    +
    + +
    + + + +
    +
    +
    + Article Content + + metronews.fr +  · + 27/01/2015 + +
    +
    +
    +
    + +
    + + + +
    +
    +
    + Article Content + + metronews.fr +  · + Il y a 3 heures + +
    +
    +
    + """ + response = mock.Mock(content=html) + results = bing_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 6) + + html = """ + +
    + + + +
    +
    +
    + Article Content + + metronews.fr +  · + 44 minutes ago + +
    +
    + """ + response = mock.Mock(content=html) + results = bing_news.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index fab911d13..bfdd1de4c 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,5 +1,6 @@ from searx.tests.engines.test_bing import * # noqa from searx.tests.engines.test_bing_images import * # noqa +from searx.tests.engines.test_bing_news import * # noqa from searx.tests.engines.test_dailymotion import * # noqa from searx.tests.engines.test_deezer import * # noqa from searx.tests.engines.test_deviantart import * # noqa -- cgit v1.2.3 From a3d444ab85dbb85dc3200c686ec3323dbb7008cb Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Fri, 30 Jan 2015 19:52:44 +0100 Subject: BTDigg's unit test --- searx/tests/engines/test_btdigg.py | 384 +++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 385 insertions(+) create mode 100644 searx/tests/engines/test_btdigg.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_btdigg.py b/searx/tests/engines/test_btdigg.py new file mode 100644 index 000000000..4947b71da --- /dev/null +++ b/searx/tests/engines/test_btdigg.py @@ -0,0 +1,384 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import btdigg +from searx.testing import SearxTestCase + + +class TestBtdiggEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = btdigg.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('btdigg.org', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, btdigg.response, None) + self.assertRaises(AttributeError, btdigg.response, []) + self.assertRaises(AttributeError, btdigg.response, '') + self.assertRaises(AttributeError, btdigg.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(btdigg.response(response), []) + + html = """ +
    + + + + + +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 8 B + + Fichiers: + 710 + + Téléchargements: + 5 + + Temps: + 417.8 jours + + Dernière mise Ã  jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    +
    + """ + response = mock.Mock(text=html) + results = btdigg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['title'], 'Should be the title') + self.assertEqual(results[0]['url'], 'https://btdigg.org/url') + self.assertEqual(results[0]['content'], 'Content') + self.assertEqual(results[0]['seed'], 5) + self.assertEqual(results[0]['leech'], 0) + self.assertEqual(results[0]['filesize'], 8) + self.assertEqual(results[0]['files'], 710) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:magnet&dn=Test') + + html = """ +
    + +
    +
    + """ + response = mock.Mock(text=html) + results = btdigg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + html = """ +
    + + + + + + + + + + + + + + + + + + + + + +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 1 KB + + Fichiers: + 710 + + Téléchargements: + 5 + + Temps: + 417.8 jours + + Dernière mise Ã  jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 1 MB + + Fichiers: + a + + Téléchargements: + 4 + + Temps: + 417.8 jours + + Dernière mise Ã  jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 1 GB + + Fichiers: + 710 + + Téléchargements: + 3 + + Temps: + 417.8 jours + + Dernière mise Ã  jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + 1 TB + + Fichiers: + 710 + + Téléchargements: + 2 + + Temps: + 417.8 jours + + Dernière mise Ã  jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    1 + + + + +
    + Should be the title +
    + + + + + + + + + + + +
    + [magnet] + + [cloud] + + Taille: + a TB + + Fichiers: + 710 + + Téléchargements: + z + + Temps: + 417.8 jours + + Dernière mise Ã  jour: + 5.3 jours + + Faux: + Aucun +
    +
    +                            Content
    +                        
    +
    +
    + """ + response = mock.Mock(text=html) + results = btdigg.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 5) + self.assertEqual(results[0]['title'], 'Should be the title') + self.assertEqual(results[0]['url'], 'https://btdigg.org/url') + self.assertEqual(results[0]['content'], 'Content') + self.assertEqual(results[0]['seed'], 5) + self.assertEqual(results[0]['leech'], 0) + self.assertEqual(results[0]['files'], 710) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:magnet&dn=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) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index bfdd1de4c..b07444e42 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,6 +1,7 @@ from searx.tests.engines.test_bing import * # noqa from searx.tests.engines.test_bing_images import * # noqa from searx.tests.engines.test_bing_news import * # noqa +from searx.tests.engines.test_btdigg import * # noqa from searx.tests.engines.test_dailymotion import * # noqa from searx.tests.engines.test_deezer import * # noqa from searx.tests.engines.test_deviantart import * # noqa -- cgit v1.2.3 From 8ea749d6ec0b711c516f3dbdb34a1bd17ae7d945 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Fri, 30 Jan 2015 21:02:17 +0100 Subject: Kickass' unit test --- searx/tests/engines/test_kickass.py | 398 ++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 399 insertions(+) create mode 100644 searx/tests/engines/test_kickass.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_kickass.py b/searx/tests/engines/test_kickass.py new file mode 100644 index 000000000..3c20a97e7 --- /dev/null +++ b/searx/tests/engines/test_kickass.py @@ -0,0 +1,398 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import kickass +from searx.testing import SearxTestCase + + +class TestKickassEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = kickass.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('kickass.so', params['url']) + self.assertIn('verify', params) + self.assertFalse(params['verify']) + + def test_response(self): + self.assertRaises(AttributeError, kickass.response, None) + self.assertRaises(AttributeError, kickass.response, []) + self.assertRaises(AttributeError, kickass.response, '') + self.assertRaises(AttributeError, kickass.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(kickass.response(response), []) + + html = """ + + + + + + + + + + + + + + + + + +
    torrent name + size + + files + + age + + seed + + leech +
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    449 bytes42 years101
    + """ + response = mock.Mock(text=html) + results = kickass.response(response) + 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.so/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) + 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') + + html = """ + + + + + + + + + +
    torrent name + size + + files + + age + + seed + + leech +
    + """ + response = mock.Mock(text=html) + results = kickass.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + html = """ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    torrent name + size + + files + + age + + seed + + leech +
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    1 KB42 years101
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    1 MB42 years91
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    1 GB42 years81
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    1 TB42 years71
    + +
    + + +
    + + This should be the title + + + Posted by + riri in + + Other > Unsorted + + +
    +
    z bytesr2 yearsat
    + """ + response = mock.Mock(text=html) + results = kickass.response(response) + 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.so/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[4]['seed'], 0) + self.assertEqual(results[4]['leech'], 0) + self.assertEqual(results[4]['files'], None) + self.assertEqual(results[4]['filesize'], None) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index b07444e42..66f8fbff7 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -9,6 +9,7 @@ from searx.tests.engines.test_digg import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa from searx.tests.engines.test_github import * # noqa +from searx.tests.engines.test_kickass import * # noqa from searx.tests.engines.test_mixcloud import * # noqa from searx.tests.engines.test_searchcode_code import * # noqa from searx.tests.engines.test_searchcode_doc import * # noqa -- cgit v1.2.3 From d5b8005ee10054b5260f57c1800ddebfa03c39cf Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sat, 31 Jan 2015 16:16:30 +0100 Subject: Google images' unit test --- searx/tests/engines/test_google_images.py | 108 ++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 109 insertions(+) create mode 100644 searx/tests/engines/test_google_images.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_google_images.py b/searx/tests/engines/test_google_images.py new file mode 100644 index 000000000..6870ff52f --- /dev/null +++ b/searx/tests/engines/test_google_images.py @@ -0,0 +1,108 @@ +from collections import defaultdict +import mock +from searx.engines import google_images +from searx.testing import SearxTestCase + + +class TestGoogleImagesEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = google_images.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('googleapis.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, google_images.response, None) + self.assertRaises(AttributeError, google_images.response, []) + self.assertRaises(AttributeError, google_images.response, '') + self.assertRaises(AttributeError, google_images.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(google_images.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(google_images.response(response), []) + + json = """ + { + "responseData": { + "results": [ + { + "GsearchResultClass": "GimageSearch", + "width": "400", + "height": "400", + "imageId": "ANd9GcQbYb9FJuAbG_hT4i8FeC0O0x-P--EHdzgRIF9ao97nHLl7C2mREn6qTQ", + "tbWidth": "124", + "tbHeight": "124", + "unescapedUrl": "http://unescaped.url.jpg", + "url": "http://image.url.jpg", + "visibleUrl": "insolitebuzz.fr", + "title": "This is the title", + "titleNoFormatting": "Petit test sympa qui rend fou tout le monde ! A faire", + "originalContextUrl": "http://this.is.the.url", + "content": "test", + "contentNoFormatting": "test", + "tbUrl": "http://thumbnail.url" + } + ] + }, + "responseDetails": null, + "responseStatus": 200 + } + """ + response = mock.Mock(text=json) + results = google_images.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'], 'http://this.is.the.url') + self.assertEqual(results[0]['thumbnail_src'], 'http://thumbnail.url') + self.assertEqual(results[0]['img_src'], 'http://image.url.jpg') + self.assertEqual(results[0]['content'], 'test') + + json = """ + { + "responseData": { + "results": [ + { + "GsearchResultClass": "GimageSearch", + "width": "400", + "height": "400", + "imageId": "ANd9GcQbYb9FJuAbG_hT4i8FeC0O0x-P--EHdzgRIF9ao97nHLl7C2mREn6qTQ", + "tbWidth": "124", + "tbHeight": "124", + "unescapedUrl": "http://unescaped.url.jpg", + "visibleUrl": "insolitebuzz.fr", + "title": "This is the title", + "titleNoFormatting": "Petit test sympa qui rend fou tout le monde ! A faire", + "originalContextUrl": "http://this.is.the.url", + "content": "test", + "contentNoFormatting": "test", + "tbUrl": "http://thumbnail.url" + } + ] + }, + "responseDetails": null, + "responseStatus": 200 + } + """ + response = mock.Mock(text=json) + results = google_images.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_images.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 66f8fbff7..e609f9a5c 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -9,6 +9,7 @@ from searx.tests.engines.test_digg import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa from searx.tests.engines.test_github import * # noqa +from searx.tests.engines.test_google_images import * # noqa from searx.tests.engines.test_kickass import * # noqa from searx.tests.engines.test_mixcloud import * # noqa from searx.tests.engines.test_searchcode_code import * # noqa -- cgit v1.2.3 From b7dc1fb9d572d53d04c0120d96c76a20a418cc94 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sat, 31 Jan 2015 16:38:03 +0100 Subject: Google news' unit test --- searx/tests/engines/test_google_news.py | 136 ++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 137 insertions(+) create mode 100644 searx/tests/engines/test_google_news.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_google_news.py b/searx/tests/engines/test_google_news.py new file mode 100644 index 000000000..31d674121 --- /dev/null +++ b/searx/tests/engines/test_google_news.py @@ -0,0 +1,136 @@ +from collections import defaultdict +import mock +from searx.engines import google_news +from searx.testing import SearxTestCase + + +class TestGoogleNewsEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['language'] = 'fr_FR' + 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']) + + def test_response(self): + self.assertRaises(AttributeError, google_news.response, None) + self.assertRaises(AttributeError, google_news.response, []) + self.assertRaises(AttributeError, google_news.response, '') + self.assertRaises(AttributeError, google_news.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(google_news.response(response), []) + + 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": "Test 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) + 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]['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) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index e609f9a5c..00ac8ffdf 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -10,6 +10,7 @@ from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa from searx.tests.engines.test_github import * # noqa from searx.tests.engines.test_google_images import * # noqa +from searx.tests.engines.test_google_news import * # noqa from searx.tests.engines.test_kickass import * # noqa from searx.tests.engines.test_mixcloud import * # noqa from searx.tests.engines.test_searchcode_code import * # noqa -- cgit v1.2.3 From 787fee6a09f5569f67e7bddaf73d52e159c0431c Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sat, 31 Jan 2015 17:10:37 +0100 Subject: Soundcloud's unit test --- searx/tests/engines/test_soundcloud.py | 192 +++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 193 insertions(+) create mode 100644 searx/tests/engines/test_soundcloud.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_soundcloud.py b/searx/tests/engines/test_soundcloud.py new file mode 100644 index 000000000..85495dc57 --- /dev/null +++ b/searx/tests/engines/test_soundcloud.py @@ -0,0 +1,192 @@ +from collections import defaultdict +import mock +from searx.engines import soundcloud +from searx.testing import SearxTestCase +from urllib import quote_plus + + +class TestSoundcloudEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = soundcloud.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('soundcloud.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, soundcloud.response, None) + self.assertRaises(AttributeError, soundcloud.response, []) + self.assertRaises(AttributeError, soundcloud.response, '') + self.assertRaises(AttributeError, soundcloud.response, '[]') + + response = mock.Mock(text='{}') + self.assertEqual(soundcloud.response(response), []) + + response = mock.Mock(text='{"data": []}') + self.assertEqual(soundcloud.response(response), []) + + json = """ + { + "collection": [ + { + "kind": "track", + "id": 159723640, + "created_at": "2014/07/22 00:51:21 +0000", + "user_id": 2976616, + "duration": 303780, + "commentable": true, + "state": "finished", + "original_content_size": 13236349, + "last_modified": "2015/01/31 15:14:50 +0000", + "sharing": "public", + "tag_list": "seekae flume", + "permalink": "seekae-test-recognise-flume-re-work", + "streamable": true, + "embeddable_by": "all", + "downloadable": true, + "purchase_url": "http://www.facebook.com/seekaemusic", + "label_id": null, + "purchase_title": "Seekae", + "genre": "freedownload", + "title": "This is the title", + "description": "This is the content", + "label_name": "Future Classic", + "release": "", + "track_type": "remix", + "key_signature": "", + "isrc": "", + "video_url": null, + "bpm": null, + "release_year": 2014, + "release_month": 7, + "release_day": 22, + "original_format": "mp3", + "license": "all-rights-reserved", + "uri": "https://api.soundcloud.com/tracks/159723640", + "user": { + "id": 2976616, + "kind": "user", + "permalink": "flume", + "username": "Flume", + "last_modified": "2014/11/24 19:21:29 +0000", + "uri": "https://api.soundcloud.com/users/2976616", + "permalink_url": "http://soundcloud.com/flume", + "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg" + }, + "permalink_url": "http://soundcloud.com/this.is.the.url", + "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg", + "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png", + "stream_url": "https://api.soundcloud.com/tracks/159723640/stream", + "download_url": "https://api.soundcloud.com/tracks/159723640/download", + "playback_count": 2190687, + "download_count": 54856, + "favoritings_count": 49061, + "comment_count": 826, + "likes_count": 49061, + "reposts_count": 15910, + "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments", + "policy": "ALLOW" + } + ], + "total_results": 375750, + "next_href": "https://api.soundcloud.com/search?&q=test", + "tx_id": "" + } + """ + response = mock.Mock(text=json) + results = soundcloud.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'], 'http://soundcloud.com/this.is.the.url') + self.assertEqual(results[0]['content'], 'This is the content') + self.assertIn(quote_plus('https://api.soundcloud.com/tracks/159723640'), results[0]['embedded']) + + json = """ + { + "collection": [ + { + "kind": "user", + "id": 159723640, + "created_at": "2014/07/22 00:51:21 +0000", + "user_id": 2976616, + "duration": 303780, + "commentable": true, + "state": "finished", + "original_content_size": 13236349, + "last_modified": "2015/01/31 15:14:50 +0000", + "sharing": "public", + "tag_list": "seekae flume", + "permalink": "seekae-test-recognise-flume-re-work", + "streamable": true, + "embeddable_by": "all", + "downloadable": true, + "purchase_url": "http://www.facebook.com/seekaemusic", + "label_id": null, + "purchase_title": "Seekae", + "genre": "freedownload", + "title": "This is the title", + "description": "This is the content", + "label_name": "Future Classic", + "release": "", + "track_type": "remix", + "key_signature": "", + "isrc": "", + "video_url": null, + "bpm": null, + "release_year": 2014, + "release_month": 7, + "release_day": 22, + "original_format": "mp3", + "license": "all-rights-reserved", + "uri": "https://api.soundcloud.com/tracks/159723640", + "user": { + "id": 2976616, + "kind": "user", + "permalink": "flume", + "username": "Flume", + "last_modified": "2014/11/24 19:21:29 +0000", + "uri": "https://api.soundcloud.com/users/2976616", + "permalink_url": "http://soundcloud.com/flume", + "avatar_url": "https://i1.sndcdn.com/avatars-000044475439-4zi7ii-large.jpg" + }, + "permalink_url": "http://soundcloud.com/this.is.the.url", + "artwork_url": "https://i1.sndcdn.com/artworks-000085857162-xdxy5c-large.jpg", + "waveform_url": "https://w1.sndcdn.com/DWrL1lAN8BkP_m.png", + "stream_url": "https://api.soundcloud.com/tracks/159723640/stream", + "download_url": "https://api.soundcloud.com/tracks/159723640/download", + "playback_count": 2190687, + "download_count": 54856, + "favoritings_count": 49061, + "comment_count": 826, + "likes_count": 49061, + "reposts_count": 15910, + "attachments_uri": "https://api.soundcloud.com/tracks/159723640/attachments", + "policy": "ALLOW" + } + ], + "total_results": 375750, + "next_href": "https://api.soundcloud.com/search?&q=test", + "tx_id": "" + } + """ + response = mock.Mock(text=json) + results = soundcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + { + "collection": [], + "total_results": 375750, + "next_href": "https://api.soundcloud.com/search?&q=test", + "tx_id": "" + } + """ + response = mock.Mock(text=json) + results = soundcloud.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 00ac8ffdf..4ed1a9bba 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -15,4 +15,5 @@ from searx.tests.engines.test_kickass import * # noqa from searx.tests.engines.test_mixcloud import * # noqa from searx.tests.engines.test_searchcode_code import * # noqa from searx.tests.engines.test_searchcode_doc import * # noqa +from searx.tests.engines.test_soundcloud import * # noqa from searx.tests.engines.test_youtube import * # noqa -- cgit v1.2.3 From d20ddf9da147647710127385a3ee95ff273d4fea Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sat, 31 Jan 2015 17:29:22 +0100 Subject: Stackoverflow's unit test --- searx/tests/engines/test_stackoverflow.py | 106 ++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 107 insertions(+) create mode 100644 searx/tests/engines/test_stackoverflow.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_stackoverflow.py b/searx/tests/engines/test_stackoverflow.py new file mode 100644 index 000000000..e69bafb4c --- /dev/null +++ b/searx/tests/engines/test_stackoverflow.py @@ -0,0 +1,106 @@ +from collections import defaultdict +import mock +from searx.engines import stackoverflow +from searx.testing import SearxTestCase + + +class TestStackoverflowEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = stackoverflow.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('stackoverflow.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, stackoverflow.response, None) + self.assertRaises(AttributeError, stackoverflow.response, []) + self.assertRaises(AttributeError, stackoverflow.response, '') + self.assertRaises(AttributeError, stackoverflow.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(stackoverflow.response(response), []) + + html = """ +
    +
    +
    +
    +
    +
    + 2583 +
    votes
    +
    +
    +
    +
    +
    + +
    + This is the content +
    +
    +
    +
    + answered nov 23 '09 by + hallski +
    +
    +
    + """ + response = mock.Mock(text=html) + results = stackoverflow.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'], 'http://stackoverflow.com/questions/this.is.the.url') + self.assertEqual(results[0]['content'], 'This is the content') + + html = """ +
    +
    +
    +
    +
    + 2583 +
    votes
    +
    +
    +
    +
    +
    + +
    + This is the content +
    +
    +
    +
    + answered nov 23 '09 by + hallski +
    +
    + """ + response = mock.Mock(text=html) + results = stackoverflow.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 4ed1a9bba..31ad9cd4e 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -16,4 +16,5 @@ from searx.tests.engines.test_mixcloud import * # noqa from searx.tests.engines.test_searchcode_code import * # noqa from searx.tests.engines.test_searchcode_doc import * # noqa from searx.tests.engines.test_soundcloud import * # noqa +from searx.tests.engines.test_stackoverflow import * # noqa from searx.tests.engines.test_youtube import * # noqa -- cgit v1.2.3 From 04fa31b7f4d45182fa4ced6d6e23fd9ec4960d2e Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sat, 31 Jan 2015 19:49:54 +0100 Subject: Vimeo's unit test --- searx/tests/engines/test_vimeo.py | 84 +++++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 85 insertions(+) create mode 100644 searx/tests/engines/test_vimeo.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_vimeo.py b/searx/tests/engines/test_vimeo.py new file mode 100644 index 000000000..24b3ad897 --- /dev/null +++ b/searx/tests/engines/test_vimeo.py @@ -0,0 +1,84 @@ +from collections import defaultdict +import mock +from searx.engines import vimeo +from searx.testing import SearxTestCase + + +class TestVimeoEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 0 + params = vimeo.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('vimeo.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, vimeo.response, None) + self.assertRaises(AttributeError, vimeo.response, []) + self.assertRaises(AttributeError, vimeo.response, '') + self.assertRaises(AttributeError, vimeo.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(vimeo.response(response), []) + + html = """ + + """ + response = mock.Mock(text=html) + 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'], 'http://vimeo.com/videoid') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['thumbnail'], 'http://image.url.webp') + self.assertIn('/videoid', results[0]['embedded']) + + html = """ +
      +
    1. + + +
      +

      + This is the title +

      +

      + +

      +
      +
      +
    2. +
    + """ + response = mock.Mock(text=html) + results = vimeo.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 31ad9cd4e..27acc067a 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -17,4 +17,5 @@ from searx.tests.engines.test_searchcode_code import * # noqa from searx.tests.engines.test_searchcode_doc import * # noqa from searx.tests.engines.test_soundcloud import * # noqa from searx.tests.engines.test_stackoverflow import * # noqa +from searx.tests.engines.test_vimeo import * # noqa from searx.tests.engines.test_youtube import * # noqa -- cgit v1.2.3 From 8cf2ee57216b4dffc419e1762ff1fe4dfd30e227 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sun, 1 Feb 2015 13:43:10 +0100 Subject: 500px unit test --- searx/tests/engines/test_www500px.py | 83 ++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 84 insertions(+) create mode 100644 searx/tests/engines/test_www500px.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_www500px.py b/searx/tests/engines/test_www500px.py new file mode 100644 index 000000000..8df15b945 --- /dev/null +++ b/searx/tests/engines/test_www500px.py @@ -0,0 +1,83 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import www500px +from searx.testing import SearxTestCase + + +class TestWww500pxImagesEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = www500px.request(query, dicto) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('500px.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, www500px.response, None) + self.assertRaises(AttributeError, www500px.response, []) + self.assertRaises(AttributeError, www500px.response, '') + self.assertRaises(AttributeError, www500px.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(www500px.response(response), []) + + html = """ + + """ + response = mock.Mock(text=html) + 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 = """ + + + + + """ + response = mock.Mock(text=html) + results = www500px.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 27acc067a..94f479dae 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -18,4 +18,5 @@ from searx.tests.engines.test_searchcode_doc import * # noqa from searx.tests.engines.test_soundcloud import * # noqa from searx.tests.engines.test_stackoverflow import * # noqa from searx.tests.engines.test_vimeo import * # noqa +from searx.tests.engines.test_www500px import * # noqa from searx.tests.engines.test_youtube import * # noqa -- cgit v1.2.3 From c6535dd65ebf110d00d633db1170f35cf60b8df0 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sun, 1 Feb 2015 14:31:04 +0100 Subject: Flickr Noapi unit test --- searx/tests/engines/test_flickr_noapi.py | 442 +++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 443 insertions(+) create mode 100644 searx/tests/engines/test_flickr_noapi.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_flickr_noapi.py b/searx/tests/engines/test_flickr_noapi.py new file mode 100644 index 000000000..a1de3a5e4 --- /dev/null +++ b/searx/tests/engines/test_flickr_noapi.py @@ -0,0 +1,442 @@ +from collections import defaultdict +import mock +from searx.engines import flickr_noapi +from searx.testing import SearxTestCase + + +class TestFlickrNoapiEngine(SearxTestCase): + + def test_build_flickr_url(self): + url = flickr_noapi.build_flickr_url("uid", "pid") + self.assertIn("uid", url) + self.assertIn("pid", url) + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + params = flickr_noapi.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('flickr.com', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, flickr_noapi.response, None) + self.assertRaises(AttributeError, flickr_noapi.response, []) + self.assertRaises(AttributeError, flickr_noapi.response, '') + self.assertRaises(AttributeError, flickr_noapi.response, '[]') + + response = mock.Mock(text='"search-photos-models","photos":{},"totalItems":') + self.assertEqual(flickr_noapi.response(response), []) + + response = mock.Mock(text='search-photos-models","photos":{"data": []},"totalItems":') + self.assertEqual(flickr_noapi.response(response), []) + + json = """ + "search-photos-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-models", + "title": "This is the title", + "sizes": { + "c": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_c.jpg", + "width": 541, + "height": 800, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_c.jpg", + "key": "c" + }, + "h": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_761d32237a_h.jpg", + "width": 1081, + "height": 1600, + "url": "//c4.staticflickr.com/8/7246/14001294434_761d32237a_h.jpg", + "key": "h" + }, + "k": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_f145a2c11a_k.jpg", + "width": 1383, + "height": 2048, + "url": "//c4.staticflickr.com/8/7246/14001294434_f145a2c11a_k.jpg", + "key": "k" + }, + "l": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_b.jpg", + "width": 692, + "height": 1024, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_b.jpg", + "key": "l" + }, + "m": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777.jpg", + "width": 338, + "height": 500, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777.jpg", + "key": "m" + }, + "n": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_n.jpg", + "width": 216, + "height": 320, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_n.jpg", + "key": "n" + }, + "q": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_q.jpg", + "width": 150, + "height": 150, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_q.jpg", + "key": "q" + }, + "s": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_m.jpg", + "width": 162, + "height": 240, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_m.jpg", + "key": "s" + }, + "sq": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_s.jpg", + "width": 75, + "height": 75, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_s.jpg", + "key": "sq" + }, + "t": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_t.jpg", + "width": 68, + "height": 100, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_t.jpg", + "key": "t" + }, + "z": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_z.jpg", + "width": 433, + "height": 640, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg", + "key": "z" + } + }, + "canComment": false, + "rotation": 0, + "owner": { + "_flickrModelRegistry": "person-models", + "pathAlias": "klink692", + "username": "Owner", + "buddyicon": { + "retina": null, + "large": null, + "medium": null, + "small": null, + "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00" + }, + "isPro": true, + "id": "59729010@N00" + }, + "engagement": { + "_flickrModelRegistry": "photo-engagement-models", + "ownerNsid": "59729010@N00", + "faveCount": 21, + "commentCount": 14, + "viewCount": 10160, + "id": "14001294434" + }, + "description": "Description", + "isHD": false, + "secret": "410f653777", + "canAddMeta": false, + "license": 0, + "oWidth": 1803, + "oHeight": 2669, + "safetyLevel": 0, + "id": "14001294434" + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + json = json.replace('\r\n', '').replace('\n', '').replace('\r', '') + response = mock.Mock(text=json) + results = flickr_noapi.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://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('Description', results[0]['content']) + + json = """ + "search-photos-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-models", + "title": "This is the title", + "sizes": { + "z": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_z.jpg", + "width": 433, + "height": 640, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_z.jpg", + "key": "z" + } + }, + "canComment": false, + "rotation": 0, + "owner": { + "_flickrModelRegistry": "person-models", + "pathAlias": "klink692", + "username": "Owner", + "buddyicon": { + "retina": null, + "large": null, + "medium": null, + "small": null, + "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00" + }, + "isPro": true, + "id": "59729010@N00" + }, + "engagement": { + "_flickrModelRegistry": "photo-engagement-models", + "ownerNsid": "59729010@N00", + "faveCount": 21, + "commentCount": 14, + "viewCount": 10160, + "id": "14001294434" + }, + "description": "Description", + "isHD": false, + "secret": "410f653777", + "canAddMeta": false, + "license": 0, + "oWidth": 1803, + "oHeight": 2669, + "safetyLevel": 0, + "id": "14001294434" + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.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://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('Description', results[0]['content']) + + json = """ + "search-photos-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-models", + "title": "This is the title", + "sizes": { + "o": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg", + "width": 433, + "height": 640, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg", + "key": "o" + } + }, + "canComment": false, + "rotation": 0, + "owner": { + "_flickrModelRegistry": "person-models", + "pathAlias": "klink692", + "username": "Owner", + "buddyicon": { + "retina": null, + "large": null, + "medium": null, + "small": null, + "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00" + }, + "isPro": true, + "id": "59729010@N00" + }, + "engagement": { + "_flickrModelRegistry": "photo-engagement-models", + "ownerNsid": "59729010@N00", + "faveCount": 21, + "commentCount": 14, + "viewCount": 10160, + "id": "14001294434" + }, + "isHD": false, + "secret": "410f653777", + "canAddMeta": false, + "license": 0, + "oWidth": 1803, + "oHeight": 2669, + "safetyLevel": 0, + "id": "14001294434" + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.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://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']) + + json = """ + "search-photos-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-models", + "title": "This is the title", + "sizes": { + }, + "canComment": false, + "rotation": 0, + "owner": { + "_flickrModelRegistry": "person-models", + "pathAlias": "klink692", + "username": "Owner", + "buddyicon": { + "retina": null, + "large": null, + "medium": null, + "small": null, + "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00" + }, + "isPro": true, + "id": "59729010@N00" + }, + "engagement": { + "_flickrModelRegistry": "photo-engagement-models", + "ownerNsid": "59729010@N00", + "faveCount": 21, + "commentCount": 14, + "viewCount": 10160, + "id": "14001294434" + }, + "description": "Description", + "isHD": false, + "secret": "410f653777", + "canAddMeta": false, + "license": 0, + "oWidth": 1803, + "oHeight": 2669, + "safetyLevel": 0, + "id": "14001294434" + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + "search-photos-models","photos": + { + "_data": [null], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + "search-photos-models","photos": + { + "_data": [ + { + "_flickrModelRegistry": "photo-models", + "title": "This is the title", + "sizes": { + "o": { + "displayUrl": "//farm8.staticflickr.com/7246/14001294434_410f653777_o.jpg", + "width": 433, + "height": 640, + "url": "//c4.staticflickr.com/8/7246/14001294434_410f653777_o.jpg", + "key": "o" + } + }, + "canComment": false, + "rotation": 0, + "owner": { + "_flickrModelRegistry": "person-models", + "pathAlias": "klink692", + "username": "Owner", + "buddyicon": { + "retina": null, + "large": null, + "medium": null, + "small": null, + "default": "//c1.staticflickr.com/9/8108/buddyicons/59729010@N00.jpg?1361642376#59729010@N00" + }, + "isPro": true + }, + "engagement": { + "_flickrModelRegistry": "photo-engagement-models", + "ownerNsid": "59729010@N00", + "faveCount": 21, + "commentCount": 14, + "viewCount": 10160, + "id": "14001294434" + }, + "description": "Description", + "isHD": false, + "secret": "410f653777", + "canAddMeta": false, + "license": 0, + "oWidth": 1803, + "oHeight": 2669, + "safetyLevel": 0, + "id": "14001294434" + } + ], + "fetchedStart": true, + "fetchedEnd": false, + "totalItems": "4386039" + },"totalItems": + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) + + json = """ + {"toto":[ + {"id":200,"name":"Artist Name", + "link":"http:\/\/www.flickr.com\/artist\/1217","type":"artist"} + ]} + """ + response = mock.Mock(text=json) + results = flickr_noapi.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 94f479dae..ed5ee42d8 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -8,6 +8,7 @@ from searx.tests.engines.test_deviantart import * # noqa from searx.tests.engines.test_digg import * # noqa from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_flickr import * # noqa +from searx.tests.engines.test_flickr_noapi import * # noqa from searx.tests.engines.test_github import * # noqa from searx.tests.engines.test_google_images import * # noqa from searx.tests.engines.test_google_news import * # noqa -- cgit v1.2.3 From 5a16077455ef9e821a2b5f5f7e975be8a37ce83d Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sun, 1 Feb 2015 15:23:26 +0100 Subject: PirateBay unit test + reactivation in Settings --- searx/tests/engines/test_piratebay.py | 137 ++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 138 insertions(+) create mode 100644 searx/tests/engines/test_piratebay.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_piratebay.py b/searx/tests/engines/test_piratebay.py new file mode 100644 index 000000000..7207c408a --- /dev/null +++ b/searx/tests/engines/test_piratebay.py @@ -0,0 +1,137 @@ +# -*- coding: utf-8 -*- +from collections import defaultdict +import mock +from searx.engines import piratebay +from searx.testing import SearxTestCase + + +class TestPiratebayEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + dicto = defaultdict(dict) + dicto['pageno'] = 1 + dicto['category'] = 'Toto' + params = piratebay.request(query, dicto) + self.assertIn('url', params) + self.assertIn(query, params['url']) + self.assertIn('piratebay.cr', params['url']) + self.assertIn('0', params['url']) + + dicto['category'] = 'music' + params = piratebay.request(query, dicto) + self.assertIn('100', params['url']) + + def test_response(self): + self.assertRaises(AttributeError, piratebay.response, None) + self.assertRaises(AttributeError, piratebay.response, []) + self.assertRaises(AttributeError, piratebay.response, '') + self.assertRaises(AttributeError, piratebay.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(piratebay.response(response), []) + + html = """ + + + + + + + + + +
    +
    + Anime
    + (Anime) +
    +
    + + + Magnet link + + + Download + + + VIP + + + + This is the content and should be OK + + 13334
    + """ + response = mock.Mock(text=html) + results = piratebay.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://thepiratebay.cr/this.is.the.link') + self.assertEqual(results[0]['content'], 'This is the content and should be OK') + self.assertEqual(results[0]['seed'], 13) + self.assertEqual(results[0]['leech'], 334) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK') + self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent') + + html = """ + + + + + + + + + +
    +
    + Anime
    + (Anime) +
    +
    + + + Magnet link + + + Download + + + VIP + + + + This is the content and should be OK + + sd
    + """ + response = mock.Mock(text=html) + results = piratebay.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://thepiratebay.cr/this.is.the.link') + self.assertEqual(results[0]['content'], 'This is the content and should be OK') + self.assertEqual(results[0]['seed'], 0) + self.assertEqual(results[0]['leech'], 0) + self.assertEqual(results[0]['magnetlink'], 'magnet:?xt=urn:btih:MAGNETLINK') + self.assertEqual(results[0]['torrentfile'], 'http://torcache.net/torrent/TORRENTFILE.torrent') + + html = """ + +
    + """ + response = mock.Mock(text=html) + results = piratebay.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 0) diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index ed5ee42d8..e66f7db28 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -14,6 +14,7 @@ from searx.tests.engines.test_google_images import * # noqa from searx.tests.engines.test_google_news import * # noqa from searx.tests.engines.test_kickass import * # noqa from searx.tests.engines.test_mixcloud import * # noqa +from searx.tests.engines.test_piratebay import * # noqa from searx.tests.engines.test_searchcode_code import * # noqa from searx.tests.engines.test_searchcode_doc import * # noqa from searx.tests.engines.test_soundcloud import * # noqa -- cgit v1.2.3