-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathtest_domain.py
More file actions
76 lines (66 loc) · 2.12 KB
/
test_domain.py
File metadata and controls
76 lines (66 loc) · 2.12 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from __future__ import annotations
import datetime
from datetime import timezone
import pytest
from hcloud.actions import (
Action,
ActionException,
ActionFailedException,
ActionTimeoutException,
)
@pytest.mark.parametrize(
"value",
[
(Action(id=1),),
],
)
def test_eq(value):
assert value == value
class TestAction:
def test_started_finished_is_datetime(self):
action = Action(
id=1, started="2016-01-30T23:50+00:00", finished="2016-03-30T23:50+00:00"
)
assert action.started == datetime.datetime(
2016, 1, 30, 23, 50, tzinfo=timezone.utc
)
assert action.finished == datetime.datetime(
2016, 3, 30, 23, 50, tzinfo=timezone.utc
)
def test_action_exceptions():
with pytest.raises(
ActionException,
match=r"The pending action failed: Server does not exist anymore",
):
raise ActionFailedException(
action=Action(
**{
"id": 1084730887,
"command": "change_server_type",
"status": "error",
"progress": 100,
"resources": [{"id": 34574042, "type": "server"}],
"error": {
"code": "server_does_not_exist_anymore",
"message": "Server does not exist anymore",
},
"started": "2023-07-06T14:52:42+00:00",
"finished": "2023-07-06T14:53:08+00:00",
}
)
)
with pytest.raises(ActionException, match=r"The pending action timed out"):
raise ActionTimeoutException(
action=Action(
**{
"id": 1084659545,
"command": "create_server",
"status": "running",
"progress": 50,
"started": "2023-07-06T13:58:38+00:00",
"finished": None,
"resources": [{"id": 34572291, "type": "server"}],
"error": None,
}
)
)