|
11 | 11 | from databricks.labs.blueprint.tui import MockPrompts |
12 | 12 | from databricks.labs.blueprint.wheels import Wheels, find_project_root |
13 | 13 | from databricks.sdk.errors import ( |
| 14 | + BadRequest, |
14 | 15 | InvalidParameterValue, |
15 | 16 | NotFound, |
16 | 17 | OperationFailed, |
@@ -1200,3 +1201,51 @@ def test_repair_run_result_state(ws, caplog): |
1200 | 1201 | ws.jobs.list_runs.repair_run = None |
1201 | 1202 | install.repair_run("assessment") |
1202 | 1203 | assert "Please try after sometime" in caplog.text |
| 1204 | + |
| 1205 | + |
| 1206 | +def test_create_database(ws, mocker, caplog): |
| 1207 | + install = WorkspaceInstaller( |
| 1208 | + ws, |
| 1209 | + sql_backend=None, |
| 1210 | + promtps=MockPrompts( |
| 1211 | + { |
| 1212 | + r".*PRO or SERVERLESS SQL warehouse.*": "1", |
| 1213 | + r".*": "", |
| 1214 | + } |
| 1215 | + ), |
| 1216 | + ) |
| 1217 | + mocker.patch( |
| 1218 | + "databricks.labs.ucx.install.deploy_schema", |
| 1219 | + side_effect=BadRequest( |
| 1220 | + "[UNRESOLVED_COLUMN.WITH_SUGGESTION] A column, variable, or " |
| 1221 | + "function parameter with name `udf` cannot be resolved" |
| 1222 | + ), |
| 1223 | + ) |
| 1224 | + mocker.patch("databricks.labs.ucx.framework.crawlers.SqlBackend.execute", return_value=None) |
| 1225 | + config_bytes = yaml.dump(WorkspaceConfig(inventory_database="testdb", warehouse_id="123").as_dict()).encode("utf8") |
| 1226 | + ws.workspace.download = lambda _: io.BytesIO(config_bytes) |
| 1227 | + with pytest.raises(BadRequest) as failure: |
| 1228 | + install._create_database() |
| 1229 | + |
| 1230 | + assert "Kindly uninstall and reinstall UCX" in str(failure.value) |
| 1231 | + |
| 1232 | + |
| 1233 | +def test_create_database_diff_error(ws, mocker, caplog): |
| 1234 | + install = WorkspaceInstaller( |
| 1235 | + ws, |
| 1236 | + sql_backend=MockBackend(), |
| 1237 | + promtps=MockPrompts( |
| 1238 | + { |
| 1239 | + r".*PRO or SERVERLESS SQL warehouse.*": "1", |
| 1240 | + r".*": "", |
| 1241 | + } |
| 1242 | + ), |
| 1243 | + ) |
| 1244 | + mocker.patch("databricks.labs.ucx.install.deploy_schema", side_effect=BadRequest("Unknown Error")) |
| 1245 | + mocker.patch("databricks.labs.ucx.framework.crawlers.SqlBackend.execute", return_value=None) |
| 1246 | + config_bytes = yaml.dump(WorkspaceConfig(inventory_database="testdb", warehouse_id="123").as_dict()).encode("utf8") |
| 1247 | + ws.workspace.download = lambda _: io.BytesIO(config_bytes) |
| 1248 | + with pytest.raises(BadRequest) as failure: |
| 1249 | + install._create_database() |
| 1250 | + |
| 1251 | + assert "The UCX Installation Failed" in str(failure.value) |
0 commit comments