Skip to content

Commit

Permalink
🎨 Code Formating changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mgardzinski committed Sep 26, 2024
1 parent e26f832 commit 4d2fc50
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/viadot/orchestration/prefect/flows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .transform import transform
from .transform_and_catalog import transform_and_catalog


__all__ = [
"cloud_for_customers_to_adls",
"cloud_for_customers_to_databricks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
retry_delay_seconds=60,
task_runner=ConcurrentTaskRunner,
)
def salesforce_to_adls(
def salesforce_to_adls( # noqa: PLR0913
config_key: str | None = None,
azure_key_vault_secret: str | None = None,
env: str | None = None,
Expand Down
1 change: 1 addition & 0 deletions src/viadot/orchestration/prefect/tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from .sharepoint import sharepoint_download_file, sharepoint_to_df
from .sql_server import create_sql_server_table, sql_server_query, sql_server_to_df


__all__ = [
"adls_upload",
"df_to_adls",
Expand Down
1 change: 1 addition & 0 deletions src/viadot/sources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .sql_server import SQLServer
from .uk_carbon_intensity import UKCarbonIntensity


__all__ = [
"CloudForCustomers",
"Epicor",
Expand Down
2 changes: 1 addition & 1 deletion src/viadot/sources/salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def api_connection(
"""
if not query:
columns_str = ", ".join(columns) if columns else "FIELDS(STANDARD)"
query = f"SELECT {columns_str} FROM {table}"
query = f"SELECT {columns_str} FROM {table}" # noqa: S608

self.data = self.salesforce.query(query).get("records")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from viadot.orchestration.prefect.flows import salesforce_to_adls


def test_salesforce_to_adls(azure_key_vault_secret, adls_path, adls_azure_key_vault_secret):
def test_salesforce_to_adls(
azure_key_vault_secret, adls_path, adls_azure_key_vault_secret
):
"""Test Salesforce prefect flow."""
state = salesforce_to_adls(
azure_key_vault_secret=azure_key_vault_secret,
Expand Down
60 changes: 39 additions & 21 deletions tests/unit/test_salesforce.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
from viadot.sources import Salesforce
from viadot.sources.salesforce import SalesforceCredentials


variables = {
"credentials": {
"username": "test_user",
"password": "test_password",
"password": "test_password", # pragma: allowlist secret
"token": "test_token",
},
"records_1": [
Expand Down Expand Up @@ -40,11 +41,13 @@
}


@pytest.mark.basic()
@pytest.mark.basic
def test_salesforce_init_dev_env(mocker):
"""Test Salesforce, starting in dev mode."""
mock_sf_instance = mocker.MagicMock(spec=SimpleSalesforce)
mocker.patch("viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance)
mocker.patch(
"viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance
)
sf_instance = Salesforce(credentials=variables["credentials"], env="DEV")

assert sf_instance.salesforce == mock_sf_instance
Expand All @@ -53,27 +56,29 @@ def test_salesforce_init_dev_env(mocker):
class TestSalesforceCredentials:
"""Test Salesforce Credentials Class."""

@pytest.mark.basic()
@pytest.mark.basic
def test_salesforce_credentials(self):
"""Test Salesforce credentials."""
SalesforceCredentials(
username="test_user",
password="test_password",
token="test_token",
password="test_password", # noqa: S106 # pragma: allowlist secret
token="test_token", # noqa: S106
)


@pytest.mark.basic()
@pytest.mark.basic
def test_salesforce_init_prod_env(mocker):
"""Test Salesforce, starting in prod mode."""
mock_sf_instance = mocker.MagicMock(spec=SimpleSalesforce)
mocker.patch("viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance)
mocker.patch(
"viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance
)
sf_instance = Salesforce(credentials=variables["credentials"], env="PROD")

assert sf_instance.salesforce == mock_sf_instance


@pytest.mark.basic()
@pytest.mark.basic
def test_salesforce_invalid_env():
"""Test Salesforce, invalid `env` parameter."""
with pytest.raises(
Expand All @@ -82,19 +87,24 @@ def test_salesforce_invalid_env():
Salesforce(credentials=variables["credentials"], env="INVALID")


@pytest.mark.basic()
@pytest.mark.basic
def test_salesforce_missing_credentials():
"""Test Salesforce missing credentials."""
incomplete_creds = {"username": "user", "password": "pass"}
incomplete_creds = {
"username": "user", # pragma: allowlist secret
"password": "pass", # pragma: allowlist secret
}
with pytest.raises(CredentialError):
Salesforce(credentials=incomplete_creds)


@pytest.mark.connect()
@pytest.mark.connect
def test_salesforce_api_connection(mocker):
"""Test Salesforce `api_connection` method with a query."""
mock_sf_instance = mocker.MagicMock(spec=SimpleSalesforce)
mocker.patch("viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance)
mocker.patch(
"viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance
)
salesforce_instance = Salesforce(credentials=variables["credentials"])

mock_sf_instance.query.return_value = {"records": variables["records_1"]}
Expand All @@ -105,11 +115,13 @@ def test_salesforce_api_connection(mocker):
mock_sf_instance.query.assert_called_once_with("SELECT Id, Name FROM Account")


@pytest.mark.connect()
@pytest.mark.connect
def test_salesforce_api_connection_with_columns(mocker):
"""Test Salesforce `api_connection` method with columns."""
mock_sf_instance = mocker.MagicMock(spec=SimpleSalesforce)
mocker.patch("viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance)
mocker.patch(
"viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance
)
salesforce_instance = Salesforce(credentials=variables["credentials"])

mock_sf_instance.query.return_value = {"records": variables["records_2"]}
Expand All @@ -120,11 +132,13 @@ def test_salesforce_api_connection_with_columns(mocker):
mock_sf_instance.query.assert_called_once_with("SELECT Id, Name FROM Account")


@pytest.mark.functions()
@pytest.mark.functions
def test_salesforce_to_df(mocker):
"""Test Salesforce `to_df` method."""
mock_sf_instance = mocker.MagicMock(spec=SimpleSalesforce)
mocker.patch("viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance)
mocker.patch(
"viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance
)
salesforce_instance = Salesforce(credentials=variables["credentials"])
salesforce_instance.data = variables["data"]

Expand All @@ -141,23 +155,27 @@ def test_salesforce_to_df(mocker):
assert df.iloc[0]["Id"] == "001"


@pytest.mark.functions()
@pytest.mark.functions
def test_salesforce_to_df_empty_data(mocker):
"""Test Salesforce `to_df` method with empty df."""
mock_sf_instance = mocker.MagicMock(spec=SimpleSalesforce)
mocker.patch("viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance)
mocker.patch(
"viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance
)
salesforce_instance = Salesforce(credentials=variables["credentials"])
salesforce_instance.data = []

with pytest.raises(ValueError, match="The response does not contain any data."):
salesforce_instance.to_df(if_empty="fail")


@pytest.mark.functions()
@pytest.mark.functions
def test_salesforce_to_df_warn_empty_data(mocker):
"""Test Salesforce `to_df` method with empty df, warn."""
mock_sf_instance = mocker.MagicMock(spec=SimpleSalesforce)
mocker.patch("viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance)
mocker.patch(
"viadot.sources.salesforce.SimpleSalesforce", return_value=mock_sf_instance
)
salesforce_instance = Salesforce(credentials=variables["credentials"])
salesforce_instance.data = []

Expand Down

0 comments on commit 4d2fc50

Please sign in to comment.