mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
include _links in transaction status payload
This commit is contained in:
parent
7124adcd34
commit
8fa231c040
@ -1,4 +1,4 @@
|
||||
"""This module provides the blueprint for some basic API endpoints.
|
||||
"""This module provides the blueprint for the statuses API endpoints.
|
||||
|
||||
For more information please refer to the documentation on ReadTheDocs:
|
||||
- https://docs.bigchaindb.com/projects/server/en/latest/drivers-clients/
|
||||
@ -28,18 +28,35 @@ class StatusApi(Resource):
|
||||
return make_error(400, "Provide exactly one query parameter. Choices are: block_id, tx_id")
|
||||
|
||||
pool = current_app.config['bigchain_pool']
|
||||
status = None
|
||||
status, links = None, None
|
||||
|
||||
with pool() as bigchain:
|
||||
if args['tx_id']:
|
||||
status = bigchain.get_status(args['tx_id'])
|
||||
links = {
|
||||
"_links": {
|
||||
"tx": "/transactions/{}".format(args['tx_id'])
|
||||
}
|
||||
}
|
||||
|
||||
elif args['block_id']:
|
||||
block = bigchain.get_block(block_id=args['block_id'])
|
||||
if not block:
|
||||
return make_error(404)
|
||||
status = bigchain.block_election_status(block['id'], block['block']['voters'])
|
||||
# TODO: enable once blocks endpoint is available
|
||||
# links = {
|
||||
# "block": "/blocks/{}".format(args['block_id'])
|
||||
# }
|
||||
|
||||
if not status:
|
||||
return make_error(404)
|
||||
|
||||
return {'status': status}
|
||||
response = {
|
||||
'status': status
|
||||
}
|
||||
|
||||
if links:
|
||||
response.update(links)
|
||||
|
||||
return response
|
||||
|
@ -12,6 +12,7 @@ def test_get_transaction_status_endpoint(b, client, user_pk):
|
||||
tx, status = b.get_transaction(input_tx.txid, include_status=True)
|
||||
res = client.get(STATUSES_ENDPOINT + "?tx_id=" + input_tx.txid)
|
||||
assert status == res.json['status']
|
||||
assert res.json['_links']['tx'] == "/transactions/{}".format(input_tx.txid)
|
||||
assert res.status_code == 200
|
||||
|
||||
|
||||
@ -33,6 +34,7 @@ def test_get_block_status_endpoint_undecided(b, client):
|
||||
|
||||
res = client.get(STATUSES_ENDPOINT + "?block_id=" + block.id)
|
||||
assert status == res.json['status']
|
||||
assert '_links' not in res.json
|
||||
assert res.status_code == 200
|
||||
|
||||
|
||||
@ -53,6 +55,7 @@ def test_get_block_status_endpoint_valid(b, client):
|
||||
|
||||
res = client.get(STATUSES_ENDPOINT + "?block_id=" + block.id)
|
||||
assert status == res.json['status']
|
||||
assert '_links' not in res.json
|
||||
assert res.status_code == 200
|
||||
|
||||
|
||||
@ -73,6 +76,7 @@ def test_get_block_status_endpoint_invalid(b, client):
|
||||
|
||||
res = client.get(STATUSES_ENDPOINT + "?block_id=" + block.id)
|
||||
assert status == res.json['status']
|
||||
assert '_links' not in res.json
|
||||
assert res.status_code == 200
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user