|
7 | 7 | import pytest |
8 | 8 | from jsonschema import ValidationError, validate |
9 | 9 | from pydantic.v1 import BaseModel |
| 10 | +from pydantic.v1 import ValidationError as PydanticValidationError |
10 | 11 |
|
| 12 | +from airbyte_cdk.sources.file_based.config.abstract_file_based_spec import AbstractFileBasedSpec |
11 | 13 | from airbyte_cdk.sources.file_based.config.file_based_stream_config import ( |
12 | 14 | AvroFormat, |
13 | 15 | CsvFormat, |
@@ -40,3 +42,28 @@ def test_parquet_file_type_is_not_a_valid_csv_file_type( |
40 | 42 | validate(instance=format_config[file_type], schema=file_format.schema()) |
41 | 43 | else: |
42 | 44 | 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