Skip to content

Commit

Permalink
Fixed Unit Test
Browse files Browse the repository at this point in the history
  • Loading branch information
FastLee committed Nov 9, 2023
1 parent b889d21 commit b5d5542
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/databricks/labs/ucx/workspace_access/tacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,10 @@ def inner(object_type: str, object_id: str, grant: Grant) -> Permissions:
grant = self._from_reduced(object_type, object_id, principal, ", ".join(sorted(actions)))
yield functools.partial(inner, object_type=object_type, object_id=object_id, grant=grant)

for (principal, (object_type, object_id)) in own_permissions:
for principal, (object_type, object_id) in own_permissions:
grant = self._from_reduced(object_type, object_id, principal, "OWN")
yield functools.partial(inner, object_type=object_type, object_id=object_id, grant=grant)


def _from_reduced(self, object_type: str, object_id: str, principal: str, action_type: str):
match object_type:
case "TABLE":
Expand Down Expand Up @@ -95,7 +94,7 @@ def get_apply_task(self, item: Permissions, migration_state: GroupMigrationState
# this is a grant for user, service principal, or irrelevant group
return None
target_grant = dataclasses.replace(grant, principal=target_principal)
if grant.action_type.upper() == 'OWN':
if grant.action_type.upper() == "OWN":
sql = target_grant.hive_chown_sql()
else:
sql = target_grant.hive_grant_sql()
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/workspace_access/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,7 @@ def test_set_owner_permission(
):
ws_group, _ = make_ucx_group()


logger.info(f"Testing setting ownership on table.")
logger.info("Testing setting ownership on table.")
dummy_table = make_table()
logger.info(f"Table name {dummy_table.full_name} group name {ws_group.display_name}")
sql_backend.execute(f"GRANT SELECT, MODIFY ON TABLE {dummy_table.full_name} TO `{ws_group.display_name}`")
Expand Down
17 changes: 16 additions & 1 deletion tests/unit/workspace_access/test_tacl.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_tacl_crawler_multiple_permissions():
assert "catalog_a.database_b.table_c" == permissions.object_id
assert Grant(
principal="foo@example.com",
action_type="MODIFY, OWN, SELECT",
action_type="MODIFY, SELECT",
catalog="catalog_a",
database="database_b",
table="table_c",
Expand Down Expand Up @@ -183,6 +183,21 @@ def test_tacl_crawler_multiple_permissions():
anonymous_function=True,
) == Grant(**json.loads(permissions.raw))

permissions = next(crawler_tasks)()

assert "TABLE" == permissions.object_type
assert "catalog_a.database_b.table_c" == permissions.object_id
assert Grant(
principal="foo@example.com",
action_type="OWN",
catalog="catalog_a",
database="database_b",
table="table_c",
view=None,
any_file=False,
anonymous_function=False,
) == Grant(**json.loads(permissions.raw))


def test_tacl_applier(mocker):
sql_backend = MockBackend()
Expand Down

0 comments on commit b5d5542

Please sign in to comment.