searxng/tests/unit/test_exceptions.py
Grant Lanham 44a06190bb [refactor] unit tests to utilize paramaterized and break down monolithic tests
- for tests which perform the same arrange/act/assert pattern but with different
  data, the data portion has been moved to the ``paramaterized.expand`` fields

- for monolithic tests which performed multiple arrange/act/asserts,
  they have been broken up into different unit tests.

- when possible, change generic assert statements to more concise
  asserts (i.e. ``assertIsNone``)

This work ultimately is focused on creating smaller and more concise tests.
While paramaterized may make adding new configurations for existing tests
easier, that is just a beneficial side effect.  The main benefit is that smaller
tests are easier to reason about, meaning they are easier to debug when they
start failing.  This improves the developer experience in debugging what went
wrong when refactoring the project.

Total number of tests went from 192 -> 259; or, broke apart larger tests into 69
more concise ones.
2024-10-03 13:20:32 +02:00

36 lines
1.2 KiB
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
# pylint: disable=missing-module-docstring
from parameterized import parameterized
from tests import SearxTestCase
import searx.exceptions
from searx import get_setting
class TestExceptions(SearxTestCase): # pylint: disable=missing-class-docstring
@parameterized.expand(
[
searx.exceptions.SearxEngineAccessDeniedException,
searx.exceptions.SearxEngineCaptchaException,
searx.exceptions.SearxEngineTooManyRequestsException,
]
)
def test_default_suspend_time(self, exception):
with self.assertRaises(exception) as e:
raise exception()
self.assertEqual(
e.exception.suspended_time,
get_setting(exception.SUSPEND_TIME_SETTING),
)
@parameterized.expand(
[
searx.exceptions.SearxEngineAccessDeniedException,
searx.exceptions.SearxEngineCaptchaException,
searx.exceptions.SearxEngineTooManyRequestsException,
]
)
def test_custom_suspend_time(self, exception):
with self.assertRaises(exception) as e:
raise exception(suspended_time=1337)
self.assertEqual(e.exception.suspended_time, 1337)