Skip to content

Commit

Permalink
fix testing
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kovalsky committed Dec 12, 2024
1 parent 774d161 commit 6c38897
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/test_tom.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import sempy.fabric
from unittest.mock import patch
from sempy_labs.tom import connect_semantic_model
from sempy_labs._helper_functions import resolve_workspace_name_and_id


@patch("sempy.fabric.resolve_item_id")
@patch("sempy.fabric.resolve_workspace_id")
@patch("sempy_labs._helper_functions.resolve_dataset_name_and_id")
@patch("sempy_labs._helper_functions.resolve_workspace_name_and_id")
@patch("sempy.fabric.create_tom_server")
def test_tom_wrapper(create_tom_server):
def test_tom_wrapper(create_tom_server, resolve_workspace_name_and_id, resolve_dataset_name_and_id, resolve_workspace_id, resolve_item_id):

sempy.fabric._client._utils._init_analysis_services()
import Microsoft.AnalysisServices.Tabular as TOM

resolve_workspace_name_and_id.return_value = ("my_workspace", "my_workspace_id")
resolve_dataset_name_and_id.return_value = ("my_dataset", "my_dataset_id")
resolve_workspace_id.return_value = "my_workspace_id"
resolve_item_id.return_value = "my_dataset_id"

# create dummy server, database and model
tom_server = TOM.Server()

db = TOM.Database()
db.Name = "my_dataset"
db.ID = "my_dataset"
db.ID = "my_dataset_id"
db.Model = TOM.Model()
tom_server.Databases.Add(db)

create_tom_server.return_value = tom_server

resolve_workspace_name_and_id.return_value = ("my_workspace", "my_workspace_id")

# invoke the wrapper
with connect_semantic_model("my_dataset") as tom:
with connect_semantic_model(dataset="my_dataset_id", workspace="my_workspace") as tom:
tom.add_table("my_table")

# validate the result
assert tom_server.Databases["my_dataset"].Model.Tables["my_table"] is not None
assert tom_server.Databases["my_dataset_id"].Model.Tables["my_table"] is not None

0 comments on commit 6c38897

Please sign in to comment.