test_engines_init.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from searx.testing import SearxTestCase
  2. from searx import settings, engines
  3. class TestEnginesInit(SearxTestCase):
  4. @classmethod
  5. def tearDownClass(cls):
  6. settings['outgoing']['using_tor_proxy'] = False
  7. settings['outgoing']['extra_proxy_timeout'] = 0
  8. def test_initialize_engines_default(self):
  9. engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1'},
  10. {'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2'}]
  11. engines.load_engines(engine_list)
  12. self.assertEqual(len(engines.engines), 2)
  13. self.assertIn('engine1', engines.engines)
  14. self.assertIn('engine2', engines.engines)
  15. def test_initialize_engines_exclude_onions(self):
  16. settings['outgoing']['using_tor_proxy'] = False
  17. engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general'},
  18. {'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'}]
  19. engines.initialize_engines(engine_list)
  20. self.assertEqual(len(engines.engines), 1)
  21. self.assertIn('engine1', engines.engines)
  22. self.assertNotIn('onions', engines.categories)
  23. def test_initialize_engines_include_onions(self):
  24. settings['outgoing']['using_tor_proxy'] = True
  25. settings['outgoing']['extra_proxy_timeout'] = 100.0
  26. engine_list = [{'engine': 'dummy', 'name': 'engine1', 'shortcut': 'e1', 'categories': 'general',
  27. 'timeout': 20.0, 'onion_url': 'http://engine1.onion'},
  28. {'engine': 'dummy', 'name': 'engine2', 'shortcut': 'e2', 'categories': 'onions'}]
  29. engines.initialize_engines(engine_list)
  30. self.assertEqual(len(engines.engines), 2)
  31. self.assertIn('engine1', engines.engines)
  32. self.assertIn('engine2', engines.engines)
  33. self.assertIn('onions', engines.categories)
  34. self.assertIn('http://engine1.onion', engines.engines['engine1'].search_url)
  35. self.assertEqual(engines.engines['engine1'].timeout, 120.0)