@@ -584,7 +584,13 @@ def test_create_uber_principal(ws):
584584 create_uber_principal (ws , prompts , subscription_id = "12" )
585585
586586
587- def test_migrate_locations_azure (ws ):
587+ def test_migrate_locations_raises_value_error_for_unsupported_cloud_provider (ws ) -> None :
588+ ctx = WorkspaceContext (ws ).replace (is_azure = False , is_aws = False )
589+ with pytest .raises (ValueError , match = "Unsupported cloud provider" ):
590+ migrate_locations (ws , ctx = ctx )
591+
592+
593+ def test_migrate_locations_azure (ws ) -> None :
588594 azurerm = create_autospec (AzureResources )
589595 ctx = WorkspaceContext (ws ).replace (
590596 is_azure = True ,
@@ -593,12 +599,41 @@ def test_migrate_locations_azure(ws):
593599 azure_subscription_id = 'test' ,
594600 azure_resources = azurerm ,
595601 )
602+
596603 migrate_locations (ws , ctx = ctx )
604+
597605 ws .external_locations .list .assert_called ()
598606 azurerm .storage_accounts .assert_called ()
599607
600608
601- def test_migrate_locations_aws (ws , caplog ):
609+ @pytest .mark .xfail (reason = "Currently not supported in unit tests see TODO" )
610+ def test_migrate_locations_azure_run_as_collection (workspace_clients , acc_client ) -> None :
611+ """Test migrate locations for a collection of workspaces
612+
613+ The "run as collection" test should run the same as the test `test_migrate_locations_azure`, but the assert should
614+ be called on **all** workspace clients.
615+ """
616+ for workspace_client in workspace_clients :
617+ # Setting the auth as follows as we (currently) do not support injecting multiple workspace contexts
618+ workspace_client .config .is_aws = False
619+ workspace_client .config .auth_type = "azure-cli"
620+
621+ # TODO: Migrate locations fails in unit testing as we currently not support injecting multiple workspace contexts
622+ # thus we cannot mock azure-cli login for multiple workspaces.
623+ # If we support this in the future, the `pytest.raises` can be removed and the test should pass
624+ with pytest .raises (OSError , match = ".*The provided request must include a 'scope' input parameter.*" ):
625+ migrate_locations (
626+ workspace_clients [0 ],
627+ run_as_collection = True ,
628+ a = acc_client ,
629+ subscription_id = "test" ,
630+ )
631+
632+ for workspace_client in workspace_clients :
633+ workspace_client .external_locations .list .assert_called ()
634+
635+
636+ def test_migrate_locations_aws (ws , caplog ) -> None :
602637 successful_return = """
603638 {
604639@@ -616,10 +651,38 @@ def successful_call(_):
616651 aws_profile = "profile" ,
617652 aws_cli_run_command = successful_call ,
618653 )
654+
619655 migrate_locations (ws , ctx = ctx )
656+
620657 ws .external_locations .list .assert_called ()
621658
622659
660+ @pytest .mark .xfail (reason = "Currently not supported in unit tests see TODO" )
661+ def test_migrate_locations_run_as_collection (workspace_clients , acc_client ) -> None :
662+ """Test migrate locations for a collection of workspaces
663+
664+ The "run as collection" test should run the same as the test `test_migrate_locations_aws`, but the assert should
665+ be called on **all** workspace clients.
666+ """
667+ for workspace_client in workspace_clients :
668+ # Setting the auth as follows as we (currently) do not support injecting multiple workspace contexts
669+ workspace_client .config .is_azure = False
670+
671+ # TODO: Migrate locations fails in unit testing as we currently not support injecting multiple workspace contexts
672+ # thus we cannot mock AWS login for multiple workspaces.
673+ # If we support this in the future, the `pytest.raises` can be removed and the test should pass
674+ with pytest .raises (AttributeError , match = "'NoneType' object has no attribute 'get'" ):
675+ migrate_locations (
676+ workspace_clients [0 ],
677+ run_as_collection = True ,
678+ a = acc_client ,
679+ aws_profile = "profile" ,
680+ )
681+
682+ for workspace_client in workspace_clients :
683+ workspace_client .external_locations .list .assert_called ()
684+
685+
623686def test_migrate_locations_gcp (ws ):
624687 ctx = WorkspaceContext (ws ).replace (is_aws = False , is_azure = False )
625688 with pytest .raises (ValueError ):
0 commit comments