-
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.
Merge pull request #439 from dyvenia/dev
Release 0.4.5 PR
- Loading branch information
Showing
26 changed files
with
831 additions
and
57 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 |
---|---|---|
@@ -1,23 +1,76 @@ | ||
from viadot.flows import BigQueryToADLS | ||
from viadot.tasks import AzureDataLakeRemove | ||
from prefect.tasks.secrets import PrefectSecret | ||
import pendulum | ||
import os | ||
|
||
ADLS_DIR_PATH = "raw/tests/" | ||
ADLS_FILE_NAME = str(pendulum.now("utc")) + ".parquet" | ||
BIGQ_CREDENTIAL_KEY = "BIGQUERY_TESTS" | ||
ADLS_CREDENTIAL_SECRET = PrefectSecret( | ||
"AZURE_DEFAULT_ADLS_SERVICE_PRINCIPAL_SECRET" | ||
).run() | ||
|
||
|
||
def test_bigquery_to_adls(): | ||
credentials_secret = PrefectSecret( | ||
"AZURE_DEFAULT_ADLS_SERVICE_PRINCIPAL_SECRET" | ||
).run() | ||
flow_bigquery = BigQueryToADLS( | ||
name="Test BigQuery to ADLS extract", | ||
dataset_name="official_empty", | ||
table_name="space", | ||
adls_file_name=ADLS_FILE_NAME, | ||
credentials_key=BIGQ_CREDENTIAL_KEY, | ||
adls_dir_path=ADLS_DIR_PATH, | ||
adls_sp_credentials_secret=ADLS_CREDENTIAL_SECRET, | ||
) | ||
|
||
result = flow_bigquery.run() | ||
assert result.is_successful() | ||
|
||
task_results = result.result.values() | ||
assert all([task_result.is_successful() for task_result in task_results]) | ||
|
||
os.remove("test_bigquery_to_adls_extract.parquet") | ||
os.remove("test_bigquery_to_adls_extract.json") | ||
|
||
|
||
def test_bigquery_to_adls_overwrite_true(): | ||
flow_bigquery = BigQueryToADLS( | ||
name="BigQuery to ADLS", | ||
name="Test BigQuery to ADLS overwrite true", | ||
dataset_name="official_empty", | ||
table_name="space", | ||
credentials_key="BIGQUERY_TESTS", | ||
adls_dir_path="raw/tests", | ||
adls_sp_credentials_secret=credentials_secret, | ||
credentials_key=BIGQ_CREDENTIAL_KEY, | ||
adls_file_name=ADLS_FILE_NAME, | ||
overwrite_adls=True, | ||
adls_dir_path=ADLS_DIR_PATH, | ||
adls_sp_credentials_secret=ADLS_CREDENTIAL_SECRET, | ||
) | ||
|
||
result = flow_bigquery.run() | ||
assert result.is_successful() | ||
|
||
task_results = result.result.values() | ||
assert all([task_result.is_successful() for task_result in task_results]) | ||
os.remove("test_bigquery_to_adls_overwrite_true.parquet") | ||
os.remove("test_bigquery_to_adls_overwrite_true.json") | ||
|
||
|
||
def test_bigquery_to_adls_false(): | ||
flow_bigquery = BigQueryToADLS( | ||
name="Test BigQuery to ADLS overwrite false", | ||
dataset_name="official_empty", | ||
table_name="space", | ||
adls_file_name=ADLS_FILE_NAME, | ||
overwrite_adls=False, | ||
credentials_key=BIGQ_CREDENTIAL_KEY, | ||
adls_dir_path=ADLS_DIR_PATH, | ||
adls_sp_credentials_secret=ADLS_CREDENTIAL_SECRET, | ||
) | ||
|
||
result = flow_bigquery.run() | ||
assert result.is_failed() | ||
os.remove("test_bigquery_to_adls_overwrite_false.parquet") | ||
os.remove("test_bigquery_to_adls_overwrite_false.json") | ||
rm = AzureDataLakeRemove( | ||
path=ADLS_DIR_PATH + ADLS_FILE_NAME, vault_name="azuwevelcrkeyv001s" | ||
) | ||
rm.run(sp_credentials_secret=ADLS_CREDENTIAL_SECRET) |
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,33 @@ | ||
from viadot.flows import SalesforceToADLS | ||
from viadot.tasks import AzureDataLakeRemove | ||
from prefect.tasks.secrets import PrefectSecret | ||
import os | ||
|
||
ADLS_FILE_NAME = "test_salesforce.parquet" | ||
ADLS_DIR_PATH = "raw/tests/" | ||
|
||
|
||
def test_salesforce_to_adls(): | ||
|
||
credentials_secret = PrefectSecret( | ||
"AZURE_DEFAULT_ADLS_SERVICE_PRINCIPAL_SECRET" | ||
).run() | ||
|
||
flow = SalesforceToADLS( | ||
"test_salesforce_to_adls_run_flow", | ||
query="SELECT IsDeleted, FiscalYear FROM Opportunity LIMIT 50", | ||
adls_sp_credentials_secret=credentials_secret, | ||
adls_dir_path=ADLS_DIR_PATH, | ||
adls_file_name=ADLS_FILE_NAME, | ||
) | ||
|
||
result = flow.run() | ||
assert result.is_successful() | ||
|
||
os.remove("test_salesforce_to_adls_run_flow.parquet") | ||
os.remove("test_salesforce_to_adls_run_flow.json") | ||
rm = AzureDataLakeRemove( | ||
path=ADLS_DIR_PATH + ADLS_FILE_NAME, | ||
vault_name="azuwevelcrkeyv001s", | ||
) | ||
rm.run(sp_credentials_secret=credentials_secret) |
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
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
def test_version(): | ||
assert __version__ == "0.4.4" | ||
assert __version__ == "0.4.5" |
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,36 @@ | ||
import os | ||
import pytest | ||
|
||
from viadot.tasks import DuckDBCreateTableFromParquet | ||
from viadot.sources.duckdb import DuckDB | ||
|
||
TABLE = "test_table" | ||
SCHEMA = "test_schema" | ||
DATABASE_PATH = "test_db_123.duckdb" | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def duckdb(): | ||
duckdb = DuckDB(credentials=dict(database=DATABASE_PATH)) | ||
yield duckdb | ||
|
||
|
||
def test_create_table_empty_file(duckdb): | ||
path = "empty.parquet" | ||
with open(path, "w"): | ||
pass | ||
duckdb_creds = {f"database": DATABASE_PATH} | ||
task = DuckDBCreateTableFromParquet(credentials=duckdb_creds) | ||
task.run(schema=SCHEMA, table=TABLE, path=path, if_empty="skip") | ||
|
||
assert duckdb._check_if_table_exists(TABLE, schema=SCHEMA) == False | ||
os.remove(path) | ||
|
||
|
||
def test_create_table(duckdb, TEST_PARQUET_FILE_PATH): | ||
duckdb_creds = {f"database": DATABASE_PATH} | ||
task = DuckDBCreateTableFromParquet(credentials=duckdb_creds) | ||
task.run(schema=SCHEMA, table=TABLE, path=TEST_PARQUET_FILE_PATH, if_empty="skip") | ||
|
||
assert duckdb._check_if_table_exists(TABLE, schema=SCHEMA) | ||
os.remove(DATABASE_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
Oops, something went wrong.