77import pytest
88from dateutil .parser import isoparse
99
10+ from hcloud import Client
1011from hcloud .storage_box_types import (
1112 BoundStorageBoxType ,
1213 StorageBoxTypesClient ,
@@ -23,24 +24,30 @@ def assert_bound_model(
2324 assert o .name == "bx11"
2425
2526
27+ @pytest .fixture (name = "request_mock" )
28+ def request_mock_fixture ():
29+ return mock .MagicMock ()
30+
31+
2632@pytest .fixture (name = "client" )
27- def client_fixture () -> StorageBoxTypesClient :
28- return StorageBoxTypesClient (client = mock .MagicMock ())
33+ def client_fixture (request_mock ) -> StorageBoxTypesClient :
34+ client = Client ("" )
35+ client ._request_hetzner = request_mock
36+ return StorageBoxTypesClient (client = client )
2937
3038
3139class TestClient :
3240 def test_get_by_id (
3341 self ,
42+ request_mock : mock .MagicMock ,
3443 client : StorageBoxTypesClient ,
3544 storage_box_type1 ,
3645 ):
37- client ._client ._request_hetzner .return_value = {
38- "storage_box_type" : storage_box_type1
39- }
46+ request_mock .return_value = {"storage_box_type" : storage_box_type1 }
4047
4148 result = client .get_by_id (42 )
4249
43- client . _client . _request_hetzner .assert_called_with (
50+ request_mock .assert_called_with (
4451 method = "GET" ,
4552 url = "/storage_box_types/42" ,
4653 )
@@ -73,18 +80,19 @@ def test_get_by_id(
7380 )
7481 def test_get_list (
7582 self ,
83+ request_mock : mock .MagicMock ,
7684 client : StorageBoxTypesClient ,
7785 storage_box_type1 ,
7886 storage_box_type2 ,
7987 params ,
8088 ):
81- client . _client . _request_hetzner .return_value = {
89+ request_mock .return_value = {
8290 "storage_box_types" : [storage_box_type1 , storage_box_type2 ]
8391 }
8492
8593 result = client .get_list (** params )
8694
87- client . _client . _request_hetzner .assert_called_with (
95+ request_mock .assert_called_with (
8896 url = "/storage_box_types" ,
8997 method = "GET" ,
9098 params = params ,
@@ -113,18 +121,19 @@ def test_get_list(
113121 )
114122 def test_get_all (
115123 self ,
124+ request_mock : mock .MagicMock ,
116125 client : StorageBoxTypesClient ,
117126 storage_box_type1 ,
118127 storage_box_type2 ,
119128 params ,
120129 ):
121- client . _client . _request_hetzner .return_value = {
130+ request_mock .return_value = {
122131 "storage_box_types" : [storage_box_type1 , storage_box_type2 ]
123132 }
124133
125134 result = client .get_all (** params )
126135
127- client . _client . _request_hetzner .assert_called_with (
136+ request_mock .assert_called_with (
128137 url = "/storage_box_types" ,
129138 method = "GET" ,
130139 params = {** params , "page" : 1 , "per_page" : 50 },
@@ -145,18 +154,17 @@ def test_get_all(
145154
146155 def test_get_by_name (
147156 self ,
157+ request_mock : mock .MagicMock ,
148158 client : StorageBoxTypesClient ,
149159 storage_box_type1 ,
150160 ):
151- client ._client ._request_hetzner .return_value = {
152- "storage_box_types" : [storage_box_type1 ]
153- }
161+ request_mock .return_value = {"storage_box_types" : [storage_box_type1 ]}
154162
155163 result = client .get_by_name ("bx11" )
156164
157165 params = {"name" : "bx11" }
158166
159- client . _client . _request_hetzner .assert_called_with (
167+ request_mock .assert_called_with (
160168 method = "GET" ,
161169 url = "/storage_box_types" ,
162170 params = params ,
0 commit comments