-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathtest_exceptions.py
More file actions
62 lines (56 loc) · 1.57 KB
/
test_exceptions.py
File metadata and controls
62 lines (56 loc) · 1.57 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from __future__ import annotations
import pytest
from hcloud import (
APIException,
HCloudException,
)
from hcloud.actions import Action, ActionFailedException, ActionTimeoutException
running_action = Action(
id=12345,
command="action_command",
status=Action.STATUS_RUNNING,
)
failed_action = Action(
id=12345,
command="action_command",
status=Action.STATUS_ERROR,
error={"code": "action_failed", "message": "Action failed"},
)
@pytest.mark.parametrize(
("exception", "expected"),
[
(
# Should never be raised by itself
HCloudException(),
"",
),
(
# Should never be raised by itself
HCloudException("A test error"),
"A test error",
),
(
APIException(code="conflict", message="API error message", details=None),
"API error message (conflict)",
),
(
APIException(
code="conflict",
message="API error message",
details=None,
correlation_id="fddea8fabd02fb21",
),
"API error message (conflict, fddea8fabd02fb21)",
),
(
ActionFailedException(failed_action),
"The pending action failed: Action failed (action_failed, 12345)",
),
(
ActionTimeoutException(running_action),
"The pending action timed out (action_command, 12345)",
),
],
)
def test_exceptions(exception, expected):
assert str(exception) == expected