Tests
This commit is contained in:
parent
9825ab65bd
commit
5ca488dba5
1 changed files with 85 additions and 0 deletions
85
tests/test_integration/test_data_testing.py
Normal file
85
tests/test_integration/test_data_testing.py
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
from great_expectations.core.expectation_configuration import ExpectationConfiguration
|
||||
|
||||
from lolafect.lolaconfig import build_lolaconfig
|
||||
from lolafect.data_testing import run_data_test_on_mysql
|
||||
|
||||
# __ __ _____ _ _ _____ _ _ _____ _
|
||||
# \ \ / /\ | __ \| \ | |_ _| \ | |/ ____| |
|
||||
# \ \ /\ / / \ | |__) | \| | | | | \| | | __| |
|
||||
# \ \/ \/ / /\ \ | _ /| . ` | | | | . ` | | |_ | |
|
||||
# \ /\ / ____ \| | \ \| |\ |_| |_| |\ | |__| |_|
|
||||
# \/ \/_/ \_\_| \_\_| \_|_____|_| \_|\_____(_)
|
||||
# This testing suite requires:
|
||||
# - The calling shell to have permission in AWS
|
||||
# - The calling shell to be within the Mercadão network
|
||||
# - Do not use this tests as part of CI/CD pipelines since they are not idempotent and
|
||||
# rely external resources. Instead, use them manually to check yourself that things
|
||||
# are working properly.
|
||||
|
||||
TEST_LOLACONFIG = build_lolaconfig(flow_name="testing-suite")
|
||||
|
||||
def test_validation_on_mysql_succeeds():
|
||||
|
||||
test_query = """
|
||||
SELECT 1 AS a_one,
|
||||
"lol" AS a_string,
|
||||
NULL AS a_null
|
||||
"""
|
||||
test_expectations = [
|
||||
ExpectationConfiguration(
|
||||
expectation_type="expect_column_values_to_be_between",
|
||||
kwargs={"column": "a_one", "min_value": 1, "max_value": 1},
|
||||
),
|
||||
ExpectationConfiguration(
|
||||
expectation_type="expect_column_values_to_match_like_pattern",
|
||||
kwargs={"column": "a_string", "like_pattern ": "%lol%"},
|
||||
),
|
||||
ExpectationConfiguration(
|
||||
expectation_type="expect_column_values_to_be_null",
|
||||
kwargs={"column": "a_null"},
|
||||
),
|
||||
]
|
||||
|
||||
validation_result = run_data_test_on_mysql(
|
||||
name="lolafect-testing-test_validation_on_mysql_succeeds",
|
||||
mysql_credentials=TEST_LOLACONFIG.DW_CREDENTIALS,
|
||||
query=test_query,
|
||||
expectations=test_expectations
|
||||
)
|
||||
|
||||
data_test_passed = validation_result["success"] == True
|
||||
|
||||
assert data_test_passed
|
||||
|
||||
|
||||
def test_validation_on_mysql_fails():
|
||||
test_query = """
|
||||
SELECT 1 AS a_one,
|
||||
"lol" AS a_string,
|
||||
NULL AS a_null
|
||||
"""
|
||||
test_expectations = [
|
||||
ExpectationConfiguration(
|
||||
expectation_type="expect_column_values_to_be_between",
|
||||
kwargs={"column": "a_one", "min_value": 2, "max_value": 2},
|
||||
),
|
||||
ExpectationConfiguration(
|
||||
expectation_type="expect_column_values_to_match_like_pattern",
|
||||
kwargs={"column": "a_string", "like_pattern ": "%xD%"},
|
||||
),
|
||||
ExpectationConfiguration(
|
||||
expectation_type="expect_column_values_to_not_be_null",
|
||||
kwargs={"column": "a_null"},
|
||||
),
|
||||
]
|
||||
|
||||
validation_result = run_data_test_on_mysql(
|
||||
name="lolafect-testing-test_validation_on_mysql_fails",
|
||||
mysql_credentials=TEST_LOLACONFIG.DW_CREDENTIALS,
|
||||
query=test_query,
|
||||
expectations=test_expectations
|
||||
)
|
||||
|
||||
data_test_failed = validation_result["success"] == False
|
||||
|
||||
assert data_test_failed
|
||||
Loading…
Add table
Add a link
Reference in a new issue