Skip to content

Commit afb8fcb

Browse files
authored
fix: milliseconds precision in dates and tests update (#90)
- use milliseconds precision for items dates - update tests following STAC-formatted serialization in EODAG - improve tests failures verbosity
1 parent d299420 commit afb8fcb

3 files changed

Lines changed: 9 additions & 8 deletions

File tree

stac_fastapi/eodag/models/stac_metadata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ class CommonStacMetadata(ItemProperties):
6464

6565
@field_serializer("datetime", "start_datetime", "end_datetime", "created", "updated")
6666
def format_datetime(self, value: dt):
67-
"""format datetime properties"""
68-
return value.strftime("%Y-%m-%dT%H:%M:%S.%fZ")
67+
"""format datetime properties with milliseconds precision (3 decimal places)"""
68+
milliseconds = value.microsecond // 1000
69+
return value.strftime("%Y-%m-%dT%H:%M:%S") + f".{milliseconds:03d}Z"
6970

7071
@model_validator(mode="before")
7172
@classmethod

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def mock_search_result():
169169
"https://peps.cnes.fr/resto/collections/S1/578f1768-e66e-5b86-9363-b19f8931cc7b/download"
170170
),
171171
"eodag:provider": "peps",
172-
"eodag:collection": "S1_SAR_OCN",
172+
"collection": "S1_SAR_OCN",
173173
"platform": "S1A",
174174
"eo:cloud_cover": 0,
175175
"title": "S1A_WV_OCN__2SSV_20180215T235323_20180216T001213_020624_023501_0FD3",
@@ -226,7 +226,7 @@ def mock_search_result():
226226
"https://peps.cnes.fr/resto/collections/S1/578f1768-e66e-5b86-9363-b19f8931cc7c/download"
227227
),
228228
"eodag:provider": "peps",
229-
"eodag:collection": "S1_SAR_OCN",
229+
"collection": "S1_SAR_OCN",
230230
"platform": "S1A",
231231
"eo:cloud_cover": 0,
232232
"title": "S1A_WV_OCN__2SSV_20180216T235323_20180217T001213_020624_023501_0FD3",
@@ -450,7 +450,7 @@ async def _request_valid_raw(
450450
pytest.fail(f"Assertion failed: {e}\nAdditional context: {response.text}.")
451451

452452
assert expected_status_code == response.status_code, (
453-
f"For {method}: {url}, body: {post_data}, got: {str(response)}"
453+
f"For {method}: {url}, body: {post_data}, got: {response.content}"
454454
)
455455
return response
456456

tests/test_search.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ async def test_items_response(request_valid, defaults):
126126
"properties",
127127
}
128128
assert first_props["federation:backends"] == ["peps"]
129-
assert first_props["datetime"] == "2018-02-15T23:53:22.871000Z"
130-
assert first_props["start_datetime"] == "2018-02-15T23:53:22.871000Z"
131-
assert first_props["end_datetime"] == "2018-02-16T00:12:14.035000Z"
129+
assert first_props["datetime"] == "2018-02-15T23:53:22.871Z"
130+
assert first_props["start_datetime"] == "2018-02-15T23:53:22.871Z"
131+
assert first_props["end_datetime"] == "2018-02-16T00:12:14.035Z"
132132
assert first_props["license"] == "other"
133133
assert first_props["platform"] == "S1A"
134134
assert first_props["instruments"] == ["SAR-C", "SAR"]

0 commit comments

Comments
 (0)