Skip to content

Commit 1b350a2

Browse files
Repair API sort tests (#264)
**Related Issue(s):** - #262 **Description:** Edit to four tests of the sort extension. The timezone `Z` character was not being included with the `.replace` command. So it was removed and `Z` is appended to the datetime string. **PR Checklist:** - [x] Code is formatted and linted (run `pre-commit run --all-files`) - [x] Tests pass (run `make test`) - [x] Documentation has been updated to reflect changes, if applicable - [x] Changes are added to the changelog
1 parent 49fecf9 commit 1b350a2

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- API sort extension tests [#264](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/264)
13+
1014
## [v3.0.0a1]
1115

1216
### Changed

stac_fastapi/tests/api/test_api.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid
2-
from datetime import timedelta
2+
from datetime import datetime, timedelta, timezone
33

44
import pytest
55

@@ -245,7 +245,9 @@ async def test_app_sort_extension_get_asc(app_client, txn_client, ctx):
245245

246246
second_item = dict(first_item)
247247
second_item["id"] = "another-item"
248-
another_item_date = first_item["properties"]["datetime"] - timedelta(days=1)
248+
another_item_date = datetime.strptime(
249+
first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ"
250+
).replace(tzinfo=timezone.utc) - timedelta(days=1)
249251
second_item["properties"]["datetime"] = another_item_date.isoformat().replace(
250252
"+00:00", "Z"
251253
)
@@ -265,7 +267,9 @@ async def test_app_sort_extension_get_desc(app_client, txn_client, ctx):
265267

266268
second_item = dict(first_item)
267269
second_item["id"] = "another-item"
268-
another_item_date = first_item["properties"]["datetime"] - timedelta(days=1)
270+
another_item_date = datetime.strptime(
271+
first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ"
272+
).replace(tzinfo=timezone.utc) - timedelta(days=1)
269273
second_item["properties"]["datetime"] = another_item_date.isoformat().replace(
270274
"+00:00", "Z"
271275
)
@@ -284,7 +288,9 @@ async def test_app_sort_extension_post_asc(app_client, txn_client, ctx):
284288

285289
second_item = dict(first_item)
286290
second_item["id"] = "another-item"
287-
another_item_date = first_item["properties"]["datetime"] - timedelta(days=1)
291+
another_item_date = datetime.strptime(
292+
first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ"
293+
).replace(tzinfo=timezone.utc) - timedelta(days=1)
288294
second_item["properties"]["datetime"] = another_item_date.isoformat().replace(
289295
"+00:00", "Z"
290296
)
@@ -307,7 +313,9 @@ async def test_app_sort_extension_post_desc(app_client, txn_client, ctx):
307313

308314
second_item = dict(first_item)
309315
second_item["id"] = "another-item"
310-
another_item_date = first_item["properties"]["datetime"] - timedelta(days=1)
316+
another_item_date = datetime.strptime(
317+
first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ"
318+
).replace(tzinfo=timezone.utc) - timedelta(days=1)
311319
second_item["properties"]["datetime"] = another_item_date.isoformat().replace(
312320
"+00:00", "Z"
313321
)

0 commit comments

Comments
 (0)