summaryrefslogtreecommitdiff
path: root/tests/unit/test_exceptions.py
blob: fb2834058a6a12f902476c68f809d958a3faa207 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# 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)