11import datetime
22from datetime import timezone
33
4- from hcloud .actions .domain import Action
4+ import pytest
5+
6+ from hcloud .actions .domain import (
7+ Action ,
8+ ActionException ,
9+ ActionFailedException ,
10+ ActionTimeoutException ,
11+ )
512
613
714class TestAction :
@@ -15,3 +22,43 @@ def test_started_finished_is_datetime(self):
1522 assert action .finished == datetime .datetime (
1623 2016 , 3 , 30 , 23 , 50 , tzinfo = timezone .utc
1724 )
25+
26+
27+ def test_action_exceptions ():
28+ with pytest .raises (
29+ ActionException ,
30+ match = r"The pending action failed: Server does not exist anymore" ,
31+ ):
32+ raise ActionFailedException (
33+ action = Action (
34+ ** {
35+ "id" : 1084730887 ,
36+ "command" : "change_server_type" ,
37+ "status" : "error" ,
38+ "progress" : 100 ,
39+ "resources" : [{"id" : 34574042 , "type" : "server" }],
40+ "error" : {
41+ "code" : "server_does_not_exist_anymore" ,
42+ "message" : "Server does not exist anymore" ,
43+ },
44+ "started" : "2023-07-06T14:52:42+00:00" ,
45+ "finished" : "2023-07-06T14:53:08+00:00" ,
46+ }
47+ )
48+ )
49+
50+ with pytest .raises (ActionException , match = r"The pending action timed out" ):
51+ raise ActionTimeoutException (
52+ action = Action (
53+ ** {
54+ "id" : 1084659545 ,
55+ "command" : "create_server" ,
56+ "status" : "running" ,
57+ "progress" : 50 ,
58+ "started" : "2023-07-06T13:58:38+00:00" ,
59+ "finished" : None ,
60+ "resources" : [{"id" : 34572291 , "type" : "server" }],
61+ "error" : None ,
62+ }
63+ )
64+ )
0 commit comments