1
0
mirror of https://github.com/bigchaindb/bigchaindb.git synced 2024-06-10 11:35:16 +02:00
bigchaindb/tests/web/test_basic_views.py

53 lines
1.7 KiB
Python
Raw Normal View History

2016-02-24 02:38:30 +01:00
import json
2016-02-23 03:37:33 +01:00
import pytest
2016-02-24 02:38:30 +01:00
from bigchaindb import crypto
from bigchaindb import util
2016-02-23 03:37:33 +01:00
2016-02-29 18:28:04 +01:00
TX_ENDPOINT = '/api/v1/transactions/'
2016-02-23 03:37:33 +01:00
@pytest.mark.usefixtures('inputs')
2016-04-06 16:21:35 +02:00
def test_get_transaction_endpoint(b, client, user_vk):
input_tx = b.get_owned_ids(user_vk).pop()
tx = b.get_transaction(input_tx['txid'])
res = client.get(TX_ENDPOINT + input_tx['txid'])
2016-02-23 03:37:33 +01:00
assert tx == res.json
2016-02-24 02:38:30 +01:00
2016-06-08 18:39:40 +02:00
@pytest.mark.usefixtures('inputs')
def test_get_transaction_returns_404_if_not_found(client):
res = client.get(TX_ENDPOINT + '123')
assert res.status_code == 404
def test_api_endpoint_shows_basic_info(client):
from bigchaindb import version
res = client.get('/')
assert res.json['software'] == 'BigchainDB'
assert res.json['version'] == version.__version__
2016-02-24 02:38:30 +01:00
def test_post_create_transaction_endpoint(b, client):
keypair = crypto.generate_key_pair()
tx = util.create_and_sign_tx(keypair[0], keypair[1], keypair[1], None, 'CREATE')
2016-02-29 18:28:04 +01:00
res = client.post(TX_ENDPOINT, data=json.dumps(tx))
2016-04-08 15:56:51 +02:00
assert res.json['transaction']['fulfillments'][0]['current_owners'][0] == b.me
assert res.json['transaction']['conditions'][0]['new_owners'][0] == keypair[1]
2016-02-24 02:38:30 +01:00
2016-04-08 15:56:51 +02:00
@pytest.mark.usefixtures('inputs')
def test_post_transfer_transaction_endpoint(b, client, user_vk, user_sk):
2016-02-24 02:38:30 +01:00
to_keypair = crypto.generate_key_pair()
2016-04-08 15:56:51 +02:00
input_valid = b.get_owned_ids(user_vk).pop()
2016-02-24 02:38:30 +01:00
transfer = util.create_and_sign_tx(user_sk, user_vk, to_keypair[1], input_valid)
2016-02-29 18:28:04 +01:00
res = client.post(TX_ENDPOINT, data=json.dumps(transfer))
2016-02-24 02:38:30 +01:00
2016-04-08 15:56:51 +02:00
assert res.json['transaction']['fulfillments'][0]['current_owners'][0] == user_vk
assert res.json['transaction']['conditions'][0]['new_owners'][0] == to_keypair[1]
2016-02-24 02:38:30 +01:00