From 1fb9ca90f645920140609bde6d4ded8046d9902b Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 7 Dec 2022 12:10:50 -0700 Subject: [PATCH 1/3] fix: ensure client self hrefs don't end in '/' --- pystac_client/client.py | 2 ++ tests/test_client.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/pystac_client/client.py b/pystac_client/client.py index 422b4b21..9e0a0112 100644 --- a/pystac_client/client.py +++ b/pystac_client/client.py @@ -132,6 +132,8 @@ def open( Return: catalog : A :class:`Client` instance for this Catalog/API """ + if url.endswith("/"): + url = url[0:-1] client: Client = cls.from_file( url, headers=headers, parameters=parameters, modifier=modifier ) diff --git a/tests/test_client.py b/tests/test_client.py index e563ae4f..ff07a486 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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( From 705bb676fe89c7c89da3e271e54e1a36823fb63c Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Wed, 7 Dec 2022 12:15:25 -0700 Subject: [PATCH 2/3] chore: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b6f6362..cefbb610 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,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) ### Removed From 9a57781d06cfaa92f572e06f7bde0103bb65779e Mon Sep 17 00:00:00 2001 From: Pete Gadomski Date: Mon, 12 Dec 2022 05:13:52 -0700 Subject: [PATCH 3/3] fix: remove multiple `/` characters from url Co-authored-by: Tom Augspurger --- pystac_client/client.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pystac_client/client.py b/pystac_client/client.py index 9e0a0112..c87581dc 100644 --- a/pystac_client/client.py +++ b/pystac_client/client.py @@ -132,8 +132,7 @@ def open( Return: catalog : A :class:`Client` instance for this Catalog/API """ - if url.endswith("/"): - url = url[0:-1] + url = url.rstrip("/") client: Client = cls.from_file( url, headers=headers, parameters=parameters, modifier=modifier )