from collections import defaultdict import mock from searx.engines import deviantart from searx.testing import SearxTestCase class TestDeviantartEngine(SearxTestCase): def test_request(self): dicto = defaultdict(dict) query = 'test_query' dicto['pageno'] = 0 dicto['time_range'] = '' params = deviantart.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) self.assertTrue('deviantart.com' in params['url']) def test_no_url_in_request_year_time_range(self): dicto = defaultdict(dict) query = 'test_query' dicto['time_range'] = 'year' params = deviantart.request(query, dicto) self.assertEqual({}, params['url']) def test_response(self): self.assertRaises(AttributeError, deviantart.response, None) self.assertRaises(AttributeError, deviantart.response, []) self.assertRaises(AttributeError, deviantart.response, '') self.assertRaises(AttributeError, deviantart.response, '[]') response = mock.Mock(text='') self.assertEqual(deviantart.response(response), []) response = mock.Mock(status_code=302) self.assertEqual(deviantart.response(response), []) html = """
Title of image
""" response = mock.Mock(text=html) results = deviantart.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'Title of image') self.assertEqual(results[0]['url'], 'https://url.of.image') self.assertNotIn('content', results[0]) self.assertEqual(results[0]['thumbnail_src'], 'https://url.of.thumbnail') html = """ Test Title of image 5 years ago in Animation More Like This """ response = mock.Mock(text=html) results = deviantart.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 0)