diff --git a/bigchaindb/web/views/info.py b/bigchaindb/web/views/info.py index 4b0b3f0b..98e061b6 100644 --- a/bigchaindb/web/views/info.py +++ b/bigchaindb/web/views/info.py @@ -10,7 +10,16 @@ from bigchaindb import version class RootIndex(Resource): def get(self): + docs_url = [ + 'https://docs.bigchaindb.com/projects/server/en/', + version.__short_version__ + '/' + ] + api_v1_url = base_url() + 'api/v1/' return flask.jsonify({ + '_links': { + 'docs': ''.join(docs_url), + 'api_v1': api_v1_url, + }, 'software': 'BigchainDB', 'version': version.__version__, 'public_key': bigchaindb.config['keypair']['public'], @@ -21,16 +30,16 @@ class RootIndex(Resource): class ApiV1Index(Resource): def get(self): api_root = base_url() + 'api/v1/' - docs_url = ['https://docs.bigchaindb.com/projects/server/en/', - version.__short_version__, - '/drivers-clients/http-client-server-api.html', - ] - + docs_url = [ + 'https://docs.bigchaindb.com/projects/server/en/', + version.__short_version__, + '/drivers-clients/http-client-server-api.html', + ] return { "_links": { - "docs": {"href": ''.join(docs_url)}, - "self": {"href": api_root}, - "statuses": {"href": api_root + "statuses/"}, - "transactions": {"href": api_root + "transactions/"}, + "docs": ''.join(docs_url), + "self": api_root, + "statuses": api_root + "statuses/", + "transactions": api_root + "transactions/", }, } diff --git a/tests/web/test_info.py b/tests/web/test_info.py index be753ed0..93b39390 100644 --- a/tests/web/test_info.py +++ b/tests/web/test_info.py @@ -1,25 +1,35 @@ from unittest import mock -def test_api_root_url_shows_basic_info(client): - from bigchaindb import version +@mock.patch('bigchaindb.version.__short_version__', 'tst') +@mock.patch('bigchaindb.version.__version__', 'tsttst') +@mock.patch('bigchaindb.config', {'keyring': ['abc'], 'keypair': {'public': 'def'}}) +def test_api_root_endpoint(client): res = client.get('/') - assert res.json['software'] == 'BigchainDB' - assert res.json['version'] == version.__version__ + assert res.json == { + '_links': { + 'docs': 'https://docs.bigchaindb.com/projects/server/en/tst/', + 'api_v1': 'http://localhost/api/v1/', + }, + 'version': 'tsttst', + 'keyring': ['abc'], + 'public_key': 'def', + 'software': 'BigchainDB', + } +@mock.patch('bigchaindb.version.__short_version__', 'tst') def test_api_v1_endpoint(client): - with mock.patch('bigchaindb.version.__short_version__', 'tst'): - res = client.get('/api/v1') + res = client.get('/api/v1') docs_url = ['https://docs.bigchaindb.com/projects/server/en/', 'tst', '/drivers-clients/http-client-server-api.html', ] assert res.json == { '_links': { - 'docs': {'href': ''.join(docs_url)}, - 'self': {'href': 'http://localhost/api/v1/'}, - 'statuses': {'href': 'http://localhost/api/v1/statuses/'}, - 'transactions': {'href': 'http://localhost/api/v1/transactions/'} + 'docs': ''.join(docs_url), + 'self': 'http://localhost/api/v1/', + 'statuses': 'http://localhost/api/v1/statuses/', + 'transactions': 'http://localhost/api/v1/transactions/', } }