mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Make votes endpoint return 404 & helpful msg
This commit is contained in:
parent
1aece3c10d
commit
8e4a2398a7
@ -1,27 +1,42 @@
|
|||||||
"""This module provides the blueprint for the votes API endpoints.
|
"""This module provides the blueprint for the votes API endpoints.
|
||||||
|
|
||||||
For more information please refer to the documentation: http://bigchaindb.com/http-api
|
For more information please refer to the documentation: http://bigchaindb.com/http-api
|
||||||
"""
|
|
||||||
from flask import current_app
|
|
||||||
from flask_restful import Resource, reqparse
|
|
||||||
|
|
||||||
from bigchaindb import backend
|
We might bring back a votes API endpoint in the future, see:
|
||||||
|
https://github.com/bigchaindb/bigchaindb/issues/2037
|
||||||
|
"""
|
||||||
|
|
||||||
|
from flask import jsonify
|
||||||
|
from flask_restful import Resource
|
||||||
|
#from flask import current_app
|
||||||
|
#from flask_restful import Resource, reqparse
|
||||||
|
|
||||||
|
#from bigchaindb import backend
|
||||||
|
|
||||||
|
|
||||||
class VotesApi(Resource):
|
class VotesApi(Resource):
|
||||||
def get(self):
|
def get(self):
|
||||||
"""API endpoint to get details about votes on a block.
|
"""API endpoint to get details about votes.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
A list of votes voting for a block with ID ``block_id``.
|
404 Not Found
|
||||||
"""
|
"""
|
||||||
parser = reqparse.RequestParser()
|
#parser = reqparse.RequestParser()
|
||||||
parser.add_argument('block_id', type=str, required=True)
|
#parser.add_argument('block_id', type=str, required=True)
|
||||||
|
|
||||||
args = parser.parse_args(strict=True)
|
#args = parser.parse_args(strict=True)
|
||||||
|
|
||||||
pool = current_app.config['bigchain_pool']
|
#pool = current_app.config['bigchain_pool']
|
||||||
with pool() as bigchain:
|
#with pool() as bigchain:
|
||||||
votes = list(backend.query.get_votes_by_block_id(bigchain.connection, args['block_id']))
|
# votes = list(backend.query.get_votes_by_block_id(bigchain.connection, args['block_id']))
|
||||||
|
|
||||||
|
#return votes
|
||||||
|
|
||||||
return votes
|
# Return an HTTP status code 404 Not Found, which means:
|
||||||
|
# The requested resource could not be found but may be available in the future.
|
||||||
|
|
||||||
|
gone = 'The votes endpoint is gone now, but it might return in the future.'
|
||||||
|
response = jsonify({'message': gone})
|
||||||
|
response.status_code = 404
|
||||||
|
|
||||||
|
return response
|
||||||
|
@ -5,6 +5,29 @@ from bigchaindb.models import Transaction
|
|||||||
VOTES_ENDPOINT = '/api/v1/votes'
|
VOTES_ENDPOINT = '/api/v1/votes'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.tendermint
|
||||||
|
def test_get_votes_endpoint(client):
|
||||||
|
gone = 'The votes endpoint is gone now, but it might return in the future.'
|
||||||
|
response = {'message': gone}
|
||||||
|
|
||||||
|
res = client.get(VOTES_ENDPOINT)
|
||||||
|
assert response == res.json
|
||||||
|
assert res.status_code == 404
|
||||||
|
|
||||||
|
res = client.get(VOTES_ENDPOINT + '?block_id=')
|
||||||
|
assert response == res.json
|
||||||
|
assert res.status_code == 404
|
||||||
|
|
||||||
|
res = client.get(VOTES_ENDPOINT + '?block_id=123')
|
||||||
|
assert response == res.json
|
||||||
|
assert res.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
# Old tests are below. We're keeping their code in a long comment block for now,
|
||||||
|
# because we might bring back a votes endpoint in the future.
|
||||||
|
# https://github.com/bigchaindb/bigchaindb/issues/2037
|
||||||
|
|
||||||
@pytest.mark.bdb
|
@pytest.mark.bdb
|
||||||
@pytest.mark.usefixtures('inputs')
|
@pytest.mark.usefixtures('inputs')
|
||||||
def test_get_votes_endpoint(b, client):
|
def test_get_votes_endpoint(b, client):
|
||||||
@ -73,3 +96,4 @@ def test_get_votes_endpoint_returns_400_bad_query_params(client):
|
|||||||
|
|
||||||
res = client.get(VOTES_ENDPOINT + '?tx_id=123&block_id=123')
|
res = client.get(VOTES_ENDPOINT + '?tx_id=123&block_id=123')
|
||||||
assert res.status_code == 400
|
assert res.status_code == 400
|
||||||
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user