44import os
55
66# Assuming your main code is in main.py
7- from main import update_pipeline_yaml , DEEPSET_API_BASE_URL
7+ from deepset_mcp . main import update_pipeline_yaml , DEEPSET_API_BASE_URL
88
99# --- Test Data ---
1010TEST_WORKSPACE = "test-workspace"
@@ -42,7 +42,7 @@ def create_mock_response(status_code, json_data=None, text_data=None):
4242# --- Test Cases ---
4343
4444@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
45- @mock .patch ('main.requests.put' ) # Mock requests.put used in update_pipeline_yaml
45+ @mock .patch ('deepset_mcp. main.requests.put' ) # Mock requests.put used in update_pipeline_yaml
4646def test_update_pipeline_yaml_success_json_response (mock_put ):
4747 """Tests successful update with JSON response."""
4848 mock_response = create_mock_response (200 , json_data = {"status" : "success" , "message" : "Updated" })
@@ -64,7 +64,7 @@ def test_update_pipeline_yaml_success_json_response(mock_put):
6464 assert result == {"status" : "success" , "message" : "Updated" }
6565
6666@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
67- @mock .patch ('main.requests.put' )
67+ @mock .patch ('deepset_mcp. main.requests.put' )
6868def test_update_pipeline_yaml_success_empty_response (mock_put ):
6969 """Tests successful update with empty response body."""
7070 mock_response = create_mock_response (200 , text_data = "" ) # Empty body
@@ -78,7 +78,7 @@ def test_update_pipeline_yaml_success_empty_response(mock_put):
7878 assert result == {"status" : "success" , "message" : "Pipeline YAML updated successfully (empty response body)" }
7979
8080@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
81- @mock .patch ('main.requests.put' )
81+ @mock .patch ('deepset_mcp. main.requests.put' )
8282def test_update_pipeline_yaml_api_error_422_json (mock_put ):
8383 """Tests API error (422) with JSON details."""
8484 error_details = {"detail" : [{"type" : "validation_error" , "msg" : "Something is wrong" }]}
@@ -94,7 +94,7 @@ def test_update_pipeline_yaml_api_error_422_json(mock_put):
9494 }
9595
9696@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
97- @mock .patch ('main.requests.put' )
97+ @mock .patch ('deepset_mcp. main.requests.put' )
9898def test_update_pipeline_yaml_api_error_500_text (mock_put ):
9999 """Tests API error (500) with non-JSON text details."""
100100 error_text = "Internal Server Error"
@@ -110,7 +110,7 @@ def test_update_pipeline_yaml_api_error_500_text(mock_put):
110110 }
111111
112112@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
113- @mock .patch ('main.requests.put' )
113+ @mock .patch ('deepset_mcp. main.requests.put' )
114114def test_update_pipeline_yaml_request_exception (mock_put ):
115115 """Tests network request failure."""
116116 mock_put .side_effect = requests .exceptions .RequestException ("Connection timed out" )
@@ -122,15 +122,15 @@ def test_update_pipeline_yaml_request_exception(mock_put):
122122 assert "Request failed: Connection timed out" in result ["error" ]
123123
124124@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
125- @mock .patch ('main.requests.put' ) # Still need to mock put, even if not called
125+ @mock .patch ('deepset_mcp. main.requests.put' ) # Still need to mock put, even if not called
126126def test_update_pipeline_yaml_empty_content (mock_put ):
127127 """Tests the function's validation for empty YAML content."""
128128 result = update_pipeline_yaml (TEST_PIPELINE_NAME , "" )
129129 assert result == {"error" : "Empty YAML content provided" }
130130 mock_put .assert_not_called () # Ensure API wasn't called
131131
132132@mock .patch .dict (os .environ , {"DEEPSET_WORKSPACE" : TEST_WORKSPACE , "DEEPSET_API_KEY" : TEST_API_KEY })
133- @mock .patch ('main.requests.put' )
133+ @mock .patch ('deepset_mcp. main.requests.put' )
134134def test_update_pipeline_yaml_invalid_structure (mock_put ):
135135 """Tests the function's validation for missing 'components:'."""
136136 result = update_pipeline_yaml (TEST_PIPELINE_NAME , INVALID_YAML_CONTENT_NO_COMPONENTS )
0 commit comments