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')