Debian Codegraph @

tests/test_callback.py

raw symbols SCIP
1 import pytest
2
3 import consul
4 from consul.base import Response
5 from consul.callback import CB
6 from consul.exceptions import ACLDisabled, ACLPermissionDenied, BadRequest, ClientError, NotFound
7
8
9 class TestCB:
10 # pylint: disable=protected-access
11 def test_status_200_passes(self) -> None:
12 response = consul.base.Response(200, None, None)
13 CB._status(response)
14
15 @pytest.mark.parametrize(
16 ("response", "expected_exception"),
17 [
18 (Response(400, None, None), BadRequest),
19 (Response(401, None, None), ACLDisabled),
20 (Response(403, None, None), ACLPermissionDenied),
21 ],
22 )
23 def test_status_4xx_raises_error(self, response, expected_exception) -> None:
24 with pytest.raises(expected_exception):
25 CB._status(response)
26
27 def test_status_404_allow_404(self) -> None:
28 response = Response(404, None, None)
29 CB._status(response, allow_404=True)
30
31 def test_status_404_dont_allow_404(self) -> None:
32 response = Response(404, None, None)
33 with pytest.raises(NotFound):
34 CB._status(response, allow_404=False)
35
36 def test_status_405_raises_generic_ClientError(self) -> None:
37 response = Response(405, None, None)
38 with pytest.raises(ClientError):
39 CB._status(response)
40
41 @pytest.mark.parametrize(
42 "response",
43 [
44 Response(500, None, None),
45 Response(599, None, None),
46 ],
47 )
48 def test_status_5xx_raises_error(self, response) -> None:
49 with pytest.raises(consul.base.ConsulException):
50 CB._status(response)