Skip to content

Commit

Permalink
fixed unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Dec 17, 2024
1 parent 9fc658f commit d43e10f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/sempy_labs/lakehouse/_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def create_shortcut_onelake(

(source_workspace_name, source_workspace_id) = resolve_workspace_name_and_id(source_workspace)
source_lakehouse_id = resolve_lakehouse_id(source_lakehouse, source_workspace_id)
source_lakehouse_name = fabric.resolve_item_name(item_id=source_lakehouse_id, type='Lakehouse', workspace=destination_workspace_id)
source_lakehouse_name = fabric.resolve_item_name(item_id=source_lakehouse_id, type='Lakehouse', workspace=source_workspace_id)

if destination_workspace is None:
destination_workspace_name = source_workspace_name
Expand Down
11 changes: 6 additions & 5 deletions tests/test_shortcuts.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import pandas as pd
from json import loads
from sempy_labs.lakehouse._shortcuts import create_shortcut_onelake
from unittest.mock import MagicMock, PropertyMock, patch


@patch("sempy.fabric.resolve_item_name")
@patch("sempy.fabric.list_items")
@patch("sempy.fabric.resolve_workspace_id")
@patch("sempy.fabric.resolve_item_id")
@patch("sempy.fabric.FabricRestClient")
def test_create_shortcut_onelake(fabric_rest_client_mock, resolve_item_id_mock, resolve_workspace_id_mock, list_items_mock):
def test_create_shortcut_onelake(fabric_rest_client_mock, resolve_item_id_mock, resolve_workspace_id_mock, list_items_mock, resolve_item_name_mock):
# prepare mocks
def resolve_workspace_id_mock_side_effect(workspace_name):
if workspace_name == "source_workspace":
Expand All @@ -22,22 +22,23 @@ def resolve_workspace_id_mock_side_effect(workspace_name):
resolve_workspace_id_mock.side_effect = resolve_workspace_id_mock_side_effect

resolve_item_id_mock.return_value = "00000000-0000-0000-0000-00000000000A"
resolve_item_name_mock.return_value = "My item"

def list_items_side_effect(type, workspace):
assert type == "Lakehouse"

if workspace == "source_workspace":
return pd.DataFrame([{
"Display Name": "source_lakehouse",
"Display Name": "source_lakehouse_id",
"Id": "10000000-0000-0000-0000-000000000001"
}])

if workspace == "destination_workspace":
return pd.DataFrame([{
"Display Name": "destination_lakehouse",
"Display Name": "destination_lakehouse_id",
"Id": "20000000-0000-0000-0000-000000000002"
}])

assert False, f"Unexpected workspace: {workspace}"

list_items_mock.side_effect = list_items_side_effect
Expand Down

0 comments on commit d43e10f

Please sign in to comment.