summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-27 23:20:57 +0100
committerCqoicebordel <Cqoicebordel@users.noreply.github.com>2015-01-27 23:20:57 +0100
commit92368a410749a4a057b476eb10c524f0fc133a0b (patch)
tree3f8424a52ab17c106299c83d6c917f7e3192d4d8
parent3282e62ff92f1c2158cb169d2a21a5988766450c (diff)
Dailymotion's unit test
-rw-r--r--searx/tests/engines/test_dailymotion.py74
-rw-r--r--searx/tests/test_engines.py1
2 files changed, 75 insertions, 0 deletions
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