Skip to content

Commit

Permalink
Added unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
pritishpai committed Feb 1, 2024
1 parent e6e0ece commit bc34447
Showing 1 changed file with 38 additions and 46 deletions.
84 changes: 38 additions & 46 deletions tests/unit/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from databricks.labs.ucx.framework.dashboards import DashboardFromFiles
from databricks.labs.ucx.framework.tasks import Task
from databricks.labs.ucx.install import WorkspaceInstaller
from databricks.labs.ucx.installer import InstallationManager

from ..unit.framework.mocks import MockBackend

Expand Down Expand Up @@ -100,6 +101,17 @@ def ws(mocker):
return ws


@pytest.fixture
def installation_mock(mocker):
installation_mock = mocker.patch("databricks.labs.ucx.installer.Installation.__init__")
installation_mock.as_summary.return_value = {
"user_name": lambda: iam.User(user_name="me@example.com", groups=[iam.ComplexValue(display="admins")]),
"database": "ucx_test",
"warehouse_id": "abc",}

return installation_mock


def mock_override_choice_from_dict(text: str, choices: dict[str, Any]) -> Any:
if "warehouse" in text:
return "abc"
Expand Down Expand Up @@ -1269,49 +1281,29 @@ def test_create_database_diff_error(ws, mocker, caplog):
assert "The UCX Installation Failed" in str(failure.value)


# TODO: fix the test
#
# def test_check_installation_conflicts(ws, mocker):
# # ws.users.list.return_value = [User(user_name="foo")]
#
# # config_bytes = yaml.dump(WorkspaceConfig(inventory_database="ucx_test").as_dict()).encode("utf8")
# config_bytes = b"""default_catalog: ucx_default
# instance_profile: arn:aws:iam::111222333:instance-profile/foo-instance-profile
# inventory_database: 'ucx_test'
# log_level: '42'
# num_threads: 42
# renamed_group_prefix: '42'
# spark_conf:
# spark.databricks.hive.metastore.glueCatalog.enabled: 'true'
# version: 0
# warehouse_id: abc
# workspace_start_path: /
# """
# ws.workspace.download = lambda _: io.BytesIO(config_bytes)
#
# #ws.workspace.download = io.StringIO("version: 0\ninventory_database: ucx_test\n debug_truncate_bytes: 250000\ndefault_catalog: ucx_default\ninventory_database: ucx_test\nlog_level: INFO\nnum_threads: 10\nrenamed_group_prefix: ucx-renamed-")
# # mocker.patch("databricks.labs.ucx.installer.InstallationManager.__init__", return_value=None)
# # installation_manager = InstallationManager(ws)
# # installation_manager.user_installations = [{"database": "ucx_test"}]
# # # installation_manager.user_installations = [{"database": "ucx_test"}]
#
#
# install = WorkspaceInstaller(
# ws,
# sql_backend=MockBackend(),
# promtps=MockPrompts(
# {
# r".*Inventory Database stored in hive_metastore.*": "ucx_test",
# r".*PRO or SERVERLESS SQL warehouse.*": "1",
# r".*just for a user": "yes",
# r".*Choose how to map the workspace groups.*": "0",
# r".*": "",
# }
# ),
# single_user_install=True
# )
# install._choice = lambda *_1, **_2: "abc (abc, PRO, RUNNING)"
# install._configure()
#
#
# assert True
def test_check_installation_conflicts(ws, installation_mock, mocker):

install = WorkspaceInstaller(
ws,
sql_backend=MockBackend(),
promtps=MockPrompts(
{
r".*Inventory Database stored in hive_metastore.*": "ucx_test",
r".*PRO or SERVERLESS SQL warehouse.*": "1",
r".*just for a user": "yes",
r".*Choose how to map the workspace groups.*": "0",
r".*": "",
}
),
single_user_install=True
)
mocker.patch("databricks.labs.ucx.installer.InstallationManager.user_installations", return_value=MagicMock())
installation_manager_mock = InstallationManager(ws)
installation_manager_mock.user_installations.return_value = [installation_mock]
assert install.check_installation_conflicts("ucx_test") is True

installation_manager_mock.user_installations.return_value = []
assert install.check_installation_conflicts("ucx_test") is False



0 comments on commit bc34447

Please sign in to comment.