From 0f52cc75424b4b376b7b950801c9a91d4e24e282 Mon Sep 17 00:00:00 2001 From: Cqoicebordel Date: Sun, 25 Jan 2015 22:12:34 +0100 Subject: [PATCH] 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 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