# -*- coding: utf-8 -*- from collections import defaultdict import mock from searx.engines import wolframalpha_noapi from searx.testing import SearxTestCase class TestWolframAlphaNoAPIEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 1 params = wolframalpha_noapi.request(query, dicto) self.assertIn('url', params) self.assertIn(query, params['url']) self.assertIn('wolframalpha.com', params['url']) def test_response(self): self.assertRaises(AttributeError, wolframalpha_noapi.response, None) self.assertRaises(AttributeError, wolframalpha_noapi.response, []) self.assertRaises(AttributeError, wolframalpha_noapi.response, '') self.assertRaises(AttributeError, wolframalpha_noapi.response, '[]') # response = mock.Mock(text='') # self.assertEqual(wolframalpha_noapi.response(response), []) html = """ sqrt(-1) - Wolfram|Alpha """ response = mock.Mock(text=html) results = wolframalpha_noapi.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 2) self.assertIn("i", results[0]['answer']) self.assertIn("sqrt(-1) - Wolfram|Alpha", results[1]['title']) self.assertIn("http://www.wolframalpha.com/input/?i=+sqrt%28-1%29", results[1]['url']) html = """ integral 1/x - Wolfram|Alpha """ response = mock.Mock(text=html) results = wolframalpha_noapi.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 2) self.assertIn("log(x)+c", results[0]['answer']) self.assertIn("integral 1/x - Wolfram|Alpha", results[1]['title']) self.assertIn("http://www.wolframalpha.com/input/?i=+integral+1%2Fx", results[1]['url'])