mirror of
https://github.com/bigchaindb/bigchaindb.git
synced 2024-10-13 13:34:05 +00:00
Add unspents endpoint
This commit is contained in:
parent
f78c90ada8
commit
8e8bc90742
32
bigchaindb/web/views/unspents.py
Normal file
32
bigchaindb/web/views/unspents.py
Normal file
@ -0,0 +1,32 @@
|
||||
from flask import current_app, Blueprint
|
||||
from flask_restful import reqparse, Resource, Api
|
||||
|
||||
|
||||
unspent_views = Blueprint('unspent_views', __name__)
|
||||
unspent_api = Api(unspent_views)
|
||||
|
||||
|
||||
class UnspentListApi(Resource):
|
||||
def get(self):
|
||||
"""API endpoint to retrieve a list of links to transactions's
|
||||
conditions that have not been used in any previous transaction.
|
||||
|
||||
Returns:
|
||||
A :obj:`list` of :cls:`str` of links to unfulfilled conditions.
|
||||
"""
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('owner_after', type=str, location='args',
|
||||
required=True)
|
||||
args = parser.parse_args()
|
||||
|
||||
pool = current_app.config['bigchain_pool']
|
||||
|
||||
with pool() as bigchain:
|
||||
unspents = bigchain.get_owned_ids(args['owner_after'])
|
||||
# NOTE: We pass '..' as a path to create a valid relative URI
|
||||
return [u.to_uri('..') for u in unspents]
|
||||
|
||||
|
||||
unspent_api.add_resource(UnspentListApi,
|
||||
'/unspents/',
|
||||
strict_slashes=False)
|
26
tests/web/test_unspents.py
Normal file
26
tests/web/test_unspents.py
Normal file
@ -0,0 +1,26 @@
|
||||
import pytest
|
||||
|
||||
|
||||
UNSPENTS_ENDPOINT = '/api/v1/unspents/'
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_get_unspents_endpoint(b, client, user_vk):
|
||||
expected = [u.to_uri('..') for u in b.get_owned_ids(user_vk)]
|
||||
res = client.get(UNSPENTS_ENDPOINT + '?owner_after={}'.format(user_vk))
|
||||
assert expected == res.json
|
||||
assert res.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_get_unspents_endpoint_without_owner_after(client):
|
||||
res = client.get(UNSPENTS_ENDPOINT)
|
||||
assert res.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('inputs')
|
||||
def test_get_unspents_endpoint_with_unused_owner_after(client):
|
||||
expected = []
|
||||
res = client.get(UNSPENTS_ENDPOINT + '?owner_after=abc')
|
||||
assert expected == res.json
|
||||
assert res.status_code == 200
|
Loading…
x
Reference in New Issue
Block a user