test_exceptions.py 1.9 KB

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