-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add unit test for date parsing and add manual trimming for invalid da…
…te types (#141) * Fix date parsing * Fix date parsing * Update version to 0.2.3 * Fix lint
- Loading branch information
1 parent
278d94c
commit 887eb86
Showing
6 changed files
with
133 additions
and
3 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 |
---|---|---|
@@ -1,3 +1,24 @@ | ||
"""Test Configuration.""" | ||
from pathlib import Path | ||
|
||
from singer_sdk.testing.templates import TargetFileTestTemplate | ||
|
||
pytest_plugins = () | ||
|
||
class TargetClickhouseFileTestTemplate(TargetFileTestTemplate): | ||
"""Base Target File Test Template. | ||
Use this when sourcing Target test input from a .singer file. | ||
""" | ||
|
||
@property | ||
def singer_filepath(self): | ||
"""Get path to singer JSONL formatted messages file. | ||
Files will be sourced from `./target_test_streams/<test name>.singer`. | ||
Returns | ||
The expected Path to this tests singer file. | ||
""" | ||
current_file_path = Path(__file__).resolve() | ||
return current_file_path.parent / "target_test_streams" / f"{self.name}.singer" |
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,39 @@ | ||
|
||
import datetime | ||
import logging | ||
|
||
from singer_sdk.testing.suites import TestSuite | ||
from sqlalchemy import text | ||
|
||
from tests.conftest import TargetClickhouseFileTestTemplate | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
class TestDateTypeTargetClickhouse(TargetClickhouseFileTestTemplate): | ||
"""Test date type can be ingested into Clickhouse.""" | ||
|
||
name = "date_type" | ||
|
||
def validate(self) -> None: | ||
"""Validate the data in the target.""" | ||
connector = self.target.default_sink_class.connector_class(self.target.config) | ||
result = connector.connection.execute( | ||
statement=text("SELECT * FROM date_type"), | ||
).fetchall() | ||
record_id_1 = 1 | ||
record_1 = next(iter([ | ||
record for record in result if record[0] == record_id_1 | ||
])) | ||
assert record_1[1] == datetime.date(2024, 3, 15) | ||
record_id_2 = 2 | ||
record_2 = next(iter([ | ||
record for record in result if record[0] == record_id_2 | ||
])) | ||
assert record_2[1] == datetime.date(2024, 3, 16) | ||
|
||
custom_target_test_suite = TestSuite( | ||
kind="target", | ||
tests=[ | ||
TestDateTypeTargetClickhouse, | ||
], | ||
) |
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,4 @@ | ||
{"type": "SCHEMA", "stream": "date_type", "key_properties": ["id"], "schema": {"required": ["id"], "type": "object", "properties": {"id": {"type": "integer"}, "date": {"format": "date", "type": [ "null", "string" ] }}}} | ||
{"type": "RECORD", "stream": "date_type", "record": {"id": 1, "date": "2024-03-15"}} | ||
{"type": "RECORD", "stream": "date_type", "record": {"id": 2, "date": "2024-03-16T00:00:00+00:00"}} | ||
{"type": "RECORD", "stream": "date_type", "record": {"id": 3, "date": null}} |
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