# -*- coding: utf-8 -*- from lxml.html import fromstring from collections import defaultdict import mock from searx.engines import wikidata from searx.testing import SearxTestCase class TestWikidataEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['language'] = 'all' params = wikidata.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('wikidata.org', params['url']) self.assertIn('en', params['url']) dicto['language'] = 'es_ES' params = wikidata.request(query, dicto) self.assertIn(query, params['url']) self.assertIn('es', params['url']) # successful cases are not tested here to avoid sending additional requests def test_response(self): self.assertRaises(AttributeError, wikidata.response, None) self.assertRaises(AttributeError, wikidata.response, []) self.assertRaises(AttributeError, wikidata.response, '') self.assertRaises(AttributeError, wikidata.response, '[]') response = mock.Mock(text='', search_params={"language": "all"}) self.assertEqual(wikidata.response(response), []) def test_getDetail(self): response = {} results = wikidata.getDetail(response, "Q123", "en", "en-US") self.assertEqual(results, []) title_html = '