-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: framework for overriding standard test validation methods (#33)
- implements a sample target test class to make assertions on the table - assert row count, column count, and types - drop the table after the test is done I disabled the python version matrix in CI because they were interfering with each other since right now we share a schema. Adding the github action run ID as a prefix on the schema is probably a good idea #34. --------- Co-authored-by: Edgar R. M. <[email protected]> Co-authored-by: Ken Payne <[email protected]>
- Loading branch information
1 parent
29f7d2c
commit f144882
Showing
2 changed files
with
96 additions
and
11 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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import snowflake.sqlalchemy.custom_types as sct | ||
from singer_sdk.testing.suites import TestSuite | ||
from singer_sdk.testing.target_tests import ( | ||
TargetArrayData, | ||
TargetCamelcaseComplexSchema, | ||
TargetCamelcaseTest, | ||
TargetCliPrintsTest, | ||
TargetDuplicateRecords, | ||
TargetEncodedStringData, | ||
TargetInvalidSchemaTest, | ||
TargetNoPrimaryKeys, | ||
TargetOptionalAttributes, | ||
TargetRecordBeforeSchemaTest, | ||
TargetRecordMissingKeyProperty, | ||
TargetSchemaNoProperties, | ||
TargetSchemaUpdates, | ||
TargetSpecialCharsInAttributes, | ||
) | ||
|
||
|
||
class SnowflakeTargetArrayData(TargetArrayData): | ||
def validate(self) -> None: | ||
connector = self.target.default_sink_class.connector_class(self.target.config) | ||
table = f"{self.target.config['database']}.{self.target.config['default_target_schema']}.test_{self.name}".upper() | ||
result = connector.connection.execute( | ||
f"select * from {table}", | ||
) | ||
assert result.rowcount == 4 | ||
row = result.first() | ||
assert len(row) == 8 | ||
assert row[1] == '[\n "apple",\n "orange",\n "pear"\n]' | ||
table_schema = connector.get_table(table) | ||
expected_types = { | ||
"id": sct._CUSTOM_DECIMAL, | ||
"fruits": sct.VARIANT, | ||
"_sdc_extracted_at": sct.TIMESTAMP_NTZ, | ||
"_sdc_batched_at": sct.TIMESTAMP_NTZ, | ||
"_sdc_received_at": sct.TIMESTAMP_NTZ, | ||
"_sdc_deleted_at": sct.TIMESTAMP_NTZ, | ||
"_sdc_table_version": sct.NUMBER, | ||
"_sdc_sequence": sct.NUMBER, | ||
} | ||
for column in table_schema.columns: | ||
assert column.name in expected_types | ||
isinstance(column.type, expected_types[column.name]) | ||
|
||
|
||
target_tests = TestSuite( | ||
kind="target", | ||
tests=[ | ||
SnowflakeTargetArrayData, | ||
TargetCamelcaseComplexSchema, | ||
TargetCamelcaseTest, | ||
TargetCliPrintsTest, | ||
TargetDuplicateRecords, | ||
TargetEncodedStringData, | ||
TargetInvalidSchemaTest, | ||
# TargetMultipleStateMessages, | ||
TargetNoPrimaryKeys, | ||
TargetOptionalAttributes, | ||
TargetRecordBeforeSchemaTest, | ||
TargetRecordMissingKeyProperty, | ||
TargetSchemaNoProperties, | ||
TargetSchemaUpdates, | ||
TargetSpecialCharsInAttributes, | ||
], | ||
) |