@@ -890,3 +890,126 @@ async def test_get_logs_preserves_extra_fields(self) -> None:
890890 # Verify extra fields are preserved
891891 assert "custom_field" in result .data [0 ].extra_fields
892892 assert result .data [0 ].extra_fields ["custom_field" ] == "custom_value"
893+
894+ @pytest .mark .asyncio
895+ async def test_deploy_pipeline_success (self ) -> None :
896+ """Test successful pipeline deployment."""
897+ # Create client with successful response
898+ client = DummyClient (responses = {"test-workspace/pipelines/test-pipeline/deploy" : {"status" : "success" }})
899+
900+ # Create resource and call deploy method
901+ resource = PipelineResource (client = client , workspace = "test-workspace" )
902+ result = await resource .deploy (pipeline_name = "test-pipeline" )
903+
904+ # Verify results
905+ assert isinstance (result , PipelineValidationResult )
906+ assert result .valid is True
907+ assert len (result .errors ) == 0
908+
909+ # Verify request
910+ assert len (client .requests ) == 1
911+ assert client .requests [0 ]["endpoint" ] == "v1/workspaces/test-workspace/pipelines/test-pipeline/deploy"
912+ assert client .requests [0 ]["method" ] == "POST"
913+
914+ @pytest .mark .asyncio
915+ async def test_deploy_pipeline_with_validation_errors (self ) -> None :
916+ """Test deployment with validation errors (422)."""
917+ # Create a response with validation errors
918+ validation_errors = {
919+ "details" : [
920+ {"code" : "invalid_component" , "message" : "Component 'invalid_reader' is not available" },
921+ {"code" : "missing_field" , "message" : "Required field 'index' is missing" },
922+ ]
923+ }
924+
925+ # Create mock client with 422 response containing validation errors
926+ client = DummyClient ()
927+ transport_response = TransportResponse (text = "" , status_code = 422 , json = validation_errors )
928+ client .responses = {"test-workspace/pipelines/test-pipeline/deploy" : transport_response }
929+
930+ # Run the deployment
931+ resource = PipelineResource (client = client , workspace = "test-workspace" )
932+ result = await resource .deploy (pipeline_name = "test-pipeline" )
933+
934+ # Check the result
935+ assert isinstance (result , PipelineValidationResult )
936+ assert result .valid is False
937+ assert len (result .errors ) == 2
938+ assert result .errors [0 ].code == "invalid_component"
939+ assert result .errors [0 ].message == "Component 'invalid_reader' is not available"
940+ assert result .errors [1 ].code == "missing_field"
941+ assert result .errors [1 ].message == "Required field 'index' is missing"
942+
943+ @pytest .mark .asyncio
944+ async def test_deploy_pipeline_with_400_error (self ) -> None :
945+ """Test deployment with 400 error."""
946+ # Create response for 400 error
947+ error_response : TransportResponse [None ] = TransportResponse (text = "Bad request" , status_code = 400 , json = None )
948+
949+ client = DummyClient (responses = {"test-workspace/pipelines/test-pipeline/deploy" : error_response })
950+
951+ # Run the deployment
952+ resource = PipelineResource (client = client , workspace = "test-workspace" )
953+ result = await resource .deploy (pipeline_name = "test-pipeline" )
954+
955+ # Check the result
956+ assert result .valid is False
957+ assert len (result .errors ) == 1
958+ assert result .errors [0 ].code == "DEPLOYMENT_ERROR"
959+ assert result .errors [0 ].message == "Bad request"
960+
961+ @pytest .mark .asyncio
962+ async def test_deploy_pipeline_with_404_error (self ) -> None :
963+ """Test deployment with 404 error (pipeline not found)."""
964+ # Create response for 404 error
965+ error_response : TransportResponse [None ] = TransportResponse (
966+ text = "Pipeline not found" , status_code = 404 , json = None
967+ )
968+
969+ client = DummyClient (responses = {"test-workspace/pipelines/nonexistent-pipeline/deploy" : error_response })
970+
971+ # Run the deployment
972+ resource = PipelineResource (client = client , workspace = "test-workspace" )
973+ result = await resource .deploy (pipeline_name = "nonexistent-pipeline" )
974+
975+ # Check the result
976+ assert result .valid is False
977+ assert len (result .errors ) == 1
978+ assert result .errors [0 ].code == "DEPLOYMENT_ERROR"
979+ assert result .errors [0 ].message == "Pipeline not found"
980+
981+ @pytest .mark .asyncio
982+ async def test_deploy_pipeline_with_500_error (self ) -> None :
983+ """Test deployment with 500 error (unexpected error)."""
984+ # Create response for 500 error
985+ error_response : TransportResponse [None ] = TransportResponse (
986+ text = "Internal server error" , status_code = 500 , json = None
987+ )
988+
989+ client = DummyClient (responses = {"test-workspace/pipelines/test-pipeline/deploy" : error_response })
990+
991+ # Run the deployment and expect an exception
992+ resource = PipelineResource (client = client , workspace = "test-workspace" )
993+ with pytest .raises (UnexpectedAPIError ) as exc_info :
994+ await resource .deploy (pipeline_name = "test-pipeline" )
995+
996+ assert exc_info .value .status_code == 500
997+ assert "Internal server error" in str (exc_info .value )
998+
999+ @pytest .mark .asyncio
1000+ async def test_deploy_pipeline_with_empty_error_text (self ) -> None :
1001+ """Test deployment with error response but empty text."""
1002+ # Create response for 400 error with empty text
1003+ error_response : TransportResponse [None ] = TransportResponse (text = "" , status_code = 400 , json = None )
1004+
1005+ client = DummyClient (responses = {"test-workspace/pipelines/test-pipeline/deploy" : error_response })
1006+
1007+ # Run the deployment
1008+ resource = PipelineResource (client = client , workspace = "test-workspace" )
1009+ result = await resource .deploy (pipeline_name = "test-pipeline" )
1010+
1011+ # Check the result
1012+ assert result .valid is False
1013+ assert len (result .errors ) == 1
1014+ assert result .errors [0 ].code == "DEPLOYMENT_ERROR"
1015+ assert result .errors [0 ].message == "HTTP 400 error"
0 commit comments