Skip to content

Commit

Permalink
Aggregation self link with collection specified (#295)
Browse files Browse the repository at this point in the history
**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
  • Loading branch information
StijnCaerts committed Sep 4, 2024
1 parent 4fa6546 commit 7b2b191
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Added

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async def get_aggregations(self, collection_id: Optional[str] = None, **kwargs):
{
"rel": "self",
"type": "application/json",
"href": urljoin(collection_endpoint, "aggregations"),
"href": urljoin(collection_endpoint + "/", "aggregations"),
},
]
)
Expand Down
11 changes: 11 additions & 0 deletions stac_fastapi/tests/extensions/test_aggregation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from urllib.parse import urlparse

import pytest

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

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

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

0 comments on commit 7b2b191

Please sign in to comment.