From ff3efb782264f3bf24d30ee973f34aa78320761a Mon Sep 17 00:00:00 2001 From: aliel Date: Mon, 19 Feb 2024 17:19:29 +0100 Subject: [PATCH] Fix regression introduced by (#473) * Fix aggregate filter by keys --- src/aleph/web/controllers/aggregates.py | 14 ++++++-------- tests/api/test_aggregates.py | 3 ++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/aleph/web/controllers/aggregates.py b/src/aleph/web/controllers/aggregates.py index 8c77e2dfa..73360b1d7 100644 --- a/src/aleph/web/controllers/aggregates.py +++ b/src/aleph/web/controllers/aggregates.py @@ -1,16 +1,13 @@ import datetime as dt import logging -from typing import List, Optional, Dict +from typing import Dict, List, Optional from aiohttp import web -from pydantic import BaseModel, validator, ValidationError +from aleph.db.accessors.aggregates import get_aggregates_by_owner, refresh_aggregate +from aleph.db.models import AggregateDb +from pydantic import BaseModel, ValidationError, validator from sqlalchemy import select -from aleph.db.accessors.aggregates import ( - get_aggregates_by_owner, - refresh_aggregate, -) -from aleph.db.models import AggregateDb from .utils import LIST_FIELD_SEPARATOR LOGGER = logging.getLogger(__name__) @@ -62,7 +59,8 @@ async def address_aggregate(request: web.Request) -> web.Response: aggregates = list( get_aggregates_by_owner( - session=session, owner=address, with_info=query_params.with_info + session=session, owner=address, + with_info=query_params.with_info, keys=query_params.keys ) ) diff --git a/tests/api/test_aggregates.py b/tests/api/test_aggregates.py index aed31f72d..f6826cee4 100644 --- a/tests/api/test_aggregates.py +++ b/tests/api/test_aggregates.py @@ -2,7 +2,6 @@ import aiohttp import pytest - from aleph.db.models import MessageDb AGGREGATES_URI = "/api/v0/aggregates/{address}.json" @@ -100,10 +99,12 @@ async def test_get_aggregates_filter_by_key( # Multiple keys address, keys = ADDRESS_1, ["test_target", "test_reference"] + except_key = "test_key" aggregates = await get_aggregates_expect_success( ccn_api_client, address=address, keys=",".join(keys), with_info=False ) assert aggregates["address"] == address + assert except_key not in aggregates["data"] for key in keys: assert ( aggregates["data"][key] == EXPECTED_AGGREGATES[address][key]