Skip to content

Commit

Permalink
Fix collection links in the return of the collection list endpoint (#269
Browse files Browse the repository at this point in the history
)

* Fix return of the collection list

Add test

Update changelog

* Fix return of the collection list

Add test

Update changelog

* Lint

Co-authored-by: Rob Emanuele <rdemanuele@gmail.com>
Co-authored-by: Nathan Zimmerman <npzimmerman@gmail.com>
  • Loading branch information
3 people authored Sep 21, 2021
1 parent f9ea999 commit 2ffaf12
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* Restrict `limit` parameter in sqlalchemy backend to between 1 and 10,000. ([#251](https://github.com/stac-utils/stac-fastapi/pull/251))
* Fix OAS conformance URL ([#263](https://github.com/stac-utils/stac-fastapi/pull/263))
* Links to children collections from the landing pagge always have a title ([#260](https://github.com/stac-utils/stac-fastapi/pull/260))
* Fix collection links in the `all_collections` method in `pgstac` ([#269](https://github.com/stac-utils/stac-fastapi/pull/269))

## [2.1.0]

Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/pgstac/stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async def all_collections(self, **kwargs) -> Collections:
"href": urljoin(base_url, "collections"),
},
]
collection_list = Collections(collections=collections or [], links=links)
collection_list = Collections(collections=linked_collections or [], links=links)
return collection_list

async def get_collection(self, id: str, **kwargs) -> Collection:
Expand Down
49 changes: 49 additions & 0 deletions stac_fastapi/pgstac/tests/resources/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,52 @@ async def test_returns_valid_collection(app_client, load_test_data):
resp_json, root=mock_root, preserve_dict=False
)
collection.validate()


@pytest.mark.asyncio
async def test_returns_valid_links_in_collections(app_client, load_test_data):
"""Test links from listing collections"""
in_json = load_test_data("test_collection.json")
resp = await app_client.post(
"/collections",
json=in_json,
)
assert resp.status_code == 200

# Get collection by ID
resp = await app_client.get(f"/collections/{in_json['id']}")
assert resp.status_code == 200
resp_json = resp.json()

# Mock root to allow validation
mock_root = pystac.Catalog(
id="test", description="test desc", href="https://example.com"
)
collection = pystac.Collection.from_dict(
resp_json, root=mock_root, preserve_dict=False
)
assert collection.validate()

# List collections
resp = await app_client.get("/collections")
assert resp.status_code == 200
resp_json = resp.json()
collections = resp_json["collections"]
# Find collection in list by ID
single_coll = next(coll for coll in collections if coll["id"] == in_json["id"])
is_coll_from_list_valid = False
single_coll_mocked_link = dict()
if single_coll is not None:
single_coll_mocked_link = pystac.Collection.from_dict(
single_coll, root=mock_root, preserve_dict=False
)
is_coll_from_list_valid = single_coll_mocked_link.validate()

assert is_coll_from_list_valid

# Check links from the collection GET and list
assert [
i
for i in collection.to_dict()["links"]
if i not in single_coll_mocked_link.to_dict()["links"]
] == []

0 comments on commit 2ffaf12

Please # to comment.