Skip to content

Commit e8bed6d

Browse files
authored
Increased installation test coverage (#742)
* Corrected unit test setup as per PR [740](#740) * Fixed corrupted state warning
1 parent f86a7f5 commit e8bed6d

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

tests/unit/assessment/test_dashboard.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import io
2+
import json
23

34
import yaml
45
from databricks.sdk.service import iam
@@ -22,8 +23,39 @@ def test_dashboard(mocker):
2223
ws.current_user.me = lambda: iam.User(user_name="[email protected]", groups=[iam.ComplexValue(display="admins")])
2324
ws.config.host = "https://foo"
2425
ws.config.is_aws = True
25-
config_bytes = yaml.dump(WorkspaceConfig(inventory_database="a").as_dict()).encode("utf8")
26-
ws.workspace.download = lambda _: io.BytesIO(config_bytes)
26+
install_folder = "/users/not_a_real_user"
27+
queries_folder = f"{install_folder}/queries"
28+
29+
def download_mock(path):
30+
if path == f"{queries_folder}/state.json":
31+
return io.StringIO(
32+
json.dumps(
33+
{
34+
"jobs.sql:query_id": "91e51760-7653-4769-bc32-1595ce1892af",
35+
"all_tables.sql:query_id": "4000e54c-4c51-45b3-b009-a4dd9a3b5599",
36+
}
37+
)
38+
)
39+
40+
if path == f"{install_folder}/state.json":
41+
return io.StringIO(
42+
json.dumps(
43+
{
44+
"$version": 1,
45+
"resources": {
46+
"queries": {
47+
"jobs.sql": "91e51760-7653-4769-bc32-1595ce1892af",
48+
"all_tables.sql": "4000e54c-4c51-45b3-b009-a4dd9a3b5599",
49+
}
50+
},
51+
}
52+
)
53+
)
54+
55+
config_bytes = yaml.dump(WorkspaceConfig(inventory_database="a").as_dict()).encode("utf8")
56+
return io.BytesIO(config_bytes)
57+
58+
ws.workspace.download = download_mock
2759
ws.data_sources.list = lambda: [DataSource(id="bcd", warehouse_id="000000")]
2860
ws.dashboards.create.return_value = Dashboard(id="abc")
2961
ws.queries.create.return_value = Query(id="abc")
@@ -34,9 +66,9 @@ def test_dashboard(mocker):
3466
local_query_files = find_project_root() / "src/databricks/labs/ucx/queries"
3567
dash = DashboardFromFiles(
3668
ws,
37-
InstallState(ws, "/users/not_a_real_user"),
69+
InstallState(ws, install_folder),
3870
local_folder=local_query_files,
39-
remote_folder="/users/not_a_real_user/queries",
71+
remote_folder=queries_folder,
4072
name_prefix="Assessment",
4173
warehouse_id="000000",
4274
query_text_callback=installer.current_config.replace_inventory_variable,

0 commit comments

Comments
 (0)