Skip to content

Commit 4567874

Browse files
committed
test: missing bound action tests
1 parent 8b97f0e commit 4567874

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

tests/unit/actions/test_client.py

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import pytest
66

7+
from hcloud import Client
78
from hcloud.actions import (
89
Action,
910
ActionFailedException,
@@ -16,41 +17,52 @@
1617

1718
class TestBoundAction:
1819
@pytest.fixture()
19-
def bound_running_action(self, mocked_requests):
20-
action_client = ActionsClient(client=mocked_requests)
20+
def bound_running_action(self, client: Client):
2121
# Speed up tests that run `wait_until_finished`
22-
action_client._client._poll_interval_func = lambda _: 0.0
23-
action_client._client._poll_max_retries = 3
22+
client._poll_interval_func = lambda _: 0.0
23+
client._poll_max_retries = 3
2424

2525
return BoundAction(
26-
client=action_client,
26+
client=client.actions,
2727
data=dict(id=14, status=Action.STATUS_RUNNING),
2828
)
2929

3030
def test_wait_until_finished(
31-
self, bound_running_action, mocked_requests, running_action, successfully_action
31+
self,
32+
request_mock: mock.MagicMock,
33+
bound_running_action,
34+
running_action,
35+
successfully_action,
3236
):
33-
mocked_requests.request.side_effect = [running_action, successfully_action]
37+
request_mock.side_effect = [running_action, successfully_action]
3438
bound_running_action.wait_until_finished()
35-
mocked_requests.request.assert_called_with(url="/actions/2", method="GET")
39+
request_mock.assert_called_with(url="/actions/2", method="GET")
3640

3741
assert bound_running_action.status == "success"
38-
assert mocked_requests.request.call_count == 2
42+
assert request_mock.call_count == 2
3943

4044
def test_wait_until_finished_with_error(
41-
self, bound_running_action, mocked_requests, running_action, failed_action
45+
self,
46+
request_mock: mock.MagicMock,
47+
bound_running_action,
48+
running_action,
49+
failed_action,
4250
):
43-
mocked_requests.request.side_effect = [running_action, failed_action]
51+
request_mock.side_effect = [running_action, failed_action]
4452
with pytest.raises(ActionFailedException) as exception_info:
4553
bound_running_action.wait_until_finished()
4654

4755
assert bound_running_action.status == "error"
4856
assert exception_info.value.action.id == 2
4957

5058
def test_wait_until_finished_max_retries(
51-
self, bound_running_action, mocked_requests, running_action, successfully_action
59+
self,
60+
request_mock: mock.MagicMock,
61+
bound_running_action,
62+
running_action,
63+
successfully_action,
5264
):
53-
mocked_requests.request.side_effect = [
65+
request_mock.side_effect = [
5466
running_action,
5567
running_action,
5668
successfully_action,
@@ -60,7 +72,7 @@ def test_wait_until_finished_max_retries(
6072

6173
assert bound_running_action.status == "running"
6274
assert exception_info.value.action.id == 2
63-
assert mocked_requests.request.call_count == 1
75+
assert request_mock.call_count == 1
6476

6577

6678
class TestResourceActionsClient:

0 commit comments

Comments
 (0)