Fix syntax.

This commit is contained in:
maoudia 2020-05-06 22:05:55 -04:00
parent ac16183979
commit 1939947164
3 changed files with 23 additions and 23 deletions

View File

@ -38,8 +38,8 @@ ROUTES_API_V1 = [
r('transactions/<string:tx_id>', tx.TransactionApi),
r('transactions', tx.TransactionListApi),
r('outputs/', outputs.OutputListApi),
r('query-assets/', assets.AssetQueryApi),
r('aggregate-assets/', assets.AssetAggregateApi),
r('assets/query/', assets.AssetQueryApi),
r('assets/aggregate/', assets.AssetAggregateApi),
r('validators/', validators.ValidatorsApi),
]

View File

@ -6,7 +6,7 @@ import pytest
import json
import urllib.parse
AGGREGATE_ASSETS_ENDPOINT = '/api/v1/aggregate-assets/'
AGGREGATE_ASSETS_ENDPOINT = '/api/v1/assets/aggregate'
def insert_aggregation_assets(b, alice):
@ -19,18 +19,12 @@ def insert_aggregation_assets(b, alice):
asset6 = {'msg': 'BigchainDB 3', 'complex_key': {'complex_sub_key': 'value_6', 'aggregation_key': 'ak_3'}}
# create the transactions
tx1 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
asset=asset1).sign([alice.private_key])
tx2 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
asset=asset2).sign([alice.private_key])
tx3 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
asset=asset3).sign([alice.private_key])
tx4 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
asset=asset4).sign([alice.private_key])
tx5 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
asset=asset5).sign([alice.private_key])
tx6 = Transaction.create([alice.public_key], [([alice.public_key], 1)],
asset=asset6).sign([alice.private_key])
tx1 = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset=asset1).sign([alice.private_key])
tx2 = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset=asset2).sign([alice.private_key])
tx3 = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset=asset3).sign([alice.private_key])
tx4 = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset=asset4).sign([alice.private_key])
tx5 = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset=asset5).sign([alice.private_key])
tx6 = Transaction.create([alice.public_key], [([alice.public_key], 1)], asset=asset6).sign([alice.private_key])
# write the transactions to the DB
b.store_bulk_transactions([tx1, tx2, tx3, tx4, tx5, tx6])
@ -39,16 +33,21 @@ def insert_aggregation_assets(b, alice):
@pytest.mark.bdb
def test_aggregate_assets_with_query(client, b, alice):
insert_aggregation_assets(b, alice)
aggregation_functions = {'function_list': [{'$group': {'_id': "$data.complex_key.aggregation_key", 'count': {'$sum': 1}}}]}
res = client.get(AGGREGATE_ASSETS_ENDPOINT + f"?aggregation_functions={urllib.parse.quote(json.dumps(aggregation_functions))}")
aggregation_functions = {'function_list':
[{'$group': {'_id': "$data.complex_key.aggregation_key", 'count': {'$sum': 1}}}]}
res = client.get(AGGREGATE_ASSETS_ENDPOINT +
f"?aggregation_functions={urllib.parse.quote(json.dumps(aggregation_functions))}")
assert res.json == json.dumps({"results": [{'_id': 'ak_3', 'count': 3},
{'_id': 'ak_2', 'count': 1},
{'_id': 'ak_1', 'count': 2}]})
assert res.status_code == 200
@pytest.mark.bdb
def test_aggregate_assets_with_invalid_query(client, b, alice):
insert_aggregation_assets(b, alice)
aggregation_functions = {'something': [{'$group': {'_id': "$data.complex_key.aggregation_key", 'count': {'$sum': 1}}}]}
res = client.get(AGGREGATE_ASSETS_ENDPOINT + f"?aggregation_functions={urllib.parse.quote(json.dumps(aggregation_functions))}")
assert res.status_code == 400
aggregation_functions = {'something':
[{'$group': {'_id': "$data.complex_key.aggregation_key", 'count': {'$sum': 1}}}]}
res = client.get(AGGREGATE_ASSETS_ENDPOINT +
f"?aggregation_functions={urllib.parse.quote(json.dumps(aggregation_functions))}")
assert res.status_code == 400

View File

@ -6,7 +6,8 @@ import pytest
import json
import urllib.parse
QUERY_ASSETS_ENDPOINT = '/api/v1/query-assets/'
QUERY_ASSETS_ENDPOINT = '/api/v1/assets/query'
@pytest.mark.bdb
def test_query_assets_with_query(client, b, alice):
@ -27,6 +28,7 @@ def test_query_assets_with_query(client, b, alice):
assert json.loads(res.json)[0]["data"] == {'msg': 'abc 1'}
assert res.status_code == 200
@pytest.mark.bdb
def test_query_assets_with_empty_query(client, b, alice):
from bigchaindb.models import Transaction
@ -83,10 +85,9 @@ def test_query_assets_with_empty_query_limit_0(client, b, alice):
b.store_bulk_transactions([tx1])
b.store_bulk_transactions([tx2])
res = client.get(QUERY_ASSETS_ENDPOINT + '?limit=0'+ f"&query={urllib.parse.quote(json.dumps({}))}")
res = client.get(QUERY_ASSETS_ENDPOINT + '?limit=0' + f"&query={urllib.parse.quote(json.dumps({}))}")
print(res.json)
assert len(json.loads(res.json)) == 2
assert json.loads(res.json)[0]["data"] == {'msg': 'abc 1'}
assert json.loads(res.json)[1]["data"] == {'msg': 'abc 2'}
assert res.status_code == 200