Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated context extension #255

Merged
merged 6 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Changed

- Removed deprecated context extension [#255](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/255)


## [v3.0.0a0]

Expand Down
24 changes: 4 additions & 20 deletions stac_fastapi/core/stac_fastapi/core/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,22 +312,14 @@ async def item_collection(
self.item_serializer.db_to_stac(item, base_url=base_url) for item in items
]

context_obj = None
if self.extension_is_enabled("ContextExtension"):
context_obj = {
"returned": len(items),
"limit": limit,
}
if maybe_count is not None:
context_obj["matched"] = maybe_count

links = await PagingLinks(request=request, next=next_token).get_links()

return stac_types.ItemCollection(
type="FeatureCollection",
features=items,
links=links,
context=context_obj,
numReturned=len(items),
numMatched=maybe_count,
)

async def get_item(
Expand Down Expand Up @@ -633,22 +625,14 @@ async def post_search(
for feat in items
]

context_obj = None
if self.extension_is_enabled("ContextExtension"):
context_obj = {
"returned": len(items),
"limit": limit,
}
if maybe_count is not None:
context_obj["matched"] = maybe_count

links = await PagingLinks(request=request, next=next_token).get_links()

return stac_types.ItemCollection(
type="FeatureCollection",
features=items,
links=links,
context=context_obj,
numReturned=len(items),
numMatched=maybe_count,
)


Expand Down
2 changes: 0 additions & 2 deletions stac_fastapi/elasticsearch/stac_fastapi/elasticsearch/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
create_index_templates,
)
from stac_fastapi.extensions.core import (
ContextExtension,
FieldsExtension,
FilterExtension,
SortExtension,
Expand Down Expand Up @@ -57,7 +56,6 @@
QueryExtension(),
SortExtension(),
TokenPaginationExtension(),
ContextExtension(),
filter_extension,
]

Expand Down
2 changes: 0 additions & 2 deletions stac_fastapi/opensearch/stac_fastapi/opensearch/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from stac_fastapi.core.extensions import QueryExtension
from stac_fastapi.core.session import Session
from stac_fastapi.extensions.core import (
ContextExtension,
FieldsExtension,
FilterExtension,
SortExtension,
Expand Down Expand Up @@ -57,7 +56,6 @@
QueryExtension(),
SortExtension(),
TokenPaginationExtension(),
ContextExtension(),
filter_extension,
]

Expand Down
8 changes: 4 additions & 4 deletions stac_fastapi/tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async def test_app_search_response(app_client, ctx):


@pytest.mark.asyncio
async def test_app_context_extension(app_client, txn_client, ctx, load_test_data):
async def test_app_context_results(app_client, txn_client, ctx, load_test_data):
test_item = load_test_data("test_item.json")
test_item["id"] = "test-item-2"
test_item["collection"] = "test-collection-2"
Expand Down Expand Up @@ -111,9 +111,8 @@ async def test_app_context_extension(app_client, txn_client, ctx, load_test_data

resp_json = resp.json()
assert len(resp_json["features"]) == 1
assert "context" in resp_json
assert resp_json["context"]["returned"] == 1
if matched := resp_json["context"].get("matched"):
assert resp_json["numReturned"] == 1
if matched := resp_json.get("numMatched"):
assert matched == 1


Expand Down Expand Up @@ -225,6 +224,7 @@ async def test_app_query_extension_limit_lt0(app_client):
).status_code == 400


@pytest.mark.skip(reason="removal of context extension")
@pytest.mark.asyncio
async def test_app_query_extension_limit_gt10000(app_client):
resp = await app_client.post("/search", json={"limit": 10001})
Expand Down
5 changes: 1 addition & 4 deletions stac_fastapi/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@
create_index_templates,
)

from stac_fastapi.extensions.core import ( # FieldsExtension,
ContextExtension,
from stac_fastapi.extensions.core import (
FieldsExtension,
FilterExtension,
SortExtension,
Expand Down Expand Up @@ -193,7 +192,6 @@ async def app():
),
settings=settings,
),
ContextExtension(),
SortExtension(),
FieldsExtension(),
QueryExtension(),
Expand Down Expand Up @@ -236,7 +234,6 @@ async def app_basic_auth():
),
settings=settings,
),
ContextExtension(),
SortExtension(),
FieldsExtension(),
QueryExtension(),
Expand Down
10 changes: 5 additions & 5 deletions stac_fastapi/tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ async def test_get_item_collection(app_client, ctx, txn_client):
assert resp.status_code == 200

item_collection = resp.json()
if matched := item_collection["context"].get("matched"):
if matched := item_collection.get("numMatched"):
assert matched == item_count + 1


Expand Down Expand Up @@ -283,13 +283,13 @@ async def test_pagination(app_client, load_test_data):
)
assert resp.status_code == 200
first_page = resp.json()
assert first_page["context"]["returned"] == 3
assert first_page["numReturned"] == 3

url_components = urlsplit(first_page["links"][0]["href"])
resp = await app_client.get(f"{url_components.path}?{url_components.query}")
assert resp.status_code == 200
second_page = resp.json()
assert second_page["context"]["returned"] == 3
assert second_page["numReturned"] == 3


@pytest.mark.skip(reason="created and updated fields not be added with stac fastapi 3?")
Expand Down Expand Up @@ -547,14 +547,14 @@ async def test_item_search_get_query_extension(app_client, ctx):
),
}
resp = await app_client.get("/search", params=params)
assert resp.json()["context"]["returned"] == 0
assert resp.json()["numReturned"] == 0

params["query"] = json.dumps(
{"proj:epsg": {"eq": test_item["properties"]["proj:epsg"]}}
)
resp = await app_client.get("/search", params=params)
resp_json = resp.json()
assert resp_json["context"]["returned"] == 1
assert resp_json["numReturned"] == 1
assert (
resp_json["features"][0]["properties"]["proj:epsg"]
== test_item["properties"]["proj:epsg"]
Expand Down