Integrate asset search
This commit is contained in:
parent
00dd16840f
commit
6c3f176122
|
@ -7,7 +7,7 @@ from bigchaindb.backend.exceptions import DuplicateKeyError
|
|||
from bigchaindb.backend.utils import module_dispatch_registrar
|
||||
from bigchaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
from bigchaindb.common.transaction import Transaction
|
||||
|
||||
from bigchaindb.backend import mongodb
|
||||
|
||||
register_query = module_dispatch_registrar(backend.query)
|
||||
|
||||
|
@ -106,3 +106,8 @@ def get_txids_filtered(conn, asset_id, operation=None):
|
|||
conn.collection('transactions')
|
||||
.aggregate(pipeline))
|
||||
return (elem['id'] for elem in cursor)
|
||||
|
||||
|
||||
@register_query(LocalMongoDBConnection)
|
||||
def text_search(*args, **kwargs):
|
||||
return mongodb.query.text_search(*args, **kwargs)
|
||||
|
|
|
@ -72,3 +72,11 @@ def test_get_assets():
|
|||
|
||||
for asset in assets:
|
||||
assert query.get_asset(conn, asset['id'])
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
@pytest.mark.tendermint
|
||||
def test_text_search():
|
||||
from ..mongodb.test_queries import test_text_search
|
||||
|
||||
test_text_search()
|
||||
|
|
|
@ -308,6 +308,12 @@ def b():
|
|||
return Bigchain()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def tb():
|
||||
from bigchaindb.tendermint import BigchainDB
|
||||
return BigchainDB()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def create_tx(b, user_pk):
|
||||
from bigchaindb.models import Transaction
|
||||
|
|
|
@ -65,7 +65,7 @@ def test_app(b):
|
|||
data = p.process('end_block', r)
|
||||
res, err = read_message(BytesIO(data), types.Response)
|
||||
assert res
|
||||
assert 'end_block' == res.WhichOneof("value")
|
||||
assert 'end_block' == res.WhichOneof('value')
|
||||
|
||||
new_block_hash = calculate_hash([block0['app_hash'], new_block_txn_hash])
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ import pytest
|
|||
ASSETS_ENDPOINT = '/api/v1/assets/'
|
||||
|
||||
|
||||
@pytest.mark.tendermint
|
||||
def test_get_assets_with_empty_text_search(client):
|
||||
res = client.get(ASSETS_ENDPOINT + '?search=')
|
||||
assert res.json == {'status': 400,
|
||||
|
@ -10,6 +11,7 @@ def test_get_assets_with_empty_text_search(client):
|
|||
assert res.status_code == 400
|
||||
|
||||
|
||||
@pytest.mark.tendermint
|
||||
def test_get_assets_with_missing_text_search(client):
|
||||
res = client.get(ASSETS_ENDPOINT)
|
||||
assert res.status_code == 400
|
||||
|
@ -81,3 +83,62 @@ def test_get_assets_limit(client, b):
|
|||
res = client.get(ASSETS_ENDPOINT + '?search=abc&limit=1')
|
||||
assert res.status_code == 200
|
||||
assert len(res.json) == 1
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
@pytest.mark.tendermint
|
||||
def test_get_assets_tmint(client, tb):
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
|
||||
if isinstance(tb.connection, LocalMongoDBConnection):
|
||||
# test returns empty list when no assets are found
|
||||
res = client.get(ASSETS_ENDPOINT + '?search=abc')
|
||||
assert res.json == []
|
||||
assert res.status_code == 200
|
||||
|
||||
# create asset
|
||||
asset = {'msg': 'abc'}
|
||||
tx = Transaction.create([tb.me], [([tb.me], 1)],
|
||||
asset=asset).sign([tb.me_private])
|
||||
|
||||
tb.store_transaction(tx)
|
||||
|
||||
# test that asset is returned
|
||||
res = client.get(ASSETS_ENDPOINT + '?search=abc')
|
||||
assert res.status_code == 200
|
||||
assert len(res.json) == 1
|
||||
assert res.json[0] == {
|
||||
'data': {'msg': 'abc'},
|
||||
'id': tx.id
|
||||
}
|
||||
|
||||
|
||||
@pytest.mark.bdb
|
||||
@pytest.mark.tendermint
|
||||
def test_get_assets_limit_tmint(client, tb):
|
||||
from bigchaindb.models import Transaction
|
||||
from bigchaindb.backend.localmongodb.connection import LocalMongoDBConnection
|
||||
|
||||
b = tb
|
||||
if isinstance(b.connection, LocalMongoDBConnection):
|
||||
# create two assets
|
||||
asset1 = {'msg': 'abc 1'}
|
||||
asset2 = {'msg': 'abc 2'}
|
||||
tx1 = Transaction.create([b.me], [([b.me], 1)],
|
||||
asset=asset1).sign([b.me_private])
|
||||
tx2 = Transaction.create([b.me], [([b.me], 1)],
|
||||
asset=asset2).sign([b.me_private])
|
||||
|
||||
b.store_transaction(tx1)
|
||||
b.store_transaction(tx2)
|
||||
|
||||
# test that both assets are returned without limit
|
||||
res = client.get(ASSETS_ENDPOINT + '?search=abc')
|
||||
assert res.status_code == 200
|
||||
assert len(res.json) == 2
|
||||
|
||||
# test that only one asset is returned when using limit=1
|
||||
res = client.get(ASSETS_ENDPOINT + '?search=abc&limit=1')
|
||||
assert res.status_code == 200
|
||||
assert len(res.json) == 1
|
||||
|
|
|
@ -47,8 +47,8 @@ def test_post_create_transaction_endpoint(b, client):
|
|||
assert res.json['outputs'][0]['public_keys'][0] == user_pub
|
||||
|
||||
|
||||
@pytest.mark.parametrize("field", ['asset', 'metadata'])
|
||||
@pytest.mark.parametrize("value,err_key,expected_status_code", [
|
||||
@pytest.mark.parametrize('field', ['asset', 'metadata'])
|
||||
@pytest.mark.parametrize('value,err_key,expected_status_code', [
|
||||
({'bad.key': 'v'}, 'bad.key', 400),
|
||||
({'$bad.key': 'v'}, '$bad.key', 400),
|
||||
({'$badkey': 'v'}, '$badkey', 400),
|
||||
|
|
Loading…
Reference in New Issue