@@ -395,10 +395,49 @@ def test_handle_project_updated_svm_tag_removed(
395
395
mock_netapp_manager .check_if_svm_exists .assert_called_once_with (
396
396
project_id = "test-project-123"
397
397
)
398
+ # Should call cleanup_project when tag is removed but SVM exists
399
+ mock_netapp_manager .cleanup_project .assert_called_once_with ("test-project-123" )
398
400
# Should not create SVM or volume when tag is removed
399
401
mock_netapp_manager .create_svm .assert_not_called ()
400
402
mock_netapp_manager .create_volume .assert_not_called ()
401
403
404
+ @patch ("understack_workflows.oslo_event.keystone_project.NetAppManager" )
405
+ @patch ("understack_workflows.oslo_event.keystone_project._keystone_project_tags" )
406
+ @patch ("builtins.open" )
407
+ def test_handle_project_updated_svm_tag_removed_no_svm (
408
+ self ,
409
+ mock_open ,
410
+ mock_tags ,
411
+ mock_netapp_class ,
412
+ mock_conn ,
413
+ mock_nautobot ,
414
+ valid_update_event_data ,
415
+ ):
416
+ """Test project update when SVM_UNDERSTACK tag is removed but no SVM exists."""
417
+ # Project no longer has SVM tag
418
+ mock_tags .return_value = ["tag1" , "tag2" ]
419
+
420
+ mock_netapp_manager = MagicMock ()
421
+ mock_netapp_manager .check_if_svm_exists .return_value = (
422
+ False # No SVM exists and tag removed
423
+ )
424
+ mock_netapp_class .return_value = mock_netapp_manager
425
+
426
+ result = handle_project_updated (
427
+ mock_conn , mock_nautobot , valid_update_event_data
428
+ )
429
+
430
+ assert result == 0
431
+ mock_tags .assert_called_once_with (mock_conn , "test-project-123" )
432
+ mock_netapp_manager .check_if_svm_exists .assert_called_once_with (
433
+ project_id = "test-project-123"
434
+ )
435
+ # Should not call cleanup_project when no SVM exists
436
+ mock_netapp_manager .cleanup_project .assert_not_called ()
437
+ # Should not create SVM or volume
438
+ mock_netapp_manager .create_svm .assert_not_called ()
439
+ mock_netapp_manager .create_volume .assert_not_called ()
440
+
402
441
@patch ("understack_workflows.oslo_event.keystone_project.NetAppManager" )
403
442
@patch ("understack_workflows.oslo_event.keystone_project._keystone_project_tags" )
404
443
@patch ("builtins.open" )
0 commit comments