@@ -340,42 +340,34 @@ def test_list_pipelines_should_fail_if_status_not_200(self, mock_request, hook):
340340 @mock .patch (HOOK_STR .format ("DataFusionHook._cdap_request" ))
341341 def test_start_pipeline (self , mock_request , hook ):
342342 run_id = 1234
343- mock_request .return_value = mock .MagicMock (status = 200 , data = f'[ {{"runId":{ run_id } }}] ' )
343+ mock_request .return_value = mock .MagicMock (status = 200 , data = f'{{"runId":{ run_id } }}' )
344344
345- hook .start_pipeline (pipeline_name = PIPELINE_NAME , instance_url = INSTANCE_URL , runtime_args = RUNTIME_ARGS )
346- body = [
347- {
348- "appId" : PIPELINE_NAME ,
349- "programType" : "workflow" ,
350- "programId" : "DataPipelineWorkflow" ,
351- "runtimeargs" : RUNTIME_ARGS ,
352- }
353- ]
345+ result = hook .start_pipeline (
346+ pipeline_name = PIPELINE_NAME , instance_url = INSTANCE_URL , runtime_args = RUNTIME_ARGS
347+ )
348+ assert result == str (run_id )
354349 mock_request .assert_called_once_with (
355- url = f"{ INSTANCE_URL } /v3/namespaces/default/start" , method = "POST" , body = body
350+ url = f"{ INSTANCE_URL } /v3/namespaces/default/apps/{ PIPELINE_NAME } /workflows/DataPipelineWorkflow/start" ,
351+ method = "POST" ,
352+ body = RUNTIME_ARGS ,
356353 )
357354
358355 @mock .patch (HOOK_STR .format ("DataFusionHook._cdap_request" ))
359356 def test_start_pipeline_stream (self , mock_request , hook ):
360- run_id = 1234
361- mock_request .return_value = mock .MagicMock (status = 200 , data = f'[ {{"runId":{ run_id } }}] ' )
357+ run_id = "test-run-123"
358+ mock_request .return_value = mock .MagicMock (status = 200 , data = f'{{"runId":" { run_id } "}} ' )
362359
363- hook .start_pipeline (
360+ result = hook .start_pipeline (
364361 pipeline_name = PIPELINE_NAME ,
365362 instance_url = INSTANCE_URL ,
366363 runtime_args = RUNTIME_ARGS ,
367364 pipeline_type = DataFusionPipelineType .STREAM ,
368365 )
369- body = [
370- {
371- "appId" : PIPELINE_NAME ,
372- "programType" : "spark" ,
373- "programId" : "DataStreamsSparkStreaming" ,
374- "runtimeargs" : RUNTIME_ARGS ,
375- }
376- ]
366+ assert result == run_id
377367 mock_request .assert_called_once_with (
378- url = f"{ INSTANCE_URL } /v3/namespaces/default/start" , method = "POST" , body = body
368+ url = f"{ INSTANCE_URL } /v3/namespaces/default/apps/{ PIPELINE_NAME } /sparks/DataStreamsSparkStreaming/start" ,
369+ method = "POST" ,
370+ body = RUNTIME_ARGS ,
379371 )
380372
381373 @mock .patch (HOOK_STR .format ("DataFusionHook._cdap_request" ))
@@ -390,16 +382,10 @@ def test_start_pipeline_should_fail_if_empty_data_response(self, mock_request, h
390382 hook .start_pipeline (
391383 pipeline_name = PIPELINE_NAME , instance_url = INSTANCE_URL , runtime_args = RUNTIME_ARGS
392384 )
393- body = [
394- {
395- "appId" : PIPELINE_NAME ,
396- "programType" : "workflow" ,
397- "programId" : "DataPipelineWorkflow" ,
398- "runtimeargs" : RUNTIME_ARGS ,
399- }
400- ]
401385 mock_request .assert_called_once_with (
402- url = f"{ INSTANCE_URL } /v3/namespaces/default/start" , method = "POST" , body = body
386+ url = f"{ INSTANCE_URL } /v3/namespaces/default/apps/{ PIPELINE_NAME } /workflows/DataPipelineWorkflow/start" ,
387+ method = "POST" ,
388+ body = RUNTIME_ARGS ,
403389 )
404390
405391 @mock .patch (HOOK_STR .format ("DataFusionHook._cdap_request" ))
@@ -409,16 +395,29 @@ def test_start_pipeline_should_fail_if_status_not_200(self, mock_request, hook):
409395 hook .start_pipeline (
410396 pipeline_name = PIPELINE_NAME , instance_url = INSTANCE_URL , runtime_args = RUNTIME_ARGS
411397 )
412- body = [
413- {
414- "appId" : PIPELINE_NAME ,
415- "programType" : "workflow" ,
416- "programId" : "DataPipelineWorkflow" ,
417- "runtimeargs" : RUNTIME_ARGS ,
418- }
419- ]
420398 mock_request .assert_called_once_with (
421- url = f"{ INSTANCE_URL } /v3/namespaces/default/start" , method = "POST" , body = body
399+ url = f"{ INSTANCE_URL } /v3/namespaces/default/apps/{ PIPELINE_NAME } /workflows/DataPipelineWorkflow/start" ,
400+ method = "POST" ,
401+ body = RUNTIME_ARGS ,
402+ )
403+
404+ @mock .patch (HOOK_STR .format ("DataFusionHook._cdap_request" ))
405+ def test_start_pipeline_should_fail_if_no_run_id (self , mock_request , hook ):
406+ """Test that start_pipeline fails gracefully when response doesn't contain runId."""
407+ error_response = '{"error": "Invalid runtime arguments"}'
408+ mock_request .return_value = mock .MagicMock (status = 200 , data = error_response )
409+ with pytest .raises (
410+ AirflowException ,
411+ match = r"Failed to start pipeline 'shrubberyPipeline'. "
412+ r"The response does not contain a runId. Error: Invalid runtime arguments" ,
413+ ):
414+ hook .start_pipeline (
415+ pipeline_name = PIPELINE_NAME , instance_url = INSTANCE_URL , runtime_args = RUNTIME_ARGS
416+ )
417+ mock_request .assert_called_once_with (
418+ url = f"{ INSTANCE_URL } /v3/namespaces/default/apps/{ PIPELINE_NAME } /workflows/DataPipelineWorkflow/start" ,
419+ method = "POST" ,
420+ body = RUNTIME_ARGS ,
422421 )
423422
424423 @mock .patch (HOOK_STR .format ("DataFusionHook._cdap_request" ))
0 commit comments