Skip to content

Commit 7b2b191

Browse files
authored
Aggregation self link with collection specified (#295)
**Related Issue(s):** N/A **Description:** Fixes the `self` link in the response of the `/collections/{collection_id}/aggregations` request. The collection ID segment was missing in the URL because of the relative path URL construction. **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 4fa6546 commit 7b2b191

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

CHANGELOG.md

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

1212
### Changed
13+
- Fixed the `self` link for the `/collections/{collection_id}/aggregations` endpoint. [#295](https://github.com/stac-utils/stac-fastapi-elasticsearch-opensearch/pull/295)
1314

1415
## [v3.1.0] - 2024-09-02
1516

stac_fastapi/core/stac_fastapi/core/extensions/aggregation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ async def get_aggregations(self, collection_id: Optional[str] = None, **kwargs):
143143
{
144144
"rel": "self",
145145
"type": "application/json",
146-
"href": urljoin(collection_endpoint, "aggregations"),
146+
"href": urljoin(collection_endpoint + "/", "aggregations"),
147147
},
148148
]
149149
)

stac_fastapi/tests/extensions/test_aggregation.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
from urllib.parse import urlparse
23

34
import pytest
45

@@ -68,6 +69,11 @@ async def test_get_collection_aggregations(app_client, ctx, load_test_data):
6869
resp = await app_client.get(f"/collections/{test_collection['id']}/aggregations")
6970
assert resp.status_code == 200
7071
assert len(resp.json()["aggregations"]) == 15
72+
rj = resp.json()
73+
href_self = urlparse(
74+
next(link["href"] for link in rj["links"] if link["rel"] == "self")
75+
)
76+
assert href_self.path == f"/collections/{test_collection['id']}/aggregations"
7177

7278
resp = await app_client.delete(f"/collections/{test_collection['id']}")
7379
assert resp.status_code == 204
@@ -86,6 +92,11 @@ async def test_post_collection_aggregations(app_client, ctx, load_test_data):
8692
resp = await app_client.post(f"/collections/{test_collection['id']}/aggregations")
8793
assert resp.status_code == 200
8894
assert len(resp.json()["aggregations"]) == 15
95+
rj = resp.json()
96+
href_self = urlparse(
97+
next(link["href"] for link in rj["links"] if link["rel"] == "self")
98+
)
99+
assert href_self.path == f"/collections/{test_collection['id']}/aggregations"
89100

90101
resp = await app_client.delete(f"/collections/{test_collection['id']}")
91102
assert resp.status_code == 204

0 commit comments

Comments
 (0)