11from datetime import datetime
2- from typing import Any , Self
2+ from typing import Self
33
44import pytest
55
1111from deepset_mcp .api .pipeline .models import (
1212 DeepsetPipeline ,
1313 DeepsetUser ,
14+ NoContentResponse ,
1415 PipelineServiceLevel ,
1516 PipelineValidationResult ,
1617 ValidationError ,
@@ -32,15 +33,17 @@ def __init__(
3233 list_response : list [DeepsetPipeline ] | None = None ,
3334 get_response : DeepsetPipeline | None = None ,
3435 validate_response : PipelineValidationResult | None = None ,
35- create_response : Any | None = None ,
36- update_response : Any | None = None ,
36+ create_response : NoContentResponse | None = None ,
37+ update_response : NoContentResponse | None = None ,
3738 get_exception : Exception | None = None ,
3839 update_exception : Exception | None = None ,
40+ create_exception : Exception | None = None ,
3941 ) -> None :
4042 self ._list_response = list_response
4143 self ._get_response = get_response
4244 self ._validate_response = validate_response
4345 self ._create_response = create_response
46+ self ._create_exception = create_exception
4447 self ._update_response = update_response
4548 self ._get_exception = get_exception
4649 self ._update_exception = update_exception
@@ -62,7 +65,9 @@ async def validate(self, yaml_config: str) -> PipelineValidationResult:
6265 return self ._validate_response
6366 raise NotImplementedError
6467
65- async def create (self , name : str , yaml_config : str ) -> Any :
68+ async def create (self , name : str , yaml_config : str ) -> NoContentResponse :
69+ if self ._create_exception :
70+ raise self ._create_exception
6671 if self ._create_response is not None :
6772 return self ._create_response
6873 raise NotImplementedError
@@ -72,7 +77,7 @@ async def update(
7277 pipeline_name : str ,
7378 updated_pipeline_name : str | None = None ,
7479 yaml_config : str | None = None ,
75- ) -> Any :
80+ ) -> NoContentResponse :
7681 if self ._update_exception :
7782 raise self ._update_exception
7883 if self ._update_response is not None :
@@ -204,27 +209,23 @@ async def test_create_pipeline_handles_validation_failure() -> None:
204209async def test_create_pipeline_handles_success_and_failure_response () -> None :
205210 valid_result = PipelineValidationResult (valid = True , errors = [])
206211
207- class Creation :
208- def __init__ (self , success : bool , text : str = "" ) -> None :
209- self .success = success
210- self .text = text
211-
212212 # success
213213 resource_succ = FakePipelineResource (
214214 validate_response = valid_result ,
215- create_response = Creation ( success = True ),
215+ create_response = NoContentResponse ( message = "created successfully" ),
216216 )
217217 client_succ = FakeClient (resource_succ )
218218 res_succ = await create_pipeline (client_succ , workspace = "ws" , pipeline_name = "p1" , yaml_configuration = "a: b" )
219+
219220 assert "created successfully" in res_succ
220221 # failure
221222 resource_fail = FakePipelineResource (
222223 validate_response = valid_result ,
223- create_response = Creation ( success = False , text = "bad things" ),
224+ create_exception = BadRequestError ( message = "bad things" ),
224225 )
225226 client_fail = FakeClient (resource_fail )
226227 res_fail = await create_pipeline (client_fail , workspace = "ws" , pipeline_name = "p1" , yaml_configuration = "a: b" )
227- assert "Failed to create pipeline 'p1': bad things" == res_fail
228+ assert "Failed to create pipeline 'p1': bad things (Status Code: 400) " == res_fail
228229
229230
230231@pytest .mark .asyncio
@@ -373,7 +374,7 @@ async def test_update_pipeline_exceptions_on_update() -> None:
373374
374375
375376@pytest .mark .asyncio
376- async def test_update_pipeline_success_and_failure_response () -> None :
377+ async def test_update_pipeline_success_response () -> None :
377378 user = DeepsetUser (user_id = "u1" , given_name = "A" , family_name = "B" )
378379 orig_yaml = "foo: 1"
379380 original = DeepsetPipeline (
@@ -389,14 +390,11 @@ async def test_update_pipeline_success_and_failure_response() -> None:
389390 )
390391 val_ok = PipelineValidationResult (valid = True , errors = [])
391392
392- class UpdateResp :
393- def __init__ (self , success : bool , text : str = "" ) -> None :
394- self .success = success
395- self .text = text
396-
397393 # success
398394 res_succ = FakePipelineResource (
399- get_response = original , validate_response = val_ok , update_response = UpdateResp (success = True )
395+ get_response = original ,
396+ validate_response = val_ok ,
397+ update_response = NoContentResponse (message = "successfully updated" ),
400398 )
401399 client_succ = FakeClient (res_succ )
402400 r_success = await update_pipeline (
@@ -407,16 +405,3 @@ def __init__(self, success: bool, text: str = "") -> None:
407405 replacement_config_snippet = "foo: 2" ,
408406 )
409407 assert "successfully updated" in r_success .lower ()
410- # failure
411- res_fail = FakePipelineResource (
412- get_response = original , validate_response = val_ok , update_response = UpdateResp (success = False , text = "nope" )
413- )
414- client_fail = FakeClient (res_fail )
415- r_fail = await update_pipeline (
416- client_fail ,
417- workspace = "ws" ,
418- pipeline_name = "np" ,
419- original_config_snippet = "foo: 1" ,
420- replacement_config_snippet = "foo: 2" ,
421- )
422- assert r_fail == "Failed to update the pipeline 'np': nope"
0 commit comments