-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ Added tests for outlook_to_adls flow
- Loading branch information
Showing
1 changed file
with
91 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import os | ||
from unittest import mock | ||
from datetime import date, timedelta | ||
from prefect.tasks.secrets import PrefectSecret | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
from viadot.flows import OutlookToADLS | ||
|
||
|
||
ADLS_FILE_NAME = "test_outlook_to_adls.parquet" | ||
ADLS_DIR_PATH = "raw/tests/" | ||
|
||
start_date = date.today() - timedelta(days=1) | ||
start_date = start_date.strftime("%Y-%m-%d") | ||
end_date = date.today().strftime("%Y-%m-%d") | ||
|
||
mailbox_list = [ | ||
"[email protected]", | ||
] | ||
|
||
DATA = { | ||
"sender": ["[email protected]"], | ||
"receivers": ["[email protected]"], | ||
} | ||
|
||
|
||
def test_outlook_to_adls_flow_run(): | ||
flow = OutlookToADLS( | ||
name="Test OutlookToADLS flow run", | ||
mailbox_list=mailbox_list, | ||
outbox_list=["Outbox", "Sent Items"], | ||
start_date=start_date, | ||
end_date=end_date, | ||
local_file_path=ADLS_FILE_NAME, | ||
adls_file_path=ADLS_DIR_PATH + ADLS_FILE_NAME, | ||
adls_sp_credentials_secret="App-Azure-CR-DatalakeGen2-AIA", | ||
if_exists="replace", | ||
timeout=4400, | ||
) | ||
|
||
result = flow.run() | ||
assert result.is_successful() | ||
|
||
|
||
def test_outlook_to_adls_run_flow_validate_fail(): | ||
flow = OutlookToADLS( | ||
name="Test OutlookToADLS validate flow df fail", | ||
mailbox_list=mailbox_list, | ||
outbox_list=["Outbox", "Sent Items"], | ||
start_date=start_date, | ||
end_date=end_date, | ||
local_file_path=ADLS_FILE_NAME, | ||
adls_file_path=ADLS_DIR_PATH + ADLS_FILE_NAME, | ||
adls_sp_credentials_secret="App-Azure-CR-DatalakeGen2-AIA", | ||
if_exists="replace", | ||
validation_df_dict={"column_list_to_match": ["test", "wrong", "columns"]}, | ||
timeout=4400, | ||
) | ||
|
||
result = flow.run() | ||
assert result.is_failed() | ||
|
||
|
||
@mock.patch( | ||
"viadot.tasks.OutlookToDF.run", | ||
return_value=pd.DataFrame(data=DATA), | ||
) | ||
@pytest.mark.run | ||
def test_outlook_to_adls_run_flow_validate_success(mocked_task): | ||
flow = OutlookToADLS( | ||
name="Test OutlookToADLS validate flow df success", | ||
mailbox_list=mailbox_list, | ||
outbox_list=["Outbox", "Sent Items"], | ||
start_date=start_date, | ||
end_date=end_date, | ||
local_file_path=ADLS_FILE_NAME, | ||
adls_file_path=ADLS_DIR_PATH + ADLS_FILE_NAME, | ||
adls_sp_credentials_secret="App-Azure-CR-DatalakeGen2-AIA", | ||
if_exists="replace", | ||
validation_df_dict={"column_list_to_match": ["sender", "receivers"]}, | ||
timeout=4400, | ||
) | ||
|
||
result = flow.run() | ||
assert result.is_successful() | ||
|
||
os.remove("test_outlook_to_adls.parquet") | ||
os.remove("romania_tehnic.csv") | ||
os.remove("o365_token.txt") |