test_exceptions.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # pylint: disable=missing-module-docstring
  3. from parameterized import parameterized
  4. from tests import SearxTestCase
  5. import searx.exceptions
  6. from searx import get_setting
  7. class TestExceptions(SearxTestCase): # pylint: disable=missing-class-docstring
  8. @parameterized.expand(
  9. [
  10. searx.exceptions.SearxEngineAccessDeniedException,
  11. searx.exceptions.SearxEngineCaptchaException,
  12. searx.exceptions.SearxEngineTooManyRequestsException,
  13. ]
  14. )
  15. def test_default_suspend_time(self, exception):
  16. with self.assertRaises(exception) as e:
  17. raise exception()
  18. self.assertEqual(
  19. e.exception.suspended_time,
  20. get_setting(exception.SUSPEND_TIME_SETTING),
  21. )
  22. @parameterized.expand(
  23. [
  24. searx.exceptions.SearxEngineAccessDeniedException,
  25. searx.exceptions.SearxEngineCaptchaException,
  26. searx.exceptions.SearxEngineTooManyRequestsException,
  27. ]
  28. )
  29. def test_custom_suspend_time(self, exception):
  30. with self.assertRaises(exception) as e:
  31. raise exception(suspended_time=1337)
  32. self.assertEqual(e.exception.suspended_time, 1337)