forked from dyvenia/viadot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request dyvenia#731 from dyvenia/dev
Release 0.4.18 PR
- Loading branch information
Showing
32 changed files
with
2,221 additions
and
548 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import os | ||
from unittest import mock | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
from viadot.flows import SAPBWToADLS | ||
|
||
DATA = { | ||
"[0CALMONTH].[LEVEL01].[DESCRIPTION]": ["January 2023"], | ||
"date": ["2023-06-19 11:12:43+00:00"], | ||
} | ||
|
||
ADLS_FILE_NAME = "test_sap_bw_to_adls.parquet" | ||
ADLS_DIR_PATH = "raw/tests/" | ||
|
||
|
||
@mock.patch( | ||
"viadot.tasks.SAPBWToDF.run", | ||
return_value=pd.DataFrame(data=DATA), | ||
) | ||
@pytest.mark.run | ||
def test_sap_bw_to_adls_flow_run(mocked_class): | ||
flow = SAPBWToADLS( | ||
"test_sap_bw_to_adls_flow_run", | ||
sapbw_credentials_key="SAP", | ||
env="BW", | ||
mdx_query=""" | ||
SELECT | ||
{ | ||
} | ||
ON COLUMNS, | ||
NON EMPTY | ||
{ | ||
{ [0CALMONTH].[202301] } | ||
} | ||
DIMENSION PROPERTIES | ||
DESCRIPTION, | ||
MEMBER_NAME | ||
ON ROWS | ||
FROM ZCSALORD1/ZBW4_ZCSALORD1_006_BOA | ||
""", | ||
mapping_dict={"[0CALMONTH].[LEVEL01].[DESCRIPTION]": "Calendar Year/Month"}, | ||
overwrite_adls=True, | ||
adls_dir_path=ADLS_DIR_PATH, | ||
adls_file_name=ADLS_FILE_NAME, | ||
) | ||
result = flow.run() | ||
assert result.is_successful() | ||
os.remove("test_sap_bw_to_adls_flow_run.parquet") | ||
os.remove("test_sap_bw_to_adls_flow_run.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import os | ||
|
||
import pytest | ||
from prefect import Flow | ||
|
||
from viadot.flows import SQLServerToParquet | ||
from viadot.tasks import SQLServerToDF | ||
from viadot.tasks.sql_server import SQLServerQuery | ||
|
||
SCHEMA = "sandbox" | ||
TABLE = "test" | ||
PATH = "test.parquet" | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def create_table(): | ||
query_task = SQLServerQuery("AZURE_SQL") | ||
query_task.run(f"DROP TABLE IF EXISTS {SCHEMA}.{TABLE}") | ||
query_task.run(f"CREATE TABLE {SCHEMA}.{TABLE} (Id INT, Name VARCHAR (10))") | ||
yield True | ||
|
||
|
||
def test_sql_server_to_parquet_flow(create_table): | ||
flow = SQLServerToParquet( | ||
name="test_flow", | ||
sql_query=f"SELECT * FROM {SCHEMA}.{TABLE}", | ||
local_file_path=PATH, | ||
if_exists="fail", | ||
sqlserver_config_key="AZURE_SQL", | ||
timeout=3600, | ||
) | ||
flow.gen_flow() | ||
assert isinstance(flow, Flow) | ||
assert len(flow.tasks) == 3 # Number of tasks in the flow | ||
tasks = list(flow.tasks) | ||
|
||
assert isinstance(tasks[0], SQLServerToDF) | ||
flow.run() | ||
assert os.path.isfile(PATH) == True | ||
os.remove(PATH) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
from unittest import mock | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
from viadot.flows import VidClubToADLS | ||
|
||
DATA = {"col1": ["aaa", "bbb", "ccc"], "col2": [11, 22, 33]} | ||
ADLS_FILE_NAME = "test_vid_club.parquet" | ||
ADLS_DIR_PATH = "raw/test/" | ||
|
||
|
||
@mock.patch( | ||
"viadot.tasks.VidClubToDF.run", | ||
return_value=pd.DataFrame(data=DATA), | ||
) | ||
@pytest.mark.run | ||
def test_vidclub_to_adls_run_flow(mocked_class): | ||
flow = VidClubToADLS( | ||
"test_vidclub_to_adls_flow_run", | ||
source=["test"], | ||
from_date="2023-06-05", | ||
overwrite_adls=True, | ||
adls_dir_path=ADLS_DIR_PATH, | ||
adls_file_name=ADLS_FILE_NAME, | ||
) | ||
result = flow.run() | ||
assert result.is_successful() | ||
os.remove("test_vidclub_to_adls_flow_run.parquet") | ||
os.remove("test_vidclub_to_adls_flow_run.json") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.