Skip to content

Commit

Permalink
♻️ Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
judynah committed Dec 4, 2024
1 parent 84027b2 commit d19e53f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 0 additions & 1 deletion src/viadot/orchestration/prefect/tasks/tm1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Task for downloading data from TM1 to a pandas DataFrame."""


from pandas import DataFrame
from prefect import task
from prefect.logging import get_run_logger
Expand Down
10 changes: 9 additions & 1 deletion tests/unit/test_tm1.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

data = {"a": [420, 380, 390], "b": [50, 40, 45]}


@pytest.fixture
def tm1_credentials():
return TM1Credentials(
Expand All @@ -19,6 +20,7 @@ def tm1_credentials():
port="12356",
)


@pytest.fixture
def tm1(tm1_credentials: TM1Credentials):
return TM1(
Expand Down Expand Up @@ -46,11 +48,11 @@ def tm1_mock(tm1_credentials: TM1Credentials, mocker):
"password": tm1_credentials.password,
"address": tm1_credentials.address,
"port": tm1_credentials.port,

},
verify=False,
)


def test_tm1_initialization(tm1_mock):
"""Test that the TM1 object is initialized with the correct credentials."""
assert tm1_mock.credentials.get("address") == "localhost"
Expand All @@ -60,34 +62,39 @@ def test_tm1_initialization(tm1_mock):
== "test_password" # pragma: allowlist secret
)


def test_get_cubes_names(tm1):
with patch("viadot.sources.tm1.TM1Service") as mock:
instance = mock.return_value
instance.cubes.get_all_names.return_value = ["msg", "cuve"]
result = tm1.get_cubes_names()
assert result == ["msg", "cuve"]


def test_get_views_names(tm1):
with patch("viadot.sources.tm1.TM1Service") as mock:
instance = mock.return_value
instance.views.get_all_names.return_value = ["view1", "view1"]
result = tm1.get_views_names()
assert result == ["view1", "view1"]


def test_get_dimensions_names(tm1):
with patch("viadot.sources.tm1.TM1Service") as mock:
instance = mock.return_value
instance.dimensions.get_all_names.return_value = ["dim1", "dim2"]
result = tm1.get_dimensions_names()
assert result == ["dim1", "dim2"]


def test_get_available_elements(tm1):
with patch("viadot.sources.tm1.TM1Service") as mock:
instance = mock.return_value
instance.elements.get_element_names.return_value = ["el1", "el2"]
result = tm1.get_available_elements()
assert result == ["el1", "el2"]


def test_to_df(tm1):
with patch("viadot.sources.tm1.TM1Service") as mock:
instance = mock.return_value
Expand All @@ -97,6 +104,7 @@ def test_to_df(tm1):
assert not result.empty
assert len(result.columns) == 4


def test_to_df_fail(tm1_mock):
with pytest.raises(ValidationError) as excinfo:
tm1_mock.to_df()
Expand Down

0 comments on commit d19e53f

Please sign in to comment.