From a605d0ae698e8a5555935780d83df50b06727f24 Mon Sep 17 00:00:00 2001 From: Thomas Pointhuber Date: Sun, 1 Feb 2015 13:52:43 +0100 Subject: [enh] add test for 1x.com --- searx/tests/engines/test_www1x.py | 57 +++++++++++++++++++++++++++++++++++++++ searx/tests/test_engines.py | 1 + 2 files changed, 58 insertions(+) create mode 100644 searx/tests/engines/test_www1x.py (limited to 'searx/tests') diff --git a/searx/tests/engines/test_www1x.py b/searx/tests/engines/test_www1x.py new file mode 100644 index 000000000..ab4f282c1 --- /dev/null +++ b/searx/tests/engines/test_www1x.py @@ -0,0 +1,57 @@ +from collections import defaultdict +import mock +from searx.engines import www1x +from searx.testing import SearxTestCase + + +class TestWww1xEngine(SearxTestCase): + + def test_request(self): + query = 'test_query' + params = www1x.request(query, defaultdict(dict)) + self.assertTrue('url' in params) + self.assertTrue(query in params['url']) + self.assertTrue('1x.com' in params['url']) + + def test_response(self): + self.assertRaises(AttributeError, www1x.response, None) + self.assertRaises(AttributeError, www1x.response, []) + self.assertRaises(AttributeError, www1x.response, '') + self.assertRaises(AttributeError, www1x.response, '[]') + + response = mock.Mock(text='') + self.assertEqual(www1x.response(response), []) + html = """ + + + + + + + ] + > + + +
Photos
+
+ + + + + + +
+ + + ]]>
+ """ + response = mock.Mock(text=html) + results = www1x.response(response) + self.assertEqual(type(results), list) + self.assertEqual(len(results), 1) + self.assertEqual(results[0]['url'], 'http://1x.com/photo/123456') + self.assertEqual(results[0]['thumbnail_src'], 'http://1x.com/images/user/testimage-123456.jpg') + self.assertEqual(results[0]['content'], '') + self.assertEqual(results[0]['template'], 'images.html') diff --git a/searx/tests/test_engines.py b/searx/tests/test_engines.py index 1ffdbe529..cfd7fa26a 100644 --- a/searx/tests/test_engines.py +++ b/searx/tests/test_engines.py @@ -1,2 +1,3 @@ from searx.tests.engines.test_dummy import * # noqa from searx.tests.engines.test_github import * # noqa +from searx.tests.engines.test_www1x import * # noqa -- cgit v1.2.3