Skip to content

Commit

Permalink
outputs endpoint returns list of objects instead of links
Browse files Browse the repository at this point in the history
- Updated documentation
- Updated tests
  • Loading branch information
r-marques committed Jun 16, 2017
1 parent dda6517 commit 446e454
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
4 changes: 2 additions & 2 deletions bigchaindb/web/views/outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def get(self):
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]
12 changes: 9 additions & 3 deletions docs/server/source/http-client-server-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand All @@ -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.
Expand Down
13 changes: 9 additions & 4 deletions tests/web/test_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,28 @@

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)

Expand Down

0 comments on commit 446e454

Please sign in to comment.