diff --git a/annif_client.py b/annif_client.py index c54333a..c610441 100755 --- a/annif_client.py +++ b/annif_client.py @@ -13,6 +13,13 @@ class AnnifClient: def __init__(self, api_base=API_BASE): self.api_base = api_base + @property + def api_info(self): + """Get basic information of the API endpoint""" + req = requests.get(self.api_base) + req.raise_for_status() + return req.json() + @property def projects(self): """Get a list of projects available on the API endpoint""" @@ -74,7 +81,8 @@ def __str__(self): print("* Creating an AnnifClient object") annif = AnnifClient() - print("Now we have an AnnifClient object:", annif) + print(f"* The client uses Annif API at {annif.api_base}") + print(f"* The version of Annif serving the API is {annif.api_info['version']}") print() print("* Finding the available projects") for project in annif.projects: diff --git a/tests/data/api-info.json b/tests/data/api-info.json new file mode 100644 index 0000000..667e74c --- /dev/null +++ b/tests/data/api-info.json @@ -0,0 +1,4 @@ +{ + "title": "Annif REST API", + "version": "0.12.3" +} diff --git a/tests/test_annif_client.py b/tests/test_annif_client.py index bdac89e..a9c830c 100644 --- a/tests/test_annif_client.py +++ b/tests/test_annif_client.py @@ -23,6 +23,17 @@ def test_create_client_api_base(): assert client.api_base == 'http://localhost:5000/v1/' +@responses.activate +def test_api_info(client): + datafile = os.path.join(os.path.dirname(__file__), 'data/api-info.json') + responses.add(responses.GET, + 'https://api.annif.org/v1/', + body=open(datafile).read()) + result = client.api_info + assert result['title'] == 'Annif REST API' + assert result['version'] == '0.12.3' + + @responses.activate def test_projects(client): datafile = os.path.join(os.path.dirname(__file__), 'data/projects.json')