Skip to content

Commit 8c7effc

Browse files
authored
OGC API: handle URLs with URIs as ids (#964)
* OGC API: handle URLs with URIs as ids * fix tests
1 parent 810c9b4 commit 8c7effc

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

owslib/ogcapi/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,19 @@ def _build_url(self, path: str = None, params: dict = {}) -> str:
129129
@returns: fully constructed URL path
130130
"""
131131

132+
def urljoin_(url2, path2):
133+
if '//' not in path2:
134+
return urljoin(url2, path2)
135+
else:
136+
return '/'.join([url2.rstrip('/'), path2])
137+
132138
url = self.url
133139
if self.url_query_string is not None:
134140
LOGGER.debug('base URL has a query string')
135-
url = urljoin(url, path)
141+
url = urljoin_(url, path)
136142
url = '?'.join([url, self.url_query_string])
137143
else:
138-
url = urljoin(url, path)
144+
url = urljoin_(url, path)
139145

140146
if params:
141147
url = '?'.join([url, urlencode(params)])

tests/test_ogcapi_records_pycsw.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def test_ogcapi_records_pycsw():
4040
assert isinstance(w.response, dict)
4141

4242
pycsw_cite_demo_queryables = w.collection_queryables('metadata:main')
43-
assert len(pycsw_cite_demo_queryables['properties'].keys()) == 13
43+
assert len(pycsw_cite_demo_queryables['properties'].keys()) == 14
4444

4545
# Minimum of limit param is 1
4646
with pytest.raises(RuntimeError):
@@ -67,3 +67,12 @@ def test_ogcapi_records_pycsw():
6767
assert pycsw_cite_demo_query['numberMatched'] == 1
6868
assert pycsw_cite_demo_query['numberReturned'] == 1
6969
assert len(pycsw_cite_demo_query['features']) == 1
70+
71+
72+
@pytest.mark.parametrize("path, expected", [
73+
('collections/foo/1', 'https://demo.pycsw.org/cite/collections/foo/1'),
74+
('collections/foo/https://example.org/11', 'https://demo.pycsw.org/cite/collections/foo/https://example.org/11') # noqa
75+
])
76+
def test_ogcapi_build_url(path, expected):
77+
w = Records(SERVICE_URL)
78+
assert w._build_url(path) == expected

0 commit comments

Comments
 (0)