@@ -379,17 +379,19 @@ async def test_verify_graph_success(self):
379379 mock_node1 .outputs_schema = {}
380380 mock_node1 .secrets = []
381381
382- with patch ('app.tasks.verify_graph.RegisteredNode.list_nodes_by_templates' ) as mock_list_nodes :
382+ with patch ('app.tasks.verify_graph.RegisteredNode.list_nodes_by_templates' , new_callable = AsyncMock ) as mock_list_nodes :
383383 mock_list_nodes .return_value = [mock_node1 ]
384-
385- with patch ('app.tasks.verify_graph.verify_node_exists' ) as mock_verify_nodes :
386- with patch ('app.tasks.verify_graph.verify_secrets' ) as mock_verify_secrets :
387- with patch ('app.tasks.verify_graph.verify_inputs' ) as mock_verify_inputs :
388- mock_verify_nodes .return_value = []
389- mock_verify_secrets .return_value = []
390- mock_verify_inputs .return_value = []
391-
392- await verify_graph (graph_template )
384+
385+ with patch ('app.tasks.verify_graph.verify_node_exists' , new_callable = AsyncMock ) as mock_verify_nodes :
386+ with patch ('app.tasks.verify_graph.verify_secrets' , new_callable = AsyncMock ) as mock_verify_secrets :
387+ with patch ('app.tasks.verify_graph.verify_inputs' , new_callable = AsyncMock ) as mock_verify_inputs :
388+ with patch ('app.tasks.verify_graph.cancel_crons' , new_callable = AsyncMock ) as mock_cancel_crons :
389+ with patch ('app.tasks.verify_graph.create_crons' , new_callable = AsyncMock ) as mock_create_crons :
390+ mock_verify_nodes .return_value = []
391+ mock_verify_secrets .return_value = []
392+ mock_verify_inputs .return_value = []
393+
394+ await verify_graph (graph_template , [])
393395
394396 assert graph_template .validation_status == GraphTemplateValidationStatus .VALID
395397 assert graph_template .validation_errors == []
@@ -425,7 +427,7 @@ async def test_verify_graph_with_errors(self):
425427 mock_verify_secrets .return_value = ["Secret error" ]
426428 mock_verify_inputs .return_value = ["Input error" ]
427429
428- await verify_graph (graph_template )
430+ await verify_graph (graph_template , [] )
429431
430432 assert graph_template .validation_status == GraphTemplateValidationStatus .INVALID
431433 assert graph_template .validation_errors == ["Node error" , "Secret error" , "Input error" ]
@@ -446,7 +448,9 @@ async def test_verify_graph_exception(self):
446448 # Mock the save method to be async
447449 graph_template .save = AsyncMock ()
448450
449- await verify_graph (graph_template )
451+ # The verify_graph function should catch the exception, log it, set status, and re-raise it
452+ with pytest .raises (Exception , match = "Database error" ):
453+ await verify_graph (graph_template , [])
450454
451455 assert graph_template .validation_status == GraphTemplateValidationStatus .INVALID
452456 assert graph_template .validation_errors == ["Validation failed due to unexpected error: Database error" ]
@@ -469,8 +473,9 @@ async def test_verify_graph_with_exception():
469473 # Mock RegisteredNode.list_nodes_by_templates to raise an exception
470474 mock_registered_node_cls .list_nodes_by_templates .side_effect = Exception ("Database connection error" )
471475
472- # This should handle the exception and mark the graph as invalid
473- await verify_graph (graph_template )
476+ # This should handle the exception and mark the graph as invalid, then re-raise
477+ with pytest .raises (Exception , match = "Database connection error" ):
478+ await verify_graph (graph_template , [])
474479
475480 # Verify that the graph was marked as invalid with error
476481 assert graph_template .validation_status == GraphTemplateValidationStatus .INVALID
@@ -489,18 +494,33 @@ async def test_verify_graph_with_validation_errors():
489494 graph_template .validation_errors = MagicMock ()
490495
491496 # This test verifies that verify_graph can handle validation errors
492- # The complex mocking of internal functions is tested separately
493- with patch ('app.tasks.verify_graph.RegisteredNode' ) as mock_registered_node_cls :
494- # Mock registered nodes to return empty list (will cause validation errors)
495- mock_registered_node_cls .list_nodes_by_templates .return_value = []
497+ # Mock all the dependencies to avoid database and scheduler issues
498+ with patch ('app.tasks.verify_graph.RegisteredNode' ) as mock_registered_node_cls , \
499+ patch ('app.tasks.verify_graph.verify_node_exists' ) as mock_verify_nodes , \
500+ patch ('app.tasks.verify_graph.verify_secrets' ) as mock_verify_secrets , \
501+ patch ('app.tasks.verify_graph.verify_inputs' ) as mock_verify_inputs , \
502+ patch ('app.tasks.verify_graph.cancel_crons' , new_callable = AsyncMock ) as mock_cancel_crons , \
503+ patch ('app.tasks.verify_graph.create_crons' , new_callable = AsyncMock ) as mock_create_crons :
504+
505+ # Mock registered nodes to return empty list
506+ mock_registered_node_cls .list_nodes_by_templates = AsyncMock (return_value = [])
507+
508+ # Mock validation functions to return errors (simulating validation failure)
509+ mock_verify_nodes .return_value = ["Node validation error" ]
510+ mock_verify_secrets .return_value = []
511+ mock_verify_inputs .return_value = []
512+
513+ # Mock graph template properties
514+ graph_template .triggers = []
515+ graph_template .name = "test_graph"
496516
497517 # This should mark the graph as invalid due to validation errors
498- await verify_graph (graph_template )
518+ await verify_graph (graph_template , [] )
499519
500- # Verify that the graph was marked as invalid
501- assert graph_template .validation_status == GraphTemplateValidationStatus .INVALID
502- # The specific error message depends on the actual validation logic
503- assert len (graph_template .validation_errors ) > 0
520+ # Verify that the graph was marked as invalid
521+ assert graph_template .validation_status == GraphTemplateValidationStatus .INVALID
522+ # The specific error message depends on the actual validation logic
523+ assert len (graph_template .validation_errors ) > 0
504524
505525
506526@pytest .mark .asyncio
@@ -514,8 +534,14 @@ async def test_verify_graph_with_valid_graph():
514534 graph_template .validation_errors = MagicMock ()
515535
516536 # This test verifies that verify_graph can handle valid graphs
517- # The complex mocking of internal functions is tested separately
518- with patch ('app.tasks.verify_graph.RegisteredNode' ) as mock_registered_node_cls :
537+ # Mock all the dependencies to avoid database and scheduler issues
538+ with patch ('app.tasks.verify_graph.RegisteredNode' ) as mock_registered_node_cls , \
539+ patch ('app.tasks.verify_graph.verify_node_exists' ) as mock_verify_nodes , \
540+ patch ('app.tasks.verify_graph.verify_secrets' ) as mock_verify_secrets , \
541+ patch ('app.tasks.verify_graph.verify_inputs' ) as mock_verify_inputs , \
542+ patch ('app.tasks.verify_graph.cancel_crons' , new_callable = AsyncMock ) as mock_cancel_crons , \
543+ patch ('app.tasks.verify_graph.create_crons' , new_callable = AsyncMock ) as mock_create_crons :
544+
519545 # Mock registered nodes to return a valid node
520546 mock_registered_node = MagicMock ()
521547 mock_registered_node .name = "test_node"
@@ -525,14 +551,23 @@ async def test_verify_graph_with_valid_graph():
525551 mock_registered_node .inputs_schema = {}
526552 mock_registered_node .outputs_schema = {}
527553 mock_registered_node .secrets = []
528- mock_registered_node_cls .list_nodes_by_templates .return_value = [mock_registered_node ]
554+ mock_registered_node_cls .list_nodes_by_templates = AsyncMock (return_value = [mock_registered_node ])
555+
556+ # Mock validation functions to return no errors (simulating successful validation)
557+ mock_verify_nodes .return_value = []
558+ mock_verify_secrets .return_value = []
559+ mock_verify_inputs .return_value = []
560+
561+ # Mock graph template properties
562+ graph_template .triggers = []
563+ graph_template .name = "test_graph"
529564
530565 # This should mark the graph as valid
531- await verify_graph (graph_template )
566+ await verify_graph (graph_template , [] )
532567
533- # Verify that the graph was processed (status may vary based on actual validation)
534- # The specific status depends on the actual validation logic
535- assert graph_template .save .called
568+ # Verify that the graph was processed (status may vary based on actual validation)
569+ # The specific status depends on the actual validation logic
570+ assert graph_template .save .called
536571
537572
538573
0 commit comments