from collections import defaultdict import mock from searx.engines import google_images from searx.testing import SearxTestCase class TestGoogleImagesEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['safesearch'] = 1 params = google_images.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('safe=active', params['url']) dicto['safesearch'] = 0 params = google_images.request(query, dicto) self.assertNotIn('safe', params['url']) def test_response(self): self.assertRaises(AttributeError, google_images.response, None) self.assertRaises(AttributeError, google_images.response, []) self.assertRaises(AttributeError, google_images.response, '') self.assertRaises(AttributeError, google_images.response, '[]') response = mock.Mock(text='
') self.assertEqual(google_images.response(response), []) html = """ """ # noqa response = mock.Mock(text=html) results = google_images.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], u'South Arrow Clip Art at Clker.com - vector clip art online ...') self.assertEqual(results[0]['url'], 'a') self.assertEqual(results[0]['thumbnail_src'], 'https://thumbnail.url/') self.assertEqual(results[0]['img_src'], 'b') self.assertEqual(results[0]['content'], 'Download this image as:')