1- from unittest .mock import patch
1+ from unittest .mock import call , patch
22
33import pytest
44
@@ -19,21 +19,23 @@ def test_client_init(self):
1919 assert client .http_client .base_url == "https://example.com"
2020
2121 def test_client_get_pipeline_success (
22- self , get_pipeline_response , mock_success_response
22+ self , mock_success , get_pipeline_response , get_health_payload
2323 ):
2424 """Test successful pipeline retrieval by ID."""
2525 client = Client ()
2626 pipeline_id = "test-pipeline-id"
2727
28- mock_success_response .json .return_value = get_pipeline_response
29-
30- with patch (
31- "httpx.Client.request" , return_value = mock_success_response
28+ with mock_success (
29+ [
30+ get_pipeline_response ,
31+ get_health_payload (pipeline_id ),
32+ ]
3233 ) as mock_request :
3334 pipeline = client .get_pipeline (pipeline_id )
34- mock_request .assert_called_once_with (
35- "GET" , f"{ client .ENDPOINT } /{ pipeline_id } "
36- )
35+ assert mock_request .call_args_list == [
36+ call ("GET" , f"{ client .ENDPOINT } /{ pipeline_id } " ),
37+ call ("GET" , f"{ client .ENDPOINT } /{ pipeline_id } /health" ),
38+ ]
3739 assert isinstance (pipeline , Pipeline )
3840 assert pipeline .pipeline_id == pipeline_id
3941
@@ -126,13 +128,11 @@ def test_client_list_pipelines_empty(self):
126128 mock_request .assert_called_once_with ("GET" , client .ENDPOINT )
127129 assert pipelines == []
128130
129- def test_client_create_pipeline_success (self , valid_config , mock_success_response ):
131+ def test_client_create_pipeline_success (self , valid_config , mock_success ):
130132 """Test successful pipeline creation."""
131133 client = Client ()
132134
133- with patch (
134- "httpx.Client.request" , return_value = mock_success_response
135- ) as mock_request :
135+ with mock_success () as mock_request :
136136 pipeline = client .create_pipeline (valid_config )
137137 mock_request .assert_called_once_with (
138138 "POST" , client .ENDPOINT , json = mock_request .call_args [1 ]["json" ]
@@ -150,25 +150,21 @@ def test_client_create_pipeline_already_exists(
150150 with pytest .raises (errors .PipelineAlreadyExistsError ):
151151 client .create_pipeline (valid_config )
152152
153- def test_client_create_pipeline_from_yaml_success (self , mock_success_response ):
153+ def test_client_create_pipeline_from_yaml_success (self , mock_success ):
154154 """Test pipeline creation from YAML file."""
155155 client = Client ()
156- with patch (
157- "httpx.Client.request" , return_value = mock_success_response
158- ) as mock_request :
156+ with mock_success () as mock_request :
159157 client .create_pipeline (
160158 pipeline_config_yaml_path = "tests/data/valid_pipeline.yaml"
161159 )
162160 mock_request .assert_called_once_with (
163161 "POST" , client .ENDPOINT , json = mock_request .call_args [1 ]["json" ]
164162 )
165163
166- def test_client_create_pipeline_from_json_success (self , mock_success_response ):
164+ def test_client_create_pipeline_from_json_success (self , mock_success ):
167165 """Test pipeline creation from JSON file."""
168166 client = Client ()
169- with patch (
170- "httpx.Client.request" , return_value = mock_success_response
171- ) as mock_request :
167+ with mock_success () as mock_request :
172168 client .create_pipeline (
173169 pipeline_config_json_path = "tests/data/valid_pipeline.json"
174170 )
@@ -188,14 +184,12 @@ def test_client_create_pipeline_value_error(self, valid_config):
188184 with pytest .raises (ValueError ):
189185 client .create_pipeline ()
190186
191- def test_client_delete_pipeline_success (self , mock_success_response ):
187+ def test_client_delete_pipeline_success (self , mock_success ):
192188 """Test successful pipeline deletion."""
193189 client = Client ()
194190 pipeline_id = "test-pipeline-id"
195191
196- with patch (
197- "httpx.Client.request" , return_value = mock_success_response
198- ) as mock_delete_request :
192+ with mock_success () as mock_delete_request :
199193 client .delete_pipeline (pipeline_id )
200194 mock_delete_request .assert_called_once_with (
201195 "DELETE" , f"{ client .ENDPOINT } /{ pipeline_id } "
@@ -211,27 +205,23 @@ def test_client_delete_pipeline_not_found(self, mock_not_found_response):
211205 client .delete_pipeline (pipeline_id )
212206 assert "not found" in str (exc_info .value )
213207
214- def test_client_stop_pipeline_success (self , mock_success_response ):
208+ def test_client_stop_pipeline_success (self , mock_success ):
215209 """Test successful pipeline stop."""
216210 client = Client ()
217211 pipeline_id = "test-pipeline-id"
218212
219- with patch (
220- "httpx.Client.request" , return_value = mock_success_response
221- ) as mock_request :
213+ with mock_success () as mock_request :
222214 client .stop_pipeline (pipeline_id )
223215 mock_request .assert_called_once_with (
224216 "POST" , f"{ client .ENDPOINT } /{ pipeline_id } /stop"
225217 )
226218
227- def test_client_stop_pipeline_terminate_success (self , mock_success_response ):
219+ def test_client_stop_pipeline_terminate_success (self , mock_success ):
228220 """Test successful pipeline stop with terminate=True."""
229221 client = Client ()
230222 pipeline_id = "test-pipeline-id"
231223
232- with patch (
233- "httpx.Client.request" , return_value = mock_success_response
234- ) as mock_request :
224+ with mock_success () as mock_request :
235225 client .stop_pipeline (pipeline_id , terminate = True )
236226 mock_request .assert_called_once_with (
237227 "POST" , f"{ client .ENDPOINT } /{ pipeline_id } /terminate"
@@ -256,11 +246,9 @@ def test_pipeline_to_dict(self, valid_config):
256246 assert isinstance (pipeline_dict , dict )
257247 assert pipeline_dict ["pipeline_id" ] == valid_config ["pipeline_id" ]
258248
259- def test_pipeline_delete (self , pipeline_from_id , mock_success_response ):
249+ def test_pipeline_delete (self , pipeline_from_id , mock_success ):
260250 """Test Pipeline delete with explicit pipeline_id."""
261- with patch (
262- "httpx.Client.request" , return_value = mock_success_response
263- ) as mock_request :
251+ with mock_success () as mock_request :
264252 pipeline_from_id .delete ()
265253 mock_request .assert_called_once_with (
266254 "DELETE" ,
0 commit comments