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

Ensure client self hrefs don't end in '/' #373

Merged
merged 6 commits into from
Dec 12, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
### Fixed

- Some mishandled cases for datetime intervals [#363](https://github.com/stac-utils/pystac-client/pull/363)
- Collection requests when the Client's url ends in a '/' [#373](https://github.com/stac-utils/pystac-client/pull/373)
- Parse datetimes more strictly [#364](https://github.com/stac-utils/pystac-client/pull/364)

### Removed
Expand Down
1 change: 1 addition & 0 deletions pystac_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ def open(
Return:
catalog : A :class:`Client` instance for this Catalog/API
"""
url = url.rstrip("/")
client: Client = cls.from_file(
url,
headers=headers,
Expand Down
18 changes: 18 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,24 @@ def test_get_collections_with_conformance(self, requests_mock: Mocker) -> None:
assert len(history) == 2
assert history[1].url == collections_link.href

def test_get_collections_single_slash(self, requests_mock: Mocker) -> None:
pc_root_text = read_data_file("planetary-computer-root.json")
root_url = "http://pystac-client.test/"
requests_mock.get(root_url, status_code=200, text=pc_root_text)
api = Client.open(root_url)
pc_collection_dict = read_data_file(
"planetary-computer-aster-l1t-collection.json", parse_json=True
)
requests_mock.get(
f"{root_url}collections", # note the lack of the slash
status_code=200,
json={"collections": [pc_collection_dict], "links": []},
)
_ = next(api.get_collections())
history = requests_mock.request_history
assert len(history) == 2
assert history[1].url == f"{root_url}collections"

def test_custom_request_parameters(self, requests_mock: Mocker) -> None:
pc_root_text = read_data_file("planetary-computer-root.json")
pc_collection_dict = read_data_file(
Expand Down