mirror of
https://github.com/planetmint/planetmint.git
synced 2025-11-26 23:45:47 +00:00
fixed assets handling
Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
parent
d3cc8c3c5e
commit
52602ef098
@ -145,26 +145,17 @@ def store_assets(connection, assets: list):
|
|||||||
def get_asset(connection, asset_id: str):
|
def get_asset(connection, asset_id: str):
|
||||||
space = connection.space("assets")
|
space = connection.space("assets")
|
||||||
_data = space.select(asset_id, index="txid_search")
|
_data = space.select(asset_id, index="txid_search")
|
||||||
data1 = _data
|
|
||||||
_data = _data.data
|
_data = _data.data
|
||||||
print(f"DATA : {data1}")
|
return _data[0] if len(_data) > 0 else []
|
||||||
return _data[0] if len(_data) == 1 else []
|
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
def get_assets(connection, assets_ids: list) -> list:
|
def get_assets(connection, assets_ids: list) -> list:
|
||||||
_returned_data = []
|
_returned_data = []
|
||||||
# space = connection.space("assets")
|
|
||||||
for _id in list(set(assets_ids)):
|
for _id in list(set(assets_ids)):
|
||||||
# asset = space.select(str(_id), index="txid_search")
|
|
||||||
# print(f"DATA : {asset}")
|
|
||||||
# if len(asset) == 0:
|
|
||||||
# continue
|
|
||||||
# asset = asset.data[0]
|
|
||||||
asset = get_asset(connection, _id)
|
asset = get_asset(connection, _id)
|
||||||
_returned_data.append(asset)
|
_returned_data.append(tuple(asset))
|
||||||
|
return sorted(_returned_data, key=lambda k: k[0]["id"], reverse=False)
|
||||||
return sorted(_returned_data, key=lambda k: k["id"], reverse=False)
|
|
||||||
|
|
||||||
|
|
||||||
@register_query(TarantoolDB)
|
@register_query(TarantoolDB)
|
||||||
|
|||||||
@ -1261,8 +1261,7 @@ class Transaction(object):
|
|||||||
assets = list(planet.get_assets(tx_ids))
|
assets = list(planet.get_assets(tx_ids))
|
||||||
for asset in assets:
|
for asset in assets:
|
||||||
if asset is not None:
|
if asset is not None:
|
||||||
tx = tx_map[asset['id']]
|
tx = tx_map[asset[1]]
|
||||||
del asset['id']
|
|
||||||
tx['asset'] = asset
|
tx['asset'] = asset
|
||||||
|
|
||||||
tx_ids = list(tx_map.keys())
|
tx_ids = list(tx_map.keys())
|
||||||
|
|||||||
@ -51,11 +51,11 @@ def test_write_assets(db_conn):
|
|||||||
# conn = Connection().get_connection()
|
# conn = Connection().get_connection()
|
||||||
conn = db_conn.get_connection()
|
conn = db_conn.get_connection()
|
||||||
assets = [
|
assets = [
|
||||||
{'id': "1", 'data': '1'},
|
({'id': '1', 'data': '1'}, '1', '1'),
|
||||||
{'id': "2", 'data': '2'},
|
({'id': '2', 'data': '2'}, '2', '2'),
|
||||||
{'id': "3", 'data': '3'},
|
({'id': '3', 'data': '3'}, '3', '3'),
|
||||||
# Duplicated id. Should not be written to the database
|
# Duplicated id. Should not be written to the database
|
||||||
{'id': "1", 'data': '1'},
|
({'id': '1', 'data': '1'}, '1', '1'),
|
||||||
]
|
]
|
||||||
|
|
||||||
# write the assets
|
# write the assets
|
||||||
@ -63,7 +63,7 @@ def test_write_assets(db_conn):
|
|||||||
query.store_asset(connection=conn, asset=asset)
|
query.store_asset(connection=conn, asset=asset)
|
||||||
|
|
||||||
# check that 3 assets were written to the database
|
# check that 3 assets were written to the database
|
||||||
documents = query.get_assets(assets_ids=[asset["id"] for asset in assets], connection=conn)
|
documents = query.get_assets(assets_ids=[asset[2] for asset in assets], connection=conn)
|
||||||
|
|
||||||
assert len(documents) == 3
|
assert len(documents) == 3
|
||||||
assert list(documents) == assets[:-1]
|
assert list(documents) == assets[:-1]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user