Skip to content

Commit 78a0685

Browse files
committed
test: update test_update_pipeline_yaml_success_json_response to use MockHttpClient
1 parent ff322fc commit 78a0685

1 file changed

Lines changed: 35 additions & 11 deletions

File tree

test/test_main.py

Lines changed: 35 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,43 @@ def create_mock_response(
5050
# --- Test Cases ---
5151

5252

53+
@pytest.mark.asyncio
5354
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})
54-
@mock.patch("deepset_mcp.client.DeepsetClient.update_pipeline_yaml")
55-
def test_update_pipeline_yaml_success_json_response(mock_update: mock.Mock) -> None:
55+
async def test_update_pipeline_yaml_success_json_response() -> None:
5656
"""Tests successful update with JSON response."""
57-
mock_update.return_value = {"status": "success", "message": "Updated"}
58-
59-
# Since update_pipeline_yaml is now an async function wrapped with async_to_sync,
60-
# we need to mock the async method but test the sync wrapper
61-
result = update_pipeline_yaml(TEST_PIPELINE_NAME, VALID_YAML_CONTENT)
62-
63-
# Check that the DeepsetClient's update_pipeline_yaml method was called with the right args
64-
mock_update.assert_called_once_with(TEST_PIPELINE_NAME, VALID_YAML_CONTENT)
65-
assert result == {"status": "success", "message": "Updated"}
57+
# Create a mock client with the expected responses
58+
mock_responses = {}
59+
update_response = mock.Mock(spec=httpx.Response)
60+
update_response.status_code = 200
61+
update_response.text = '{"status": "success", "message": "Updated"}'
62+
update_response.json.return_value = {"status": "success", "message": "Updated"}
63+
64+
endpoint = f"/workspaces/{TEST_WORKSPACE}/pipelines/{TEST_PIPELINE_NAME}/yaml"
65+
url = f"{DEEPSET_API_BASE_URL}{endpoint}"
66+
mock_responses[f"PUT {url}"] = update_response
67+
68+
mock_client = MockHttpClient(mock_responses)
69+
70+
# Since update_pipeline_yaml is async, we need to test it differently
71+
with mock.patch("deepset_mcp.main.DeepsetClient") as mock_client_class:
72+
# Setup the mock client instance
73+
mock_client_instance = mock.MagicMock()
74+
mock_client_instance.__aenter__.return_value = mock_client_instance
75+
mock_client_instance.__aexit__.return_value = None
76+
mock_client_instance.workspace = TEST_WORKSPACE
77+
mock_client_instance.request.return_value = {"status": "success", "message": "Updated"}
78+
mock_client_class.return_value = mock_client_instance
79+
80+
# Call the function
81+
result = await update_pipeline_yaml(TEST_PIPELINE_NAME, VALID_YAML_CONTENT)
82+
83+
# Verify the call was made correctly
84+
mock_client_instance.request.assert_called_once_with(
85+
f"/workspaces/{TEST_WORKSPACE}/pipelines/{TEST_PIPELINE_NAME}/yaml",
86+
method="PUT",
87+
data={"query_yaml": VALID_YAML_CONTENT}
88+
)
89+
assert result == {"status": "success", "message": "Updated"}
6690

6791

6892
@mock.patch.dict(os.environ, {"DEEPSET_WORKSPACE": TEST_WORKSPACE, "DEEPSET_API_KEY": TEST_API_KEY})

0 commit comments

Comments
 (0)