@@ -587,7 +587,7 @@ async def test_import_index_with_overwrite_fallback_to_create(
587587 async def test_import_pipeline_with_overwrite_true (
588588 self , pipeline_service : PipelineService , index_pipeline : Pipeline , mock_api : AsyncMock
589589 ) -> None :
590- """Test importing a pipeline with overwrite=True uses PUT endpoint."""
590+ """Test importing a pipeline with overwrite=True creates a new version via POST endpoint."""
591591 config = PipelineConfig (
592592 name = "test_pipeline_overwrite" ,
593593 inputs = PipelineInputs (query = ["retriever.query" ]),
@@ -600,25 +600,21 @@ async def test_import_pipeline_with_overwrite_true(
600600 validation_response = Mock (spec = Response )
601601 validation_response .status_code = HTTPStatus .NO_CONTENT .value
602602
603- # Mock successful versions response
604- versions_response = Mock (status_code = HTTPStatus .OK .value )
605- versions_response .json .return_value = {
606- "data" : [{"version_id" : "42abcd" }],
607- }
608-
609- # Mock successful overwrite response
603+ # Mock successful "create new version" response
610604 overwrite_response = Mock (spec = Response )
611- overwrite_response .status_code = HTTPStatus .OK .value
605+ overwrite_response .status_code = HTTPStatus .CREATED .value
612606
613- mock_api .post .return_value = validation_response
614- mock_api .get .return_value = versions_response
615- mock_api .put .return_value = overwrite_response
607+ # First POST is validation, second POST is "create new version"
608+ mock_api .post .side_effect = [validation_response , overwrite_response ]
616609
617610 await pipeline_service .import_async (index_pipeline , config )
618611
619- # Should call validation endpoint first, then overwrite endpoint
620- assert mock_api .post .call_count == 1
621- assert mock_api .patch .call_count == 1
612+ # Should call validation endpoint first, then create-version endpoint
613+ assert mock_api .post .call_count == 2
614+ # No GET/PATCH/PUT calls in the overwrite path anymore
615+ assert mock_api .get .call_count == 0
616+ assert mock_api .patch .call_count == 0
617+ assert mock_api .put .call_count == 0
622618
623619 # Check validation call
624620 validation_call = mock_api .post .call_args_list [0 ]
@@ -627,16 +623,16 @@ async def test_import_pipeline_with_overwrite_true(
627623 # When overwrite=True, name should be excluded from validation payload
628624 assert "name" not in validation_call .kwargs ["json" ]
629625
630- # Check overwrite call
631- overwrite_call = mock_api .patch .call_args_list [0 ]
632- assert overwrite_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_overwrite/versions/42abcd "
626+ # Check create-version call
627+ overwrite_call = mock_api .post .call_args_list [1 ]
628+ assert overwrite_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_overwrite/versions"
633629 assert "config_yaml" in overwrite_call .kwargs ["json" ]
634630
635631 @pytest .mark .asyncio
636632 async def test_import_pipeline_with_overwrite_fallback_to_create (
637633 self , pipeline_service : PipelineService , index_pipeline : Pipeline , mock_api : AsyncMock
638634 ) -> None :
639- """Test importing a pipeline with overwrite=True that falls back to create when resource doesn't exist ."""
635+ """Test importing a pipeline with overwrite=True that falls back to create when version creation fails ."""
640636
641637 config = PipelineConfig (
642638 name = "test_pipeline_fallback" ,
@@ -650,22 +646,26 @@ async def test_import_pipeline_with_overwrite_fallback_to_create(
650646 validation_response = Mock (spec = Response )
651647 validation_response .status_code = HTTPStatus .NO_CONTENT .value
652648
653- # Mock 404 response for GET (resource not found )
654- not_found_response = Mock (spec = Response )
655- not_found_response .status_code = HTTPStatus .NOT_FOUND .value
649+ # Mock non-201 response for POST /pipelines/{name}/versions (version creation fails )
650+ version_fail_response = Mock (spec = Response )
651+ version_fail_response .status_code = HTTPStatus .BAD_REQUEST .value
656652
657- # Mock successful creation response
653+ # Mock successful creation response for POST /pipelines
658654 create_response = Mock (spec = Response )
659655 create_response .status_code = HTTPStatus .CREATED .value
660656
661- mock_api . post . side_effect = [ validation_response , create_response ]
662- mock_api .get . return_value = not_found_response
657+ # POST calls: validation, create-version (fails), create-pipeline (fallback)
658+ mock_api .post . side_effect = [ validation_response , version_fail_response , create_response ]
663659
664660 await pipeline_service .import_async (index_pipeline , config )
665661
666- # Should call validation endpoint, then GET (which returns 404), then POST to create
667- assert mock_api .post .call_count == 2
668- assert mock_api .get .call_count == 1
662+ # Should call validation endpoint, then POST to create new version (fails),
663+ # then POST to create the pipeline
664+ assert mock_api .post .call_count == 3
665+ # No GET anymore; overwrite logic doesn't fetch versions
666+ assert mock_api .get .call_count == 0
667+ assert mock_api .patch .call_count == 0
668+ assert mock_api .put .call_count == 0
669669
670670 # Check validation call
671671 validation_call = mock_api .post .call_args_list [0 ]
@@ -674,12 +674,13 @@ async def test_import_pipeline_with_overwrite_fallback_to_create(
674674 # When overwrite=True, name should be excluded from validation payload
675675 assert "name" not in validation_call .kwargs ["json" ]
676676
677- # Check GET versions attempt
678- get_call = mock_api .get .call_args_list [0 ]
679- assert get_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_fallback/versions"
677+ # Check attempted version creation call
678+ version_call = mock_api .post .call_args_list [1 ]
679+ assert version_call .kwargs ["endpoint" ] == "pipelines/test_pipeline_fallback/versions"
680+ assert "config_yaml" in version_call .kwargs ["json" ]
680681
681- # Check fallback POST call
682- create_call = mock_api .post .call_args_list [1 ]
682+ # Check fallback create-pipeline call
683+ create_call = mock_api .post .call_args_list [2 ]
683684 assert create_call .kwargs ["endpoint" ] == "pipelines"
684685 assert create_call .kwargs ["json" ]["name" ] == "test_pipeline_fallback"
685686 assert "query_yaml" in create_call .kwargs ["json" ]
0 commit comments