@@ -115,17 +115,33 @@ async def test_update_pipeline_yaml_success_empty_response() -> None:
115115 assert result == {"status" : "success" , "message" : "API returned empty response body" }
116116
117117
118+ @pytest .mark .asyncio
118119@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
119- @mock .patch ("deepset_mcp.client.DeepsetClient.update_pipeline_yaml" )
120- def test_update_pipeline_yaml_api_error_422_json (mock_update : mock .Mock ) -> None :
120+ async def test_update_pipeline_yaml_api_error_422_json () -> None :
121121 """Tests API error (422) with JSON details."""
122122 error_details = {"detail" : [{"type" : "validation_error" , "msg" : "Something is wrong" }]}
123- mock_update .return_value = {"error" : "API Error: 422" , "details" : error_details }
124-
125- result = update_pipeline_yaml (TEST_PIPELINE_NAME , VALID_YAML_CONTENT )
126-
127- mock_update .assert_called_once_with (TEST_PIPELINE_NAME , VALID_YAML_CONTENT )
128- assert result == {"error" : "API Error: 422" , "details" : error_details }
123+ error_response = {"error" : "API Error: 422" , "details" : error_details }
124+
125+ # Since update_pipeline_yaml is async, we need to test it differently
126+ with mock .patch ("deepset_mcp.main.DeepsetClient" ) as mock_client_class :
127+ # Setup the mock client instance
128+ mock_client_instance = mock .MagicMock ()
129+ mock_client_instance .__aenter__ .return_value = mock_client_instance
130+ mock_client_instance .__aexit__ .return_value = None
131+ mock_client_instance .workspace = TEST_WORKSPACE
132+ mock_client_instance .request .return_value = error_response
133+ mock_client_class .return_value = mock_client_instance
134+
135+ # Call the function
136+ result = await update_pipeline_yaml (TEST_PIPELINE_NAME , VALID_YAML_CONTENT )
137+
138+ # Verify the call was made correctly
139+ mock_client_instance .request .assert_called_once_with (
140+ f"/workspaces/{ TEST_WORKSPACE } /pipelines/{ TEST_PIPELINE_NAME } /yaml" ,
141+ method = "PUT" ,
142+ data = {"query_yaml" : VALID_YAML_CONTENT }
143+ )
144+ assert result == error_response
129145
130146
131147@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
0 commit comments