Skip to content

OGC API: handle URLs with URIs as ids #964

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

Merged
merged 2 commits into from
Dec 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
Loading