test_online.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # pylint: disable=missing-module-docstring
  3. from searx.search import SearchQuery, EngineRef
  4. from searx.search.processors import online
  5. from searx.engines import load_engines
  6. from searx import engines
  7. from tests import SearxTestCase
  8. TEST_ENGINE_NAME = 'dummy engine'
  9. TEST_ENGINE = {
  10. 'name': TEST_ENGINE_NAME,
  11. 'engine': 'dummy',
  12. 'categories': 'general',
  13. 'shortcut': 'du',
  14. 'timeout': 3.0,
  15. 'tokens': [],
  16. }
  17. class TestOnlineProcessor(SearxTestCase): # pylint: disable=missing-class-docstring
  18. def setUp(self):
  19. load_engines([TEST_ENGINE])
  20. def tearDown(self):
  21. load_engines([])
  22. def _get_params(self, online_processor, search_query, engine_category):
  23. params = online_processor.get_params(search_query, engine_category)
  24. self.assertIsNotNone(params)
  25. assert params is not None
  26. return params
  27. def test_get_params_default_params(self):
  28. engine = engines.engines[TEST_ENGINE_NAME]
  29. online_processor = online.OnlineProcessor(engine, TEST_ENGINE_NAME)
  30. search_query = SearchQuery('test', [EngineRef(TEST_ENGINE_NAME, 'general')], 'all', 0, 1, None, None, None)
  31. params = self._get_params(online_processor, search_query, 'general')
  32. self.assertIn('method', params)
  33. self.assertIn('headers', params)
  34. self.assertIn('data', params)
  35. self.assertIn('url', params)
  36. self.assertIn('cookies', params)
  37. self.assertIn('auth', params)
  38. def test_get_params_useragent(self):
  39. engine = engines.engines[TEST_ENGINE_NAME]
  40. online_processor = online.OnlineProcessor(engine, TEST_ENGINE_NAME)
  41. search_query = SearchQuery('test', [EngineRef(TEST_ENGINE_NAME, 'general')], 'all', 0, 1, None, None, None)
  42. params = self._get_params(online_processor, search_query, 'general')
  43. self.assertIn('User-Agent', params['headers'])