Skip to content

Commit 198de6d

Browse files
test: add unit tests for start_date validation
Co-Authored-By: AJ Steers <aj@airbyte.io>
1 parent 6886ab2 commit 198de6d

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

unit_tests/sources/file_based/config/test_abstract_file_based_spec.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import pytest
88
from jsonschema import ValidationError, validate
99
from pydantic.v1 import BaseModel
10+
from pydantic.v1 import ValidationError as PydanticValidationError
1011

12+
from airbyte_cdk.sources.file_based.config.abstract_file_based_spec import AbstractFileBasedSpec
1113
from airbyte_cdk.sources.file_based.config.file_based_stream_config import (
1214
AvroFormat,
1315
CsvFormat,
@@ -40,3 +42,28 @@ def test_parquet_file_type_is_not_a_valid_csv_file_type(
4042
validate(instance=format_config[file_type], schema=file_format.schema())
4143
else:
4244
validate(instance=format_config[file_type], schema=file_format.schema())
45+
46+
47+
@pytest.mark.parametrize(
48+
"start_date, should_pass",
49+
[
50+
pytest.param("2021-01-01T00:00:00.000000Z", True, id="with_microseconds"),
51+
pytest.param("2021-01-01T00:00:00Z", True, id="without_microseconds"),
52+
pytest.param("2021-01-01T00:00:00.000Z", True, id="with_milliseconds"),
53+
pytest.param("2025-01-01T00:00:00Z", True, id="terraform_provider_format"),
54+
pytest.param("2021-01-01T00:00:00+00:00", True, id="with_timezone_offset"),
55+
pytest.param("2021-01-01", True, id="date_only"),
56+
pytest.param(None, True, id="none_value"),
57+
pytest.param("not-a-date", False, id="invalid_string"),
58+
pytest.param("2021/01/01", True, id="slash_separator_also_accepted"),
59+
pytest.param("", False, id="empty_string"),
60+
],
61+
)
62+
def test_start_date_validation(start_date: str, should_pass: bool) -> None:
63+
"""Test that start_date accepts various valid ISO8601/RFC3339 formats."""
64+
if should_pass:
65+
result = AbstractFileBasedSpec.validate_start_date(start_date)
66+
assert result == start_date
67+
else:
68+
with pytest.raises(ValueError, match="is not a valid datetime string"):
69+
AbstractFileBasedSpec.validate_start_date(start_date)

0 commit comments

Comments
 (0)