|
1 | 1 | import io |
2 | | -from unittest.mock import MagicMock |
| 2 | +from unittest.mock import MagicMock, create_autospec |
3 | 3 |
|
4 | 4 | import pytest |
| 5 | +from databricks.labs.blueprint.installer import IllegalState |
5 | 6 | from databricks.labs.blueprint.parallel import ManyError |
| 7 | +from databricks.sdk import WorkspaceClient |
6 | 8 | from databricks.sdk.errors import NotFound |
7 | 9 | from databricks.sdk.service.iam import ComplexValue, User |
8 | 10 | from databricks.sdk.service.jobs import ( |
@@ -63,6 +65,26 @@ def test_corrupt_config(mocker): |
63 | 65 | assert len(user_installations) == 0 |
64 | 66 |
|
65 | 67 |
|
| 68 | +def test_for_user_corrupt_config_yaml(mocker): |
| 69 | + ws = create_autospec(WorkspaceClient) |
| 70 | + user = User(user_name="foo") |
| 71 | + ws.users.list.return_value = [user] |
| 72 | + ws.workspace.download.return_value = io.StringIO("version: 2\ntacl: extra colon: test") |
| 73 | + installation_manager = InstallationManager(ws) |
| 74 | + with pytest.raises(IllegalState): |
| 75 | + installation_manager.for_user(user) |
| 76 | + |
| 77 | + |
| 78 | +def test_user_installations_corrupt_config_yaml(mocker): |
| 79 | + ws = create_autospec(WorkspaceClient) |
| 80 | + user = User(user_name="foo") |
| 81 | + ws.users.list.return_value = [user] |
| 82 | + ws.workspace.download.return_value = io.StringIO("version: 2\ntacl: extra colon: test") |
| 83 | + installation_manager = InstallationManager(ws) |
| 84 | + user_installations = installation_manager.user_installations() |
| 85 | + assert len(user_installations) == 0 |
| 86 | + |
| 87 | + |
66 | 88 | def test_validate_assessment(mocker): |
67 | 89 | ws = mocker.patch("databricks.sdk.WorkspaceClient.__init__") |
68 | 90 | current_user = MagicMock() |
|
0 commit comments