SearXNG is a free internet metasearch engine which aggregates results from various search services and databases. Users are neither tracked nor profiled.
Python bingbravedegoogleduckduckgogooglemetasearchprivacypythonqwantsearchsearch-enginesearxsearxngstartpageyahoo
Flickr's test unit
Cqoicebordel8f040e30adbb
diff --git a/searx/tests/engines/test_flickr.py b/searx/tests/engines/test_flickr.pynew file mode 100644index 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.pyindex 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 * # noqafrom searx.tests.engines.test_deezer import * # noqafrom searx.tests.engines.test_dummy import * # noqa+from searx.tests.engines.test_flickr import * # noqafrom searx.tests.engines.test_github import * # noqafrom searx.tests.engines.test_mixcloud import * # noqa