test_exceptions.py 2.0 KB

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