-
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 #393 from dyvenia/dev
Release 0.4.3 PR
- Loading branch information
Showing
28 changed files
with
1,352 additions
and
111 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
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,23 @@ | ||
from viadot.flows import BigQueryToADLS | ||
from prefect.tasks.secrets import PrefectSecret | ||
|
||
|
||
def test_bigquery_to_adls(): | ||
credentials_secret = PrefectSecret( | ||
"AZURE_DEFAULT_ADLS_SERVICE_PRINCIPAL_SECRET" | ||
).run() | ||
|
||
flow_bigquery = BigQueryToADLS( | ||
name="BigQuery to ADLS", | ||
dataset_name="official_empty", | ||
table_name="space", | ||
credentials_key="BIGQUERY_TESTS", | ||
adls_dir_path="raw/tests", | ||
adls_sp_credentials_secret=credentials_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]) |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
import logging | ||
import pandas as pd | ||
from viadot.tasks import BigQueryToDF | ||
|
||
logger = logging.getLogger(__name__) | ||
DATASET_NAME = "official_empty" | ||
TABLE_NAME = "space" | ||
|
||
|
||
def test_bigquery_to_df_success(): | ||
bigquery_to_df_task = BigQueryToDF( | ||
dataset_name=DATASET_NAME, | ||
table_name=TABLE_NAME, | ||
date_column_name="date", | ||
credentials_key="BIGQUERY_TESTS", | ||
) | ||
df = bigquery_to_df_task.run() | ||
expectation_columns = ["date", "name", "count", "refresh"] | ||
|
||
assert isinstance(df, pd.DataFrame) | ||
assert expectation_columns == list(df.columns) | ||
|
||
|
||
def test_bigquery_to_df_wrong_table_name(caplog): | ||
bigquery_to_df_task = BigQueryToDF() | ||
with caplog.at_level(logging.WARNING): | ||
bigquery_to_df_task.run( | ||
dataset_name=DATASET_NAME, | ||
table_name="wrong_table_name", | ||
date_column_name="date", | ||
credentials_key="BIGQUERY_TESTS", | ||
) | ||
assert f"Returning empty data frame." in caplog.text | ||
|
||
|
||
def test_bigquery_to_df_wrong_column_name(caplog): | ||
bigquery_to_df_task = BigQueryToDF( | ||
dataset_name=DATASET_NAME, | ||
table_name=TABLE_NAME, | ||
date_column_name="wrong_column_name", | ||
credentials_key="BIGQUERY_TESTS", | ||
) | ||
with caplog.at_level(logging.WARNING): | ||
bigquery_to_df_task.run() | ||
assert f"'wrong_column_name' column is not recognized." in caplog.text |
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,27 @@ | ||
import pandas as pd | ||
import pytest | ||
from viadot.tasks import SalesforceUpsert | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def test_df(): | ||
data = { | ||
"Id": ["111"], | ||
"LastName": ["John Tester-External 3"], | ||
"SAPContactId__c": [111], | ||
} | ||
df = pd.DataFrame(data=data) | ||
yield df | ||
|
||
|
||
def test_salesforce_upsert(test_df): | ||
""" | ||
Id and SAPContactId__c are unique values, you can update only non-unique values for this test. | ||
If the combiantion of Id and SAPContactId__c do not exist, the test will fail. | ||
The Id and SAPContactId__c values '111' needs to be replaced with proper one (that exist in the testing system). | ||
""" | ||
try: | ||
sf = SalesforceUpsert() | ||
sf.run(test_df, table="Contact") | ||
except Exception as exception: | ||
assert False, exception |
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,48 @@ | ||
import pandas as pd | ||
from viadot.sources import BigQuery | ||
|
||
|
||
BIGQ = BigQuery(credentials_key="BIGQUERY_TESTS") | ||
|
||
|
||
def test_list_project(): | ||
project = BIGQ.get_project_id() | ||
assert project == "manifest-geode-341308" | ||
|
||
|
||
def test_list_datasets(): | ||
datasets = list(BIGQ.list_datasets()) | ||
assert datasets == ["manigeo", "official_empty"] | ||
|
||
|
||
def test_list_tables(): | ||
datasets = BIGQ.list_datasets() | ||
tables = list(BIGQ.list_tables(datasets[0])) | ||
assert tables == ["test_data", "manigeo_tab"] | ||
|
||
|
||
def test_query_is_df(): | ||
query = """ | ||
SELECT name, SUM(number) AS total | ||
FROM `bigquery-public-data.usa_names.usa_1910_2013` | ||
GROUP BY name, gender | ||
ORDER BY total DESC | ||
LIMIT 4 | ||
""" | ||
df = BIGQ.query_to_df(query) | ||
|
||
assert isinstance(df, pd.DataFrame) | ||
|
||
|
||
def test_query(): | ||
query = """ | ||
SELECT name, SUM(number) AS total | ||
FROM `bigquery-public-data.usa_names.usa_1910_2013` | ||
GROUP BY name, gender | ||
ORDER BY total DESC | ||
LIMIT 4 | ||
""" | ||
df = BIGQ.query_to_df(query) | ||
total_received = df["total"].values | ||
|
||
assert total_received == [4924235, 4818746, 4703680, 4280040] |
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,63 @@ | ||
import pandas as pd | ||
import pytest | ||
from viadot.sources import Salesforce | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def salesforce(): | ||
s = Salesforce() | ||
yield s | ||
|
||
|
||
@pytest.fixture(scope="session") | ||
def test_df_external(): | ||
data = { | ||
"Id": ["111"], | ||
"LastName": ["John Tester-External"], | ||
"SAPContactId__c": ["112"], | ||
} | ||
df = pd.DataFrame(data=data) | ||
yield df | ||
|
||
|
||
def test_upsert_empty(salesforce): | ||
try: | ||
df = pd.DataFrame() | ||
salesforce.upsert(df=df, table="Contact") | ||
except Exception as exception: | ||
assert False, exception | ||
|
||
|
||
def test_upsert_external_id_correct(salesforce, test_df_external): | ||
try: | ||
salesforce.upsert( | ||
df=test_df_external, table="Contact", external_id="SAPContactId__c" | ||
) | ||
except Exception as exception: | ||
assert False, exception | ||
result = salesforce.download(table="Contact") | ||
exists = list( | ||
filter(lambda contact: contact["LastName"] == "John Tester-External", result) | ||
) | ||
assert exists != None | ||
|
||
|
||
def test_upsert_external_id_wrong(salesforce, test_df_external): | ||
with pytest.raises(ValueError): | ||
salesforce.upsert(df=test_df_external, table="Contact", external_id="SAPId") | ||
|
||
|
||
def test_download_no_query(salesforce): | ||
ordered_dict = salesforce.download(table="Account") | ||
assert len(ordered_dict) > 0 | ||
|
||
|
||
def test_download_with_query(salesforce): | ||
query = "SELECT Id, Name FROM Account" | ||
ordered_dict = salesforce.download(query=query) | ||
assert len(ordered_dict) > 0 | ||
|
||
|
||
def test_to_df(salesforce): | ||
df = salesforce.to_df(table="Account") | ||
assert df.empty == False |
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.2" | ||
assert __version__ == "0.4.3" |
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 +1 @@ | ||
__version__ = "0.4.2" | ||
__version__ = "0.4.3" |
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 |
---|---|---|
|
@@ -8,3 +8,7 @@ class APIError(Exception): | |
|
||
class CredentialError(Exception): | ||
pass | ||
|
||
|
||
class DBDataAccessError(Exception): | ||
pass |
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.