22from datetime import timedelta
33
44import pytest
5- from databricks .sdk import AccountClient
5+ from databricks .sdk import AccountClient , WorkspaceClient
66from databricks .sdk .errors import NotFound
77from databricks .sdk .retries import retried
88from databricks .sdk .service .compute import DataSecurityMode , AwsAttributes
99from databricks .sdk .service .catalog import Privilege , SecurableType , TableInfo , TableType
1010from databricks .sdk .service .iam import PermissionLevel
11+
1112from databricks .labs .ucx .__about__ import __version__
1213
1314from databricks .labs .ucx .config import WorkspaceConfig
@@ -650,7 +651,9 @@ def test_mapping_reverts_table(ws, sql_backend, runtime_ctx, make_catalog):
650651
651652
652653# @retried(on=[NotFound], timeout=timedelta(minutes=3))
653- def test_migrate_managed_tables_with_acl (ws , sql_backend , runtime_ctx , make_catalog , make_user , env_or_skip ):
654+ def test_migrate_managed_tables_with_acl (
655+ ws : WorkspaceClient , sql_backend , runtime_ctx , make_catalog , make_user , env_or_skip
656+ ) -> None :
654657 src_schema = runtime_ctx .make_schema (catalog_name = "hive_metastore" )
655658 src_managed_table = runtime_ctx .make_table (catalog_name = src_schema .catalog_name , schema_name = src_schema .name )
656659 user = make_user ()
@@ -687,10 +690,11 @@ def test_migrate_managed_tables_with_acl(ws, sql_backend, runtime_ctx, make_cata
687690 assert len (target_tables ) == 1
688691
689692 target_table_properties = ws .tables .get (f"{ dst_schema .full_name } .{ src_managed_table .name } " ).properties
693+ assert target_table_properties
690694 assert target_table_properties ["upgraded_from" ] == src_managed_table .full_name
691695 assert target_table_properties [Table .UPGRADED_FROM_WS_PARAM ] == str (ws .get_workspace_id ())
692696
693- target_table_grants = ws .grants .get (SecurableType .TABLE , f"{ dst_schema .full_name } .{ src_managed_table .name } " )
697+ target_table_grants = ws .grants .get (SecurableType .TABLE . value , f"{ dst_schema .full_name } .{ src_managed_table .name } " )
694698 target_principals = [pa for pa in target_table_grants .privilege_assignments or [] if pa .principal == user .user_name ]
695699 assert len (target_principals ) == 1 , f"Missing grant for user { user .user_name } "
696700 assert target_principals [0 ].privileges == [Privilege .MODIFY , Privilege .SELECT ]
@@ -721,8 +725,8 @@ def test_migrate_managed_tables_with_acl(ws, sql_backend, runtime_ctx, make_cata
721725
722726@retried (on = [NotFound ], timeout = timedelta (minutes = 3 ))
723727def test_migrate_external_tables_with_principal_acl_azure (
724- ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , make_ucx_group
725- ):
728+ ws : WorkspaceClient , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , make_ucx_group
729+ ) -> None :
726730 if not ws .config .is_azure :
727731 pytest .skip ("only works in azure test env" )
728732 ctx , table_full_name , _ , _ = prepared_principal_acl
@@ -741,7 +745,8 @@ def test_migrate_external_tables_with_principal_acl_azure(
741745 )
742746 table_migrate .migrate_tables (what = What .EXTERNAL_SYNC )
743747
744- target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
748+ target_table_grants = ws .grants .get (SecurableType .TABLE .value , table_full_name )
749+ assert target_table_grants .privilege_assignments is not None
745750 match = False
746751 for _ in target_table_grants .privilege_assignments :
747752 if _ .principal == user_with_cluster_access .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
@@ -764,8 +769,8 @@ def test_migrate_external_tables_with_principal_acl_azure(
764769
765770@retried (on = [NotFound ], timeout = timedelta (minutes = 3 ))
766771def test_migrate_external_tables_with_principal_acl_aws (
767- ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , env_or_skip
768- ):
772+ ws : WorkspaceClient , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster , env_or_skip
773+ ) -> None :
769774 ctx , table_full_name , _ , _ = prepared_principal_acl
770775 ctx .with_dummy_resource_permission ()
771776 cluster = make_cluster (
@@ -782,7 +787,8 @@ def test_migrate_external_tables_with_principal_acl_aws(
782787 )
783788 table_migrate .migrate_tables (what = What .EXTERNAL_SYNC )
784789
785- target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
790+ target_table_grants = ws .grants .get (SecurableType .TABLE .value , table_full_name )
791+ assert target_table_grants .privilege_assignments is not None
786792 match = False
787793 for _ in target_table_grants .privilege_assignments :
788794 if _ .principal == user .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
@@ -793,8 +799,12 @@ def test_migrate_external_tables_with_principal_acl_aws(
793799
794800@retried (on = [NotFound ], timeout = timedelta (minutes = 3 ))
795801def test_migrate_external_tables_with_principal_acl_aws_warehouse (
796- ws , make_user , prepared_principal_acl , make_warehouse_permissions , make_warehouse , env_or_skip
797- ):
802+ ws : WorkspaceClient ,
803+ make_user ,
804+ prepared_principal_acl ,
805+ make_warehouse_permissions ,
806+ make_warehouse ,
807+ ) -> None :
798808 if not ws .config .is_aws :
799809 pytest .skip ("temporary: only works in aws test env" )
800810 ctx , table_full_name , _ , _ = prepared_principal_acl
@@ -809,7 +819,8 @@ def test_migrate_external_tables_with_principal_acl_aws_warehouse(
809819 )
810820 table_migrate .migrate_tables (what = What .EXTERNAL_SYNC )
811821
812- target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
822+ target_table_grants = ws .grants .get (SecurableType .TABLE .value , table_full_name )
823+ assert target_table_grants .privilege_assignments is not None
813824 match = False
814825 for _ in target_table_grants .privilege_assignments :
815826 if _ .principal == user .user_name and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
@@ -879,8 +890,8 @@ def test_migrate_table_in_mount(
879890
880891
881892def test_migrate_external_tables_with_spn_azure (
882- ws , make_user , prepared_principal_acl , make_cluster_permissions , make_cluster
883- ):
893+ ws : WorkspaceClient , prepared_principal_acl , make_cluster_permissions , make_cluster
894+ ) -> None :
884895 if not ws .config .is_azure :
885896 pytest .skip ("temporary: only works in azure test env" )
886897 ctx , table_full_name , _ , _ = prepared_principal_acl
@@ -897,7 +908,8 @@ def test_migrate_external_tables_with_spn_azure(
897908 )
898909 table_migrate .migrate_tables (what = What .EXTERNAL_SYNC )
899910
900- target_table_grants = ws .grants .get (SecurableType .TABLE , table_full_name )
911+ target_table_grants = ws .grants .get (SecurableType .TABLE .value , table_full_name )
912+ assert target_table_grants .privilege_assignments is not None
901913 match = False
902914 for _ in target_table_grants .privilege_assignments :
903915 if _ .principal == spn_with_mount_access and _ .privileges == [Privilege .ALL_PRIVILEGES ]:
0 commit comments