From ce605f0f40f6a308cc709b5864331ac94ad031cd Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Sun, 22 Dec 2024 13:24:31 -0500 Subject: [PATCH] OGC API: handle URLs with URIs as ids --- owslib/ogcapi/__init__.py | 10 ++++++++-- tests/test_ogcapi_records_pycsw.py | 9 +++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/owslib/ogcapi/__init__.py b/owslib/ogcapi/__init__.py index d34785c2..014475ce 100644 --- a/owslib/ogcapi/__init__.py +++ b/owslib/ogcapi/__init__.py @@ -129,13 +129,19 @@ def _build_url(self, path: str = None, params: dict = {}) -> str: @returns: fully constructed URL path """ + def urljoin_(url2, path2): + if '//' not in path2: + return urljoin(url2, path2) + else: + return '/'.join([url2.rstrip('/'), path2]) + url = self.url if self.url_query_string is not None: LOGGER.debug('base URL has a query string') - url = urljoin(url, path) + url = urljoin_(url, path) url = '?'.join([url, self.url_query_string]) else: - url = urljoin(url, path) + url = urljoin_(url, path) if params: url = '?'.join([url, urlencode(params)]) diff --git a/tests/test_ogcapi_records_pycsw.py b/tests/test_ogcapi_records_pycsw.py index db39aac6..e4ab3a64 100644 --- a/tests/test_ogcapi_records_pycsw.py +++ b/tests/test_ogcapi_records_pycsw.py @@ -67,3 +67,12 @@ def test_ogcapi_records_pycsw(): assert pycsw_cite_demo_query['numberMatched'] == 1 assert pycsw_cite_demo_query['numberReturned'] == 1 assert len(pycsw_cite_demo_query['features']) == 1 + + +@pytest.mark.parametrize("path, expected", [ + ('collections/foo/1', 'https://demo.pycsw.org/cite/collections/foo/1'), + ('collections/foo/https://example.org/11', 'https://demo.pycsw.org/cite/collections/foo/https://example.org/11') # noqa +]) +def test_ogcapi_build_url(path, expected): + w = Records(SERVICE_URL) + assert w._build_url(path) == expected