# -*- coding: utf-8 -*- from lxml.html import fromstring from lxml import etree 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']) dicto['language'] = 'es_ES' params = wikidata.request(query, dicto) self.assertIn(query, 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, '[]') wikidata.supported_languages = ['en', 'es'] wikidata.language_aliases = {} response = mock.Mock(content=''.encode("utf-8"), search_params={"language": "en"}) self.assertEqual(wikidata.response(response), []) def test_getDetail(self): response = {} results = wikidata.getDetail(response, "Q123", "en", "en-US", etree.HTMLParser()) self.assertEqual(results, []) title_html = '