From 41d8ab0b127b5ecd56dfe85a674f77b34c7e9d1e Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Mon, 20 May 2024 22:25:52 +0200 Subject: [PATCH 1/4] allow null datetime --- stac_pydantic/item.py | 2 +- tests/example_stac/datetimerange.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/stac_pydantic/item.py b/stac_pydantic/item.py index 4b2d54a..4fc24d5 100644 --- a/stac_pydantic/item.py +++ b/stac_pydantic/item.py @@ -20,7 +20,7 @@ class ItemProperties(StacCommonMetadata): """ # Overide the datetime field to be required - datetime: Optional[UtcDatetime] + datetime: Optional[UtcDatetime] = Field(...) # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. model_config = ConfigDict(extra="allow") diff --git a/tests/example_stac/datetimerange.json b/tests/example_stac/datetimerange.json index d453321..f2e9e96 100644 --- a/tests/example_stac/datetimerange.json +++ b/tests/example_stac/datetimerange.json @@ -37,7 +37,7 @@ ] }, "properties":{ - "datetime":"2018-01-01T13:21:30Z", + "datetime":null, "start_datetime":"2018-01-01T13:21:30Z", "end_datetime":"2018-01-01T13:31:30Z" }, From 960abecfb0bcd2ac2a825e3b0dc2da141197bd6f Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Tue, 21 May 2024 11:24:15 +0200 Subject: [PATCH 2/4] make datetime required in `StacCommonMetadata` --- stac_pydantic/item.py | 12 +----------- stac_pydantic/shared.py | 2 +- tests/test_models.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/stac_pydantic/item.py b/stac_pydantic/item.py index 4fc24d5..6bc03ef 100644 --- a/stac_pydantic/item.py +++ b/stac_pydantic/item.py @@ -4,13 +4,7 @@ from pydantic import AnyUrl, ConfigDict, Field, model_serializer, model_validator from stac_pydantic.links import Links -from stac_pydantic.shared import ( - SEMVER_REGEX, - Asset, - StacBaseModel, - StacCommonMetadata, - UtcDatetime, -) +from stac_pydantic.shared import SEMVER_REGEX, Asset, StacBaseModel, StacCommonMetadata from stac_pydantic.version import STAC_VERSION @@ -19,10 +13,6 @@ class ItemProperties(StacCommonMetadata): https://github.com/radiantearth/stac-spec/blob/v1.0.0/item-spec/item-spec.md#properties-object """ - # Overide the datetime field to be required - datetime: Optional[UtcDatetime] = Field(...) - - # Check https://docs.pydantic.dev/dev-v2/migration/#changes-to-config for more information. model_config = ConfigDict(extra="allow") diff --git a/stac_pydantic/shared.py b/stac_pydantic/shared.py index 5903cf3..eede150 100644 --- a/stac_pydantic/shared.py +++ b/stac_pydantic/shared.py @@ -134,7 +134,7 @@ class StacCommonMetadata(StacBaseModel): title: Optional[str] = None description: Optional[str] = None # Date and Time - datetime: Optional[UtcDatetime] = None + datetime: Optional[UtcDatetime] = Field(...) created: Optional[UtcDatetime] = None updated: Optional[UtcDatetime] = None # Date and Time Range diff --git a/tests/test_models.py b/tests/test_models.py index 6472bee..d5c08f8 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -180,6 +180,16 @@ def test_stac_common_dates(args) -> None: StacCommonMetadata(**args) +def test_stac_null_datetime_required() -> None: + with pytest.raises(ValidationError): + StacCommonMetadata( + **{ + "start_datetime": "2024-01-01T00:00:00Z", + "end_datetime": "2024-01-02T00:00:00Z", + } + ) + + @pytest.mark.parametrize( "args", [ From 7f0049d9b953a38625bfafb1f363f7d7fbe2374b Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Tue, 21 May 2024 11:29:52 +0200 Subject: [PATCH 3/4] add more start/end datetime tests --- tests/api/test_search.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/api/test_search.py b/tests/api/test_search.py index 15fd19c..95899ab 100644 --- a/tests/api/test_search.py +++ b/tests/api/test_search.py @@ -77,6 +77,14 @@ def test_temporal_search_two_tailed(): assert search.start_date == utcnow assert search.end_date is None + search = Search(collections=["collection1"], datetime=f"../{utcnow_str}") + assert search.start_date is None + assert search.end_date == utcnow + + search = Search(collections=["collection1"], datetime=f"/{utcnow_str}") + assert search.start_date is None + assert search.end_date == utcnow + def test_temporal_search_open(): # Test open date range From 9801cbb210fab8c246e725b8cb7f8b04500b5ffe Mon Sep 17 00:00:00 2001 From: vincentsarago Date: Tue, 21 May 2024 15:50:56 +0200 Subject: [PATCH 4/4] update codecov --- .github/workflows/cicd.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cicd.yml b/.github/workflows/cicd.yml index c2b72c3..b22a78f 100644 --- a/.github/workflows/cicd.yml +++ b/.github/workflows/cicd.yml @@ -8,6 +8,8 @@ on: tags: - '*' pull_request: +env: + LATEST_PY_VERSION: '3.12' jobs: tests: @@ -35,10 +37,10 @@ jobs: run: tox -e py - name: Upload Results - if: success() - uses: codecov/codecov-action@v1 + if: ${{ matrix.python-version == env.LATEST_PY_VERSION }} + uses: codecov/codecov-action@v4 with: file: ./coverage.xml flags: unittests - name: ${{ matrix.platform }}-${{ matrix.tox-env }} + name: ${{ matrix.python-version }} fail_ci_if_error: false