Skip to content

Commit

Permalink
OGC API: handle URLs with URIs as ids
Browse files Browse the repository at this point in the history
  • Loading branch information
tomkralidis committed Dec 22, 2024
1 parent 810c9b4 commit ce605f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
10 changes: 8 additions & 2 deletions owslib/ogcapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
Expand Down
9 changes: 9 additions & 0 deletions tests/test_ogcapi_records_pycsw.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ce605f0

Please sign in to comment.