clean up use of double quotes, rename UNSPENTS_ENDPOINT, clarify test

This commit is contained in:
Scott Sadler 2017-01-24 12:08:55 +01:00
parent 897ffe81bc
commit af23ff5b65
2 changed files with 12 additions and 12 deletions

View File

@ -1163,8 +1163,8 @@ def test_get_owned_ids_calls_get_outputs_filtered():
from bigchaindb.core import Bigchain
with patch('bigchaindb.core.Bigchain.get_outputs_filtered') as gof:
b = Bigchain()
res = b.get_owned_ids("abc")
gof.assert_called_once_with("abc", include_spent=False)
res = b.get_owned_ids('abc')
gof.assert_called_once_with('abc', include_spent=False)
assert res == gof()

View File

@ -3,40 +3,40 @@ from unittest.mock import MagicMock, patch
pytestmark = [pytest.mark.bdb, pytest.mark.usefixtures('inputs')]
UNSPENTS_ENDPOINT = '/api/v1/outputs/'
OUTPUTS_ENDPOINT = '/api/v1/outputs/'
def test_get_outputs_endpoint(client, user_pk):
m = MagicMock()
m.to_uri.side_effect = lambda s: s
m.to_uri.side_effect = lambda s: 'a%sb' % s
with patch('bigchaindb.core.Bigchain.get_outputs_filtered') as gof:
gof.return_value = [m, m]
res = client.get(UNSPENTS_ENDPOINT + '?public_key={}'.format(user_pk))
assert res.json == ["..", ".."]
res = client.get(OUTPUTS_ENDPOINT + '?public_key={}'.format(user_pk))
assert res.json == ['a..b', 'a..b']
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: s
m.to_uri.side_effect = lambda s: 'a%sb' % s
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(UNSPENTS_ENDPOINT + params)
assert res.json == [".."]
res = client.get(OUTPUTS_ENDPOINT + params)
assert res.json == ['a..b']
assert res.status_code == 200
gof.assert_called_once_with(user_pk, False)
def test_get_outputs_endpoint_without_public_key(client):
res = client.get(UNSPENTS_ENDPOINT)
res = client.get(OUTPUTS_ENDPOINT)
assert res.status_code == 400
def test_get_outputs_endpoint_with_invalid_public_key(client):
expected = {'message': {'public_key': 'Invalid base58 ed25519 key'}}
res = client.get(UNSPENTS_ENDPOINT + '?public_key=abc')
res = client.get(OUTPUTS_ENDPOINT + '?public_key=abc')
assert expected == res.json
assert res.status_code == 400
@ -44,6 +44,6 @@ def test_get_outputs_endpoint_with_invalid_public_key(client):
def test_get_outputs_endpoint_with_invalid_unspent(client, user_pk):
expected = {'message': {'unspent': 'Boolean value must be "true" or "false" (lowercase)'}}
params = '?unspent=tru&public_key={}'.format(user_pk)
res = client.get(UNSPENTS_ENDPOINT + params)
res = client.get(OUTPUTS_ENDPOINT + params)
assert expected == res.json
assert res.status_code == 400