From 1b350a2e6e047cd4e1e73ac19560c8ac445e7e28 Mon Sep 17 00:00:00 2001 From: James Fisher <85769594+jamesfisher-gis@users.noreply.github.com> Date: Wed, 29 May 2024 10:51:06 -0400 Subject: [PATCH] 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 --- CHANGELOG.md | 4 ++++ stac_fastapi/tests/api/test_api.py | 18 +++++++++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c763b4aa..88b1f14f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed + +- API sort extension tests [#264](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/264) + ## [v3.0.0a1] ### Changed diff --git a/stac_fastapi/tests/api/test_api.py b/stac_fastapi/tests/api/test_api.py index 8f519a0f..8fe09934 100644 --- a/stac_fastapi/tests/api/test_api.py +++ b/stac_fastapi/tests/api/test_api.py @@ -1,5 +1,5 @@ import uuid -from datetime import timedelta +from datetime import datetime, timedelta, timezone import pytest @@ -245,7 +245,9 @@ async def test_app_sort_extension_get_asc(app_client, txn_client, ctx): second_item = dict(first_item) second_item["id"] = "another-item" - another_item_date = first_item["properties"]["datetime"] - timedelta(days=1) + another_item_date = datetime.strptime( + first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" + ).replace(tzinfo=timezone.utc) - timedelta(days=1) second_item["properties"]["datetime"] = another_item_date.isoformat().replace( "+00:00", "Z" ) @@ -265,7 +267,9 @@ async def test_app_sort_extension_get_desc(app_client, txn_client, ctx): second_item = dict(first_item) second_item["id"] = "another-item" - another_item_date = first_item["properties"]["datetime"] - timedelta(days=1) + another_item_date = datetime.strptime( + first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" + ).replace(tzinfo=timezone.utc) - timedelta(days=1) second_item["properties"]["datetime"] = another_item_date.isoformat().replace( "+00:00", "Z" ) @@ -284,7 +288,9 @@ async def test_app_sort_extension_post_asc(app_client, txn_client, ctx): second_item = dict(first_item) second_item["id"] = "another-item" - another_item_date = first_item["properties"]["datetime"] - timedelta(days=1) + another_item_date = datetime.strptime( + first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" + ).replace(tzinfo=timezone.utc) - timedelta(days=1) second_item["properties"]["datetime"] = another_item_date.isoformat().replace( "+00:00", "Z" ) @@ -307,7 +313,9 @@ async def test_app_sort_extension_post_desc(app_client, txn_client, ctx): second_item = dict(first_item) second_item["id"] = "another-item" - another_item_date = first_item["properties"]["datetime"] - timedelta(days=1) + another_item_date = datetime.strptime( + first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" + ).replace(tzinfo=timezone.utc) - timedelta(days=1) second_item["properties"]["datetime"] = another_item_date.isoformat().replace( "+00:00", "Z" )