from collections import defaultdict import mock from searx.engines import stackoverflow from searx.testing import SearxTestCase class TestStackoverflowEngine(SearxTestCase): def test_request(self): query = 'test_query' dicto = defaultdict(dict) dicto['pageno'] = 0 params = stackoverflow.request(query, dicto) self.assertTrue('url' in params) self.assertTrue(query in params['url']) self.assertTrue('stackoverflow.com' in params['url']) def test_response(self): self.assertRaises(AttributeError, stackoverflow.response, None) self.assertRaises(AttributeError, stackoverflow.response, []) self.assertRaises(AttributeError, stackoverflow.response, '') self.assertRaises(AttributeError, stackoverflow.response, '[]') response = mock.Mock(text='') self.assertEqual(stackoverflow.response(response), []) html = """
2583
votes
This is the content
answered nov 23 '09 by hallski
""" response = mock.Mock(text=html) results = stackoverflow.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://stackoverflow.com/questions/this.is.the.url') self.assertEqual(results[0]['content'], 'This is the content') html = """
2583
votes
This is the content
answered nov 23 '09 by hallski
""" response = mock.Mock(text=html) results = stackoverflow.response(response) self.assertEqual(type(results), list) self.assertEqual(len(results), 0)