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):
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/",
},
}

View File

@ -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/',
}
}