tests for informational endpoints

This commit is contained in:
Scott Sadler 2017-01-06 14:45:38 +01:00
parent 80f3bb3809
commit 990d863dc7
2 changed files with 38 additions and 19 deletions

View File

@ -10,7 +10,16 @@ from bigchaindb import version
class RootIndex(Resource): class RootIndex(Resource):
def get(self): 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({ return flask.jsonify({
'_links': {
'docs': ''.join(docs_url),
'api_v1': api_v1_url,
},
'software': 'BigchainDB', 'software': 'BigchainDB',
'version': version.__version__, 'version': version.__version__,
'public_key': bigchaindb.config['keypair']['public'], 'public_key': bigchaindb.config['keypair']['public'],
@ -21,16 +30,16 @@ class RootIndex(Resource):
class ApiV1Index(Resource): class ApiV1Index(Resource):
def get(self): def get(self):
api_root = base_url() + 'api/v1/' api_root = base_url() + 'api/v1/'
docs_url = ['https://docs.bigchaindb.com/projects/server/en/', docs_url = [
'https://docs.bigchaindb.com/projects/server/en/',
version.__short_version__, version.__short_version__,
'/drivers-clients/http-client-server-api.html', '/drivers-clients/http-client-server-api.html',
] ]
return { return {
"_links": { "_links": {
"docs": {"href": ''.join(docs_url)}, "docs": ''.join(docs_url),
"self": {"href": api_root}, "self": api_root,
"statuses": {"href": api_root + "statuses/"}, "statuses": api_root + "statuses/",
"transactions": {"href": api_root + "transactions/"}, "transactions": api_root + "transactions/",
}, },
} }

View File

@ -1,15 +1,25 @@
from unittest import mock from unittest import mock
def test_api_root_url_shows_basic_info(client): @mock.patch('bigchaindb.version.__short_version__', 'tst')
from bigchaindb import version @mock.patch('bigchaindb.version.__version__', 'tsttst')
@mock.patch('bigchaindb.config', {'keyring': ['abc'], 'keypair': {'public': 'def'}})
def test_api_root_endpoint(client):
res = client.get('/') res = client.get('/')
assert res.json['software'] == 'BigchainDB' assert res.json == {
assert res.json['version'] == version.__version__ '_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): 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/', docs_url = ['https://docs.bigchaindb.com/projects/server/en/',
'tst', 'tst',
@ -17,9 +27,9 @@ def test_api_v1_endpoint(client):
] ]
assert res.json == { assert res.json == {
'_links': { '_links': {
'docs': {'href': ''.join(docs_url)}, 'docs': ''.join(docs_url),
'self': {'href': 'http://localhost/api/v1/'}, 'self': 'http://localhost/api/v1/',
'statuses': {'href': 'http://localhost/api/v1/statuses/'}, 'statuses': 'http://localhost/api/v1/statuses/',
'transactions': {'href': 'http://localhost/api/v1/transactions/'} 'transactions': 'http://localhost/api/v1/transactions/',
} }
} }