mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-24 14:35:45 +00:00
changed get transaction list api point to use comma separated txids
Signed-off-by: Lorenz Herzberger <lorenzherzberger@gmail.com>
This commit is contained in:
parent
99b5313981
commit
d723f87308
4
Makefile
4
Makefile
@ -75,9 +75,9 @@ lint: check-deps ## Lint the project
|
||||
|
||||
test: check-deps test-unit test-acceptance ## Run unit and acceptance tests
|
||||
|
||||
test-unit: check-deps ## Run all tests once
|
||||
test-unit: check-deps ## Run all tests once or specify a file/test with TEST=tests/file.py::Class::test
|
||||
@$(DC) up -d bdb
|
||||
@$(DC) exec planetmint pytest
|
||||
@$(DC) exec planetmint pytest ${TEST}
|
||||
|
||||
test-unit-watch: check-deps ## Run all tests and wait. Every time you change code, tests will be run again
|
||||
@$(DC) run --rm --no-deps planetmint pytest -f
|
||||
|
||||
@ -263,11 +263,10 @@ class Planetmint(object):
|
||||
def get_transactions(self, txn_ids):
|
||||
return backend.query.get_transactions(self.connection, txn_ids)
|
||||
|
||||
# TODO: change this to asset_ids, check references of function
|
||||
def get_transactions_filtered(self, asset_id, operation=None, last_tx=None):
|
||||
def get_transactions_filtered(self, asset_ids, operation=None, last_tx=None):
|
||||
"""Get a list of transactions filtered on some criteria
|
||||
"""
|
||||
txids = backend.query.get_txids_filtered(self.connection, asset_id,
|
||||
txids = backend.query.get_txids_filtered(self.connection, asset_ids,
|
||||
operation, last_tx)
|
||||
for txid in txids:
|
||||
yield self.get_transaction(txid)
|
||||
|
||||
@ -13,6 +13,13 @@ def valid_txid(txid):
|
||||
return txid.lower()
|
||||
raise ValueError('Invalid hash')
|
||||
|
||||
def valid_txid_list(txids):
|
||||
txids = txids.split(',')
|
||||
r = re.compile('^[a-fA-F0-9]{64}$')
|
||||
valid_txids = list(filter(r.match, txids))
|
||||
if not len(txids) == len(valid_txids):
|
||||
raise ValueError('List contains invalid hash')
|
||||
return [txid.lower() for txid in valid_txids]
|
||||
|
||||
def valid_bool(val):
|
||||
val = val.lower()
|
||||
|
||||
@ -47,7 +47,7 @@ class TransactionListApi(Resource):
|
||||
def get(self):
|
||||
parser = reqparse.RequestParser()
|
||||
parser.add_argument('operation', type=parameters.valid_operation)
|
||||
parser.add_argument('asset_id', type=parameters.valid_txid,
|
||||
parser.add_argument('asset_ids', type=parameters.valid_txid_list,
|
||||
required=True)
|
||||
parser.add_argument('last_tx', type=parameters.valid_bool,
|
||||
required=False)
|
||||
|
||||
@ -369,24 +369,24 @@ def test_transactions_get_list_good(client):
|
||||
return [type('', (), {'to_dict': partial(lambda a: a, arg)})
|
||||
for arg in sorted(args.items())]
|
||||
|
||||
asset_id = '1' * 64
|
||||
asset_ids = ['1' * 64]
|
||||
|
||||
with patch('planetmint.Planetmint.get_transactions_filtered', get_txs_patched):
|
||||
url = TX_ENDPOINT + '?asset_id=' + asset_id
|
||||
url = TX_ENDPOINT + '?asset_ids=' + ','.join(asset_ids)
|
||||
assert client.get(url).json == [
|
||||
['asset_id', asset_id],
|
||||
['asset_ids', asset_ids],
|
||||
['last_tx', None],
|
||||
['operation', None]
|
||||
]
|
||||
url = TX_ENDPOINT + '?asset_id=' + asset_id + '&operation=CREATE'
|
||||
url = TX_ENDPOINT + '?asset_ids=' + ','.join(asset_ids) + '&operation=CREATE'
|
||||
assert client.get(url).json == [
|
||||
['asset_id', asset_id],
|
||||
['asset_ids', asset_ids],
|
||||
['last_tx', None],
|
||||
['operation', 'CREATE']
|
||||
]
|
||||
url = TX_ENDPOINT + '?asset_id=' + asset_id + '&last_tx=true'
|
||||
url = TX_ENDPOINT + '?asset_ids=' + ','.join(asset_ids) + '&last_tx=true'
|
||||
assert client.get(url).json == [
|
||||
['asset_id', asset_id],
|
||||
['asset_ids', asset_ids],
|
||||
['last_tx', True],
|
||||
['operation', None]
|
||||
]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user