1
0
mirror of https://github.com/bigchaindb/bigchaindb.git synced 2024-06-14 00:23:22 +02:00

outputs endpoint returns list of objects instead of links

- Updated documentation
- Updated tests
This commit is contained in:
Rodolphe Marques 2017-06-14 12:05:18 +02:00
parent dda6517451
commit 446e454a77
3 changed files with 20 additions and 9 deletions

View File

@ -24,5 +24,5 @@ class OutputListApi(Resource):
with pool() as bigchain:
outputs = bigchain.get_outputs_filtered(args['public_key'],
include_spent)
# NOTE: We pass '..' as a path to create a valid relative URI
return [u.to_uri('..') for u in outputs]
return [{'transaction_id': output.txid, 'output': output.output}
for output in outputs]

View File

@ -176,7 +176,7 @@ not already been spent.
a base58 encoded ed25519 public key associated with transaction output
ownership.
Returns a list of links to transaction outputs.
Returns a list of transaction outputs.
:param public_key: Base58 encoded public key associated with output ownership. This parameter is mandatory and without it the endpoint will return a ``400`` response code.
:param unspent: Boolean value ("true" or "false") indicating if the result set should be limited to outputs that are available to spend. Defaults to "false".
@ -197,8 +197,14 @@ not already been spent.
Content-Type: application/json
[
"../transactions/2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e/outputs/0",
"../transactions/2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e/outputs/1"
{
"output": 0,
"transaction_id": "2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"
},
{
"output": 1,
"transaction_id": "2d431073e1477f3073a4693ac7ff9be5634751de1b8abaa1f4e19548ef0b4b0e"
}
]
:statuscode 200: A list of outputs were found and returned in the body of the response.

View File

@ -8,23 +8,28 @@ OUTPUTS_ENDPOINT = '/api/v1/outputs/'
def test_get_outputs_endpoint(client, user_pk):
m = MagicMock()
m.to_uri.side_effect = lambda s: 'a%sb' % s
m.txid = 'a'
m.output = 0
with patch('bigchaindb.core.Bigchain.get_outputs_filtered') as gof:
gof.return_value = [m, m]
res = client.get(OUTPUTS_ENDPOINT + '?public_key={}'.format(user_pk))
assert res.json == ['a..b', 'a..b']
assert res.json == [
{'transaction_id': 'a', 'output': 0},
{'transaction_id': 'a', 'output': 0}
]
assert res.status_code == 200
gof.assert_called_once_with(user_pk, True)
def test_get_outputs_endpoint_unspent(client, user_pk):
m = MagicMock()
m.to_uri.side_effect = lambda s: 'a%sb' % s
m.txid = 'a'
m.output = 0
with patch('bigchaindb.core.Bigchain.get_outputs_filtered') as gof:
gof.return_value = [m]
params = '?unspent=true&public_key={}'.format(user_pk)
res = client.get(OUTPUTS_ENDPOINT + params)
assert res.json == ['a..b']
assert res.json == [{'transaction_id': 'a', 'output': 0}]
assert res.status_code == 200
gof.assert_called_once_with(user_pk, False)