From 140b03adf97161303565de7f97a5a07d3a3f00ea Mon Sep 17 00:00:00 2001 From: James Date: Wed, 29 May 2024 05:36:50 -0400 Subject: [PATCH 1/3] sort test fix --- stac_fastapi/tests/api/test_api.py | 35 +++++++++++++++--------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/stac_fastapi/tests/api/test_api.py b/stac_fastapi/tests/api/test_api.py index 8f519a0f..2937c347 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 import pytest @@ -245,10 +245,11 @@ 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) - second_item["properties"]["datetime"] = another_item_date.isoformat().replace( - "+00:00", "Z" - ) + + another_item_date = datetime.strptime( + first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" + ) - timedelta(days=1) + second_item["properties"]["datetime"] = another_item_date.isoformat() + "Z" await create_item(txn_client, second_item) @@ -265,10 +266,10 @@ 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) - second_item["properties"]["datetime"] = another_item_date.isoformat().replace( - "+00:00", "Z" - ) + another_item_date = datetime.strptime( + first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" + ) - timedelta(days=1) + second_item["properties"]["datetime"] = another_item_date.isoformat() + "Z" await create_item(txn_client, second_item) resp = await app_client.get("/search?sortby=-properties.datetime") @@ -284,10 +285,10 @@ 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) - second_item["properties"]["datetime"] = another_item_date.isoformat().replace( - "+00:00", "Z" - ) + another_item_date = datetime.strptime( + first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" + ) - timedelta(days=1) + second_item["properties"]["datetime"] = another_item_date.isoformat() + "Z" await create_item(txn_client, second_item) params = { @@ -307,10 +308,10 @@ 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) - second_item["properties"]["datetime"] = another_item_date.isoformat().replace( - "+00:00", "Z" - ) + another_item_date = datetime.strptime( + first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" + ) - timedelta(days=1) + second_item["properties"]["datetime"] = another_item_date.isoformat() + "Z" await create_item(txn_client, second_item) params = { From 2ed402eb2ddddfa2869122b25f01a1081226d933 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 29 May 2024 06:23:55 -0400 Subject: [PATCH 2/3] fix timezone --- stac_fastapi/tests/api/test_api.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/stac_fastapi/tests/api/test_api.py b/stac_fastapi/tests/api/test_api.py index 2937c347..a29c92fb 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 datetime, timedelta +from datetime import datetime, timedelta, timezone import pytest @@ -248,8 +248,10 @@ async def test_app_sort_extension_get_asc(app_client, txn_client, ctx): another_item_date = datetime.strptime( first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" - ) - timedelta(days=1) - second_item["properties"]["datetime"] = another_item_date.isoformat() + "Z" + ).replace(tzinfo=timezone.utc) - timedelta(days=1) + second_item["properties"]["datetime"] = another_item_date.isoformat().replace( + "+00:00", "Z" + ) await create_item(txn_client, second_item) @@ -268,8 +270,10 @@ async def test_app_sort_extension_get_desc(app_client, txn_client, ctx): second_item["id"] = "another-item" another_item_date = datetime.strptime( first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" - ) - timedelta(days=1) - second_item["properties"]["datetime"] = another_item_date.isoformat() + "Z" + ).replace(tzinfo=timezone.utc) - timedelta(days=1) + second_item["properties"]["datetime"] = another_item_date.isoformat().replace( + "+00:00", "Z" + ) await create_item(txn_client, second_item) resp = await app_client.get("/search?sortby=-properties.datetime") @@ -287,8 +291,10 @@ async def test_app_sort_extension_post_asc(app_client, txn_client, ctx): second_item["id"] = "another-item" another_item_date = datetime.strptime( first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" - ) - timedelta(days=1) - second_item["properties"]["datetime"] = another_item_date.isoformat() + "Z" + ).replace(tzinfo=timezone.utc) - timedelta(days=1) + second_item["properties"]["datetime"] = another_item_date.isoformat().replace( + "+00:00", "Z" + ) await create_item(txn_client, second_item) params = { @@ -310,8 +316,10 @@ async def test_app_sort_extension_post_desc(app_client, txn_client, ctx): second_item["id"] = "another-item" another_item_date = datetime.strptime( first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" - ) - timedelta(days=1) - second_item["properties"]["datetime"] = another_item_date.isoformat() + "Z" + ).replace(tzinfo=timezone.utc) - timedelta(days=1) + second_item["properties"]["datetime"] = another_item_date.isoformat().replace( + "+00:00", "Z" + ) await create_item(txn_client, second_item) params = { From 578a384a75217164ce30185707149f851a02dcbd Mon Sep 17 00:00:00 2001 From: James Date: Wed, 29 May 2024 06:27:37 -0400 Subject: [PATCH 3/3] changelog --- CHANGELOG.md | 4 ++++ stac_fastapi/tests/api/test_api.py | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) 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 a29c92fb..8fe09934 100644 --- a/stac_fastapi/tests/api/test_api.py +++ b/stac_fastapi/tests/api/test_api.py @@ -245,7 +245,6 @@ 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 = datetime.strptime( first_item["properties"]["datetime"], "%Y-%m-%dT%H:%M:%SZ" ).replace(tzinfo=timezone.utc) - timedelta(days=1)