From 563b877af63dc76e969cec3337c0aced4eb920b9 Mon Sep 17 00:00:00 2001 From: aliel Date: Tue, 20 Feb 2024 13:53:43 +0100 Subject: [PATCH] add Tests --- src/aleph/web/controllers/aggregates.py | 4 ++-- tests/api/test_aggregates.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/aleph/web/controllers/aggregates.py b/src/aleph/web/controllers/aggregates.py index 4f38faff2..a40317daf 100644 --- a/src/aleph/web/controllers/aggregates.py +++ b/src/aleph/web/controllers/aggregates.py @@ -19,7 +19,7 @@ class AggregatesQueryParams(BaseModel): keys: Optional[List[str]] = None limit: int = DEFAULT_LIMIT with_info: bool = False - only_value: bool = False + value_only: bool = False @validator( "keys", @@ -68,7 +68,7 @@ async def address_aggregate(request: web.Request) -> web.Response: if not aggregates: raise web.HTTPNotFound(text="No aggregate found for this address") - if query_params.only_value and query_params.keys and len(query_params.keys) == 1: + if query_params.value_only and query_params.keys and len(query_params.keys) == 1: output = {} target_key = query_params.keys[0] for result in aggregates: diff --git a/tests/api/test_aggregates.py b/tests/api/test_aggregates.py index f6826cee4..06ee51a4f 100644 --- a/tests/api/test_aggregates.py +++ b/tests/api/test_aggregates.py @@ -165,3 +165,21 @@ async def test_get_aggregates_invalid_params( errors = await response.json() assert len(errors) == 1 assert errors[0]["loc"] == ["limit"], errors + +@pytest.mark.asyncio +async def test_get_aggregates_return_value_only( + ccn_api_client, fixture_aggregate_messages: Sequence[MessageDb] +): + """ + Should return the value without wrapping (aggregate info) + """ + + assert fixture_aggregate_messages # To avoid unused parameter warnings + + address, key = ADDRESS_1, "test_target" + aggregates = await get_aggregates_expect_success( + ccn_api_client, address=address, keys=key, + with_info=False, value_only="1" + ) + assert address not in aggregates + assert aggregates == EXPECTED_AGGREGATES[address][key]