from collections import defaultdict import mock from searx.engines import bing from searx.testing import SearxTestCase class TestBingEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 0 dicto['language'] = 'fr_FR' params = bing.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) self.assertTrue('bing.com' in params['url']) self.assertTrue('SRCHHPGUSR' in params['cookies']) self.assertTrue('fr' in params['cookies']['SRCHHPGUSR']) dicto['language'] = 'all' params = bing.request(query, dicto) self.assertTrue('SRCHHPGUSR' in params['cookies']) self.assertTrue('en' in params['cookies']['SRCHHPGUSR']) def test_response(self): self.assertRaises(AttributeError, bing.response, None) self.assertRaises(AttributeError, bing.response, []) self.assertRaises(AttributeError, bing.response, '') self.assertRaises(AttributeError, bing.response, '[]') response = mock.Mock(text='') self.assertEqual(bing.response(response), []) response = mock.Mock(text='') self.assertEqual(bing.response(response), []) html = """
this.meta.com

This should be the content.

""" response = mock.Mock(text=html) results = bing.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'This should be the title') self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') self.assertEqual(results[0]['content'], 'This should be the content.') html = """
  • this.meta.com

    This should be the content.

  • """ response = mock.Mock(text=html) results = bing.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 1) self.assertEqual(results[0]['title'], 'This should be the title') self.assertEqual(results[0]['url'], 'http://this.should.be.the.link/') self.assertEqual(results[0]['content'], 'This should be the content.')