Skip to content

Commit

Permalink
🚀 Add and update test to sap_rfc after change in credential passing l…
Browse files Browse the repository at this point in the history
…ogic
  • Loading branch information
adrian-wojcik committed Mar 18, 2024
1 parent e5ee5b7 commit afab409
Show file tree
Hide file tree
Showing 2 changed files with 123 additions and 7 deletions.
47 changes: 43 additions & 4 deletions tests/integration/tasks/test_sap_rfc_to_df.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,52 @@
import pytest
import logging

from viadot.exceptions import CredentialError
from viadot.config import local_config
from viadot.tasks import SAPRFCToDF


def test_sap_rfc_to_df_bbp():
sap_test_creds = local_config.get("SAP").get("QA")
task = SAPRFCToDF(
credentials=sap_test_creds,
query="SELECT MATNR, MATKL, MTART, LAEDA FROM MARA WHERE LAEDA LIKE '2022%'",
query="SELECT MATNR, MATKL, MTART, LAEDA FROM MARA WHERE LAEDA LIKE '20220110%'",
func="BBP_RFC_READ_TABLE",
)
df = task.run()
df = task.run(sap_credentials_key="SAP", env="QA")
assert len(df.columns) == 4 and not df.empty


def test_sap_rfc_to_df_wrong_sap_credential_key_bbp(caplog):
task = SAPRFCToDF(
query="SELECT MATNR, MATKL, MTART, LAEDA FROM MARA WHERE LAEDA LIKE '20220110%'",
func="BBP_RFC_READ_TABLE",
)
with pytest.raises(
CredentialError,
match="Sap_credentials_key: SAP_test is not stored neither in KeyVault or Local Config!",
):
task.run(
sap_credentials_key="SAP_test",
)
assert (
f"Getting credentials from Azure Key Vault was not possible. Either there is no key: SAP_test or env: DEV or there is not Key Vault in your environment."
in caplog.text
)


def test_sap_rfc_to_df_wrong_env_bbp(caplog):
task = SAPRFCToDF(
query="SELECT MATNR, MATKL, MTART, LAEDA FROM MARA WHERE LAEDA LIKE '20220110%'",
func="BBP_RFC_READ_TABLE",
)
with pytest.raises(
CredentialError,
match="Missing PROD_test credentials!",
):
task.run(
sap_credentials_key="SAP",
env="PROD_test",
)
assert (
f"Getting credentials from Azure Key Vault was not possible. Either there is no key: SAP or env: PROD_test or there is not Key Vault in your environment."
in caplog.text
)
83 changes: 80 additions & 3 deletions tests/integration/test_sap_rfc.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from collections import OrderedDict
import pytest
import logging

from collections import OrderedDict
from viadot.sources import SAPRFC, SAPRFCV2
from viadot.exceptions import CredentialError

sap = SAPRFC()
sap2 = SAPRFCV2()
Expand Down Expand Up @@ -192,14 +195,88 @@ def test___build_pandas_filter_query_v2():
def test_default_credentials_warning_SAPRFC(caplog):
_ = SAPRFC()
assert (
"Your credentials will use DEV environment. If you would like to use different one - please specified it."
f"Your credentials will use DEV environment from local config. If you would like to use different one - please specified it in sap_credentials parameter"
in caplog.text
)


def test_default_credentials_warning_SAPRFCV2(caplog):
_ = SAPRFCV2()
assert (
"Your credentials will use DEV environment. If you would like to use different one - please specified it."
f"Your credentials will use DEV environment from local config. If you would like to use different one - please specified it in sap_credentials parameter"
in caplog.text
)


def test_credentials_dictionary_wrong_key_warning_SAPRFC(caplog):
_ = SAPRFC(
sap_credentials={
"sysnr_test": "01",
"user": "AIA_RFC_USER",
"passwd": "gXy3!Tk06",
"ashost": "pep1v.velux.org",
}
)
assert (
f"Required key 'sysnr' not found in your 'sap_credentials' dictionary!"
in caplog.text
)
assert (
f"Your credentials will use DEV environment from local config. If you would like to use different one - please specified it in sap_credentials parameter"
in caplog.text
)


def test_credentials_dictionary_wrong_key_warning_SAPRFCV2(caplog):
_ = SAPRFCV2(
sap_credentials={
"sysnr_test": "01",
"user": "AIA_RFC_USER",
"passwd": "gXy3!Tk06",
"ashost": "pep1v.velux.org",
}
)
assert (
f"Required key 'sysnr' not found in your 'sap_credentials' dictionary!"
in caplog.text
)
assert (
f"Your credentials will use DEV environment from local config. If you would like to use different one - please specified it in sap_credentials parameter"
in caplog.text
)


def test_sap_credentials_key_wrong_value_error_SAPRFC(caplog):
with pytest.raises(
CredentialError,
match="Sap_credentials_key: SAP_test is not stored neither in KeyVault or Local Config!",
):
with caplog.at_level(logging.ERROR):
_ = SAPRFC(sap_credentials_key="SAP_test")


def test_sap_credentials_key_wrong_value_error_SAPRFCV2(caplog):
with pytest.raises(
CredentialError,
match="Sap_credentials_key: SAP_test is not stored neither in KeyVault or Local Config!",
):
with caplog.at_level(logging.ERROR):
_ = SAPRFC(sap_credentials_key="SAP_test")


def test_env_wrong_value_error_SAPRFC(caplog):
with pytest.raises(
CredentialError,
match="Missing PROD_test credentials!",
):
with caplog.at_level(logging.ERROR):
_ = SAPRFC(env="PROD_test")


def test_env_wrong_value_error_SAPRFCV2(caplog):
with pytest.raises(
CredentialError,
match="Missing PROD_test credentials!",
):
with caplog.at_level(logging.ERROR):
_ = SAPRFC(env="PROD_test")

0 comments on commit afab409

Please sign in to comment.