Integrate api GET "/transactions?asset_id={asset_id}&operation="

This commit is contained in:
kansi 2017-11-16 16:52:30 +05:30 committed by Sylvain Bellemare
parent 13b3d6b464
commit 95c0f267e0
7 changed files with 45 additions and 3 deletions

View File

@ -7,7 +7,7 @@ if [[ -n ${TOXENV} ]]; then
elif [[ "${BIGCHAINDB_DATABASE_BACKEND}" == localmongodb && \
-z "${BIGCHAINDB_DATABASE_SSL}" ]]; then
# Run the full suite of tests for MongoDB over an unsecure connection
pytest -sv --database-backend=localmongodb --cov=bigchaindb
pytest -sv --database-backend=localmongodb --cov=bigchaindb -m tendermint
elif [[ "${BIGCHAINDB_DATABASE_BACKEND}" == localmongodb && \
"${BIGCHAINDB_DATABASE_SSL}" == true ]]; then
# Run a sub-set of tests over SSL; those marked as 'pytest.mark.bdb_ssl'.

View File

@ -1,10 +1,12 @@
"""Query implementation for MongoDB"""
from pymongo import DESCENDING
from bigchaindb import backend
from bigchaindb.backend.exceptions import DuplicateKeyError
from bigchaindb.backend.utils import module_dispatch_registrar
from bigchaindb.backend.localmongodb.connection import LocalMongoDBConnection
from pymongo import DESCENDING
from bigchaindb.common.transaction import Transaction
register_query = module_dispatch_registrar(backend.query)
@ -77,3 +79,30 @@ def store_block(conn, block):
.insert_one(block))
except DuplicateKeyError:
pass
@register_query(LocalMongoDBConnection)
def get_txids_filtered(conn, asset_id, operation=None):
match_create = {
'operation': 'CREATE',
'id': asset_id
}
match_transfer = {
'operation': 'TRANSFER',
'id': asset_id
}
if operation == Transaction.CREATE:
match = match_create
elif operation == Transaction.TRANSFER:
match = match_transfer
else:
match = {'$or': [match_create, match_transfer]}
pipeline = [
{'$match': match}
]
cursor = conn.run(
conn.collection('transactions')
.aggregate(pipeline))
return (elem['id'] for elem in cursor)

View File

@ -1,3 +1,3 @@
[pytest]
testpaths = tests/tendermint
testpaths = tests/
norecursedirs = .* *.egg *.egg-info env* devenv* docs

View File

@ -1,10 +1,13 @@
import json
import pytest
def encode_tx_to_bytes(transaction):
return json.dumps(transaction.to_dict()).encode('utf8')
@pytest.mark.tendermint
def test_check_tx__signed_create_is_ok(b):
from bigchaindb.tendermint import App
from bigchaindb.models import Transaction
@ -22,6 +25,7 @@ def test_check_tx__signed_create_is_ok(b):
assert result.is_ok()
@pytest.mark.tendermint
def test_check_tx__unsigned_create_is_error(b):
from bigchaindb.tendermint import App
from bigchaindb.models import Transaction
@ -38,6 +42,7 @@ def test_check_tx__unsigned_create_is_error(b):
assert result.is_error()
@pytest.mark.tendermint
def test_deliver_tx__valid_create_updates_db(b):
from bigchaindb.tendermint import App
from bigchaindb.models import Transaction
@ -56,6 +61,7 @@ def test_deliver_tx__valid_create_updates_db(b):
assert b.get_transaction(tx.id).id == tx.id
@pytest.mark.tendermint
def test_deliver_tx__double_spend_fails(b):
from bigchaindb.tendermint import App
from bigchaindb.models import Transaction

View File

@ -7,6 +7,8 @@ from abci.wire import read_message
from abci.messages import to_request_deliver_tx, to_request_check_tx
@pytest.mark.bdb
@pytest.mark.tendermint
def test_app(b):
from bigchaindb.tendermint import App
from bigchaindb.tendermint.utils import calculate_hash

View File

@ -1,8 +1,11 @@
import os
import pytest
from bigchaindb import backend
@pytest.mark.tendermint
def test_asset_is_separated_from_transaciton(b):
from bigchaindb.models import Transaction
from bigchaindb.common.crypto import generate_key_pair

View File

@ -276,6 +276,7 @@ def test_post_invalid_transfer_transaction_returns_400(b, client, user_pk):
assert res.json['message'] == expected_error_message
@pytest.mark.tendermint
def test_transactions_get_list_good(client):
from functools import partial
@ -302,6 +303,7 @@ def test_transactions_get_list_good(client):
]
@pytest.mark.tendermint
def test_transactions_get_list_bad(client):
def should_not_be_called():
assert False