from collections import defaultdict import mock from searx.engines import subtitleseeker from searx.testing import SearxTestCase class TestSubtitleseekerEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 dicto['language'] = 'fr-FR' params = subtitleseeker.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) self.assertTrue('subtitleseeker.com' in params['url']) def test_response(self): dicto = defaultdict(dict) dicto['language'] = 'fr-FR' response = mock.Mock(search_params=dicto) self.assertRaises(AttributeError, subtitleseeker.response, None) self.assertRaises(AttributeError, subtitleseeker.response, []) self.assertRaises(AttributeError, subtitleseeker.response, '') self.assertRaises(AttributeError, subtitleseeker.response, '[]') response = mock.Mock(text='', search_params=dicto) self.assertEqual(subtitleseeker.response(response), []) html = """
""" response = mock.Mock(text=html, search_params=dicto) results = subtitleseeker.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'This is the Title') self.assertEqual(results[0]['url'], 'http://this.is.the.url/French/') self.assertIn('1998', results[0]['content']) self.assertIn('1039 Subs', results[0]['content']) self.assertIn('Alternative Title', results[0]['content']) dicto['language'] = 'pt-BR' results = subtitleseeker.response(response) self.assertEqual(results[0]['url'], 'http://this.is.the.url/Brazilian/') html = """ """ dicto['language'] = 'all' response = mock.Mock(text=html, search_params=dicto) results = subtitleseeker.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'This is the Title') self.assertEqual(results[0]['url'], 'http://this.is.the.url/') self.assertIn('1998', results[0]['content']) self.assertIn('1039 Subs', results[0]['content']) html = """ """ subtitleseeker.language = 'English' response = mock.Mock(text=html, search_params=dicto) results = subtitleseeker.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'This is the Title') self.assertEqual(results[0]['url'], 'http://this.is.the.url/English/') self.assertIn('1998', results[0]['content']) self.assertIn('1039 Subs', results[0]['content']) html = """