@@ -1562,8 +1562,9 @@ def test_command_table_structure(self):
15621562 registered_commands = []
15631563
15641564 class MockCommandGroup :
1565- def __init__ (self , name ):
1565+ def __init__ (self , name , ** kwargs ):
15661566 self .name = name
1567+ self .kwargs = kwargs
15671568
15681569 def __enter__ (self ):
15691570 return self
@@ -5065,42 +5066,36 @@ def test_start_migration_with_protected_item_id(self, mock_get_sub_id, mock_exec
50655066 # Verify
50665067 mock_execute .assert_called_once ()
50675068 call_args = mock_execute .call_args
5068- self .assertEqual (call_args [1 ]['protected_item_id' ], self .mock_protected_item_id )
5069- self .assertEqual (call_args [1 ]['resource_group_name' ], self .mock_rg_name )
5070- self .assertEqual (call_args [1 ]['vault_name' ], self .mock_vault_name )
5071- self .assertEqual (call_args [1 ]['protected_item_name' ], self .mock_protected_item_name )
5072- self .assertTrue (call_args [1 ]['turn_off_source_server' ])
5069+ # Check positional arguments
5070+ self .assertEqual (call_args [0 ][2 ], self .mock_protected_item_id ) # target_object_id
5071+ self .assertEqual (call_args [0 ][3 ], self .mock_rg_name ) # resource_group_name
5072+ self .assertEqual (call_args [0 ][4 ], self .mock_vault_name ) # vault_name
5073+ self .assertEqual (call_args [0 ][5 ], self .mock_protected_item_name ) # protected_item_name
5074+ self .assertTrue (call_args [0 ][6 ]) # turn_off_source_server
50735075 self .assertIsNotNone (result )
50745076
5075- @mock .patch ('azext_migrate.helpers.migration.start._parse.get_vault_name_from_project' )
50765077 @mock .patch ('azext_migrate.helpers.migration.start._execute_migrate.execute_migration' )
50775078 @mock .patch ('azure.cli.core.commands.client_factory.get_subscription_id' )
50785079 def test_start_migration_with_protected_item_name (self , mock_get_sub_id ,
5079- mock_execute , mock_get_vault ):
5080- """Test starting migration using protected item name"""
5080+ mock_execute ):
5081+ """Test that function requires protected_item_id ( name parameter removed) """
50815082 from azext_migrate .custom import start_local_server_migration
50825083
50835084 # Setup mocks
50845085 mock_get_sub_id .return_value = self .mock_subscription_id
5085- mock_get_vault .return_value = self .mock_vault_name
50865086 mock_execute .return_value = self ._create_job_response ()
50875087 mock_cmd = self ._create_mock_cmd ()
50885088
5089- # Execute command
5090- result = start_local_server_migration (
5091- cmd = mock_cmd ,
5092- protected_item_name = self .mock_protected_item_name ,
5093- resource_group = self .mock_rg_name ,
5094- project_name = self .mock_project_name ,
5095- turn_off_source_server = False
5096- )
5089+ # Execute command without protected_item_id should fail
5090+ with self .assertRaises (CLIError ) as context :
5091+ start_local_server_migration (
5092+ cmd = mock_cmd ,
5093+ turn_off_source_server = False
5094+ )
50975095
5098- # Verify
5099- mock_get_vault .assert_called_once_with (
5100- mock_cmd , self .mock_rg_name , self .mock_project_name , self .mock_subscription_id
5101- )
5102- mock_execute .assert_called_once ()
5103- self .assertIsNotNone (result )
5096+ # Verify error message
5097+ self .assertIn ("--protected-item-id parameter must be provided" ,
5098+ str (context .exception ))
51045099
51055100 @mock .patch ('azure.cli.core.commands.client_factory.get_subscription_id' )
51065101 def test_start_migration_missing_parameters (self , mock_get_sub_id ):
@@ -5114,25 +5109,24 @@ def test_start_migration_missing_parameters(self, mock_get_sub_id):
51145109 with self .assertRaises (CLIError ) as context :
51155110 start_local_server_migration (cmd = mock_cmd )
51165111
5117- self .assertIn ("Either --protected-item-id or --protected-item-name " ,
5112+ self .assertIn ("--protected-item-id parameter must be provided " ,
51185113 str (context .exception ))
51195114
51205115 @mock .patch ('azure.cli.core.commands.client_factory.get_subscription_id' )
51215116 def test_start_migration_name_without_resource_group (self , mock_get_sub_id ):
5122- """Test that command fails when using name without resource group """
5117+ """Test that command requires protected_item_id """
51235118 from azext_migrate .custom import start_local_server_migration
51245119
51255120 mock_get_sub_id .return_value = self .mock_subscription_id
51265121 mock_cmd = self ._create_mock_cmd ()
51275122
5128- # Execute command with name but without resource group
5123+ # Execute command without protected_item_id
51295124 with self .assertRaises (CLIError ) as context :
51305125 start_local_server_migration (
5131- cmd = mock_cmd ,
5132- protected_item_name = self .mock_protected_item_name
5126+ cmd = mock_cmd
51335127 )
51345128
5135- self .assertIn ("both --resource-group and --project-name are required " ,
5129+ self .assertIn ("--protected-item-id parameter must be provided " ,
51365130 str (context .exception ))
51375131
51385132 @mock .patch ('azext_migrate.helpers._utils.get_resource_by_id' )
@@ -5617,46 +5611,27 @@ def test_validate_arc_resource_bridge_not_found_warning(self, mock_send_request)
56175611
56185612 # Should complete without exception
56195613
5620- @mock .patch ('azext_migrate.helpers._utils.send_get_request ' )
5621- def test_get_vault_name_from_project_success (self , mock_send_get ):
5614+ @mock .patch ('azext_migrate.helpers._utils.get_resource_by_id ' )
5615+ def test_get_vault_name_from_project_success (self , mock_get_resource ):
56225616 """Test successfully retrieving vault name from project"""
5623- from azext_migrate .helpers .migration . start ._parse import (
5617+ from azext_migrate .helpers .replication . job ._parse import (
56245618 get_vault_name_from_project
56255619 )
56265620
56275621 mock_cmd = self ._create_mock_cmd ()
56285622
5629- # Mock project response
5630- mock_project_response = mock .Mock ()
5631- mock_project_response .json .return_value = {
5632- 'id' : f'/subscriptions/{ self .mock_subscription_id } /resourceGroups/{ self .mock_rg_name } /providers/Microsoft.Migrate/migrateProjects/{ self .mock_project_name } ' ,
5633- 'name' : self .mock_project_name
5634- }
5635-
5636- # Mock solutions response
5637- mock_solutions_response = mock .Mock ()
5638- mock_solutions_response .json .return_value = {
5639- 'value' : [
5640- {
5641- 'properties' : {
5642- 'tool' : 'ServerDiscovery' ,
5643- 'details' : {}
5644- }
5645- },
5646- {
5647- 'properties' : {
5648- 'tool' : 'ServerMigration_DataReplication' ,
5649- 'details' : {
5650- 'extendedDetails' : {
5651- 'vaultName' : self .mock_vault_name
5652- }
5653- }
5623+ # Mock solution response with vault ID
5624+ mock_get_resource .return_value = {
5625+ 'id' : f'/subscriptions/{ self .mock_subscription_id } /resourceGroups/{ self .mock_rg_name } /providers/Microsoft.Migrate/migrateProjects/{ self .mock_project_name } /solutions/Servers-Migration-ServerMigration_DataReplication' ,
5626+ 'name' : 'Servers-Migration-ServerMigration_DataReplication' ,
5627+ 'properties' : {
5628+ 'details' : {
5629+ 'extendedDetails' : {
5630+ 'vaultId' : f'/subscriptions/{ self .mock_subscription_id } /resourceGroups/{ self .mock_rg_name } /providers/Microsoft.DataReplication/replicationVaults/{ self .mock_vault_name } '
56545631 }
56555632 }
5656- ]
5633+ }
56575634 }
5658-
5659- mock_send_get .side_effect = [mock_project_response , mock_solutions_response ]
56605635
56615636 # Execute
56625637 result = get_vault_name_from_project (
@@ -5668,38 +5643,27 @@ def test_get_vault_name_from_project_success(self, mock_send_get):
56685643
56695644 # Verify
56705645 self .assertEqual (result , self .mock_vault_name )
5671- self . assertEqual ( mock_send_get . call_count , 2 )
5646+ mock_get_resource . assert_called_once ( )
56725647
5673- @mock .patch ('azext_migrate.helpers._utils.send_get_request ' )
5674- def test_get_vault_name_from_project_no_vault (self , mock_send_get ):
5648+ @mock .patch ('azext_migrate.helpers._utils.get_resource_by_id ' )
5649+ def test_get_vault_name_from_project_no_vault (self , mock_get_resource ):
56755650 """Test error when no vault found in project"""
5676- from azext_migrate .helpers .migration . start ._parse import (
5651+ from azext_migrate .helpers .replication . job ._parse import (
56775652 get_vault_name_from_project
56785653 )
56795654
56805655 mock_cmd = self ._create_mock_cmd ()
56815656
5682- # Mock project response
5683- mock_project_response = mock .Mock ()
5684- mock_project_response .json .return_value = {
5685- 'id' : f'/subscriptions/{ self .mock_subscription_id } /resourceGroups/{ self .mock_rg_name } /providers/Microsoft.Migrate/migrateProjects/{ self .mock_project_name } ' ,
5686- 'name' : self .mock_project_name
5687- }
5688-
5689- # Mock solutions response without replication solution
5690- mock_solutions_response = mock .Mock ()
5691- mock_solutions_response .json .return_value = {
5692- 'value' : [
5693- {
5694- 'properties' : {
5695- 'tool' : 'ServerDiscovery' ,
5696- 'details' : {}
5697- }
5657+ # Mock solution response without vault ID
5658+ mock_get_resource .return_value = {
5659+ 'id' : f'/subscriptions/{ self .mock_subscription_id } /resourceGroups/{ self .mock_rg_name } /providers/Microsoft.Migrate/migrateProjects/{ self .mock_project_name } /solutions/Servers-Migration-ServerMigration_DataReplication' ,
5660+ 'name' : 'Servers-Migration-ServerMigration_DataReplication' ,
5661+ 'properties' : {
5662+ 'details' : {
5663+ 'extendedDetails' : {}
56985664 }
5699- ]
5665+ }
57005666 }
5701-
5702- mock_send_get .side_effect = [mock_project_response , mock_solutions_response ]
57035667
57045668 # Execute
57055669 with self .assertRaises (CLIError ) as context :
@@ -5710,7 +5674,7 @@ def test_get_vault_name_from_project_no_vault(self, mock_send_get):
57105674 self .mock_subscription_id
57115675 )
57125676
5713- self .assertIn ("No replication vault found" , str (context .exception ))
5677+ self .assertIn ("Vault ID not found" , str (context .exception ))
57145678
57155679
57165680if __name__ == '__main__' :
0 commit comments