Skip to content

Commit 931c1da

Browse files
committed
enh: add `CKANAPI.hostname
1 parent 0ecc537 commit 931c1da

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
0.17.5
22
- fix: error handling when connection to server fails on download (#75)
3+
- enh: add `CKANAPI.hostname`
34
0.17.4
45
- fix: correctly handle dataset IDs and names in `DBExtract`
56
- fix: `get_datasets_user_shared` failed when many circles/collections exist

dcoraid/api/ckan_api.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import functools
55
import json
66
import logging
7+
import numbers
78
import pathlib
89
import traceback
9-
import numbers
10+
import urllib.parse
11+
1012

1113
from dclab.external.packaging import parse as parse_version
1214
import requests
@@ -111,6 +113,11 @@ def ckan_version_object(self):
111113
version_act = self.get("status_show")["ckan_version"]
112114
return parse_version(version_act)
113115

116+
@property
117+
def hostname(self):
118+
"""Hostname (server without "htttps://" prepended)"""
119+
return urllib.parse.urlparse(self.server).hostname
120+
114121
@property
115122
def user_name(self):
116123
return self._get_user_data().get("name")

tests/test_api_base.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,15 @@ def test_api_server_name(server, api_server):
6565
check_ckan_version=False)
6666
assert api.server == api_server
6767
assert api.api_url.startswith(api_server)
68+
69+
70+
@pytest.mark.parametrize("server,api_hostname", [
71+
("http://localhost:5000", "localhost"),
72+
("https://localhost:5000", "localhost"),
73+
("localhost:5000", "localhost"),
74+
("https://dcor.mpl.mpg.de", "dcor.mpl.mpg.de"),
75+
])
76+
def test_api_hostname(server, api_hostname):
77+
api = ckan_api.CKANAPI(server=server,
78+
check_ckan_version=False)
79+
assert api.hostname == api_hostname

0 commit comments

Comments
 (0)