|
| 1 | +import json |
1 | 2 | from unittest.mock import MagicMock |
2 | 3 |
|
3 | 4 | import pytest |
4 | 5 | from _pytest.outcomes import fail |
5 | 6 | from databricks.labs.blueprint.parallel import ManyError |
6 | 7 | from databricks.labs.blueprint.tui import MockPrompts |
7 | | -from databricks.sdk.errors import DatabricksError |
| 8 | +from databricks.sdk.errors import DatabricksError, ResourceDoesNotExist |
8 | 9 | from databricks.sdk.service import iam |
9 | 10 | from databricks.sdk.service.iam import ComplexValue, Group, ResourceMeta |
10 | 11 |
|
@@ -380,6 +381,32 @@ def do_side_effect(*args, **kwargs): |
380 | 381 | gm.reflect_account_groups_on_workspace() |
381 | 382 |
|
382 | 383 |
|
| 384 | +def test_reflect_account_should_not_fail_if_group_not_in_the_account_anymore(): |
| 385 | + backend = MockBackend(rows={"SELECT": [("1", "de", "de", "test-group-de", "", "", "", "")]}) |
| 386 | + wsclient = MagicMock() |
| 387 | + account_group1 = Group(id="11", display_name="de") |
| 388 | + |
| 389 | + def reflect_account_side_effect(method, *args, **kwargs): |
| 390 | + if method == "GET": |
| 391 | + return { |
| 392 | + "Resources": [g.as_dict() for g in [account_group1]], |
| 393 | + } |
| 394 | + if method == "PUT": |
| 395 | + raise ResourceDoesNotExist( |
| 396 | + "The group has been removed from the Databricks account after getting the group " |
| 397 | + "and before reflecting it to the workspace." |
| 398 | + ) |
| 399 | + |
| 400 | + wsclient.api_client.do.side_effect = reflect_account_side_effect |
| 401 | + GroupManager(backend, wsclient, inventory_database="inv").reflect_account_groups_on_workspace() |
| 402 | + |
| 403 | + wsclient.api_client.do.assert_called_with( |
| 404 | + "PUT", |
| 405 | + f"/api/2.0/preview/permissionassignments/principals/{account_group1.id}", |
| 406 | + data=json.dumps({"permissions": ["USER"]}), |
| 407 | + ) |
| 408 | + |
| 409 | + |
383 | 410 | def test_delete_original_workspace_groups_should_delete_relected_acc_groups_in_workspace(): |
384 | 411 | account_id = "11" |
385 | 412 | ws_id = "1" |
|
0 commit comments