@@ -43,8 +43,8 @@ def merge_content(_messages: List[Dict]) -> Dict:
43
43
aggregates = []
44
44
45
45
for key , group in itertools .groupby (
46
- sorted (messages , key = lambda msg : msg ["content" ]["key" ]),
47
- lambda msg : msg ["content" ]["key" ],
46
+ sorted (messages , key = lambda msg : msg ["content" ]["key" ]),
47
+ lambda msg : msg ["content" ]["key" ],
48
48
):
49
49
sorted_messages = sorted (group , key = lambda msg : msg ["time" ])
50
50
aggregates .append (merge_content (sorted_messages ))
@@ -99,22 +99,30 @@ async def test_get_aggregates(ccn_api_client, fixture_aggregates: List[Dict]):
99
99
100
100
101
101
@pytest .mark .asyncio
102
- async def test_get_aggregates_filter_by_key (ccn_api_client , fixture_aggregates : List [Dict ]):
102
+ async def test_get_aggregates_filter_by_key (
103
+ ccn_api_client , fixture_aggregates : List [Dict ]
104
+ ):
103
105
"""
104
106
Tests the 'keys' query parameter.
105
107
"""
106
108
107
109
address , key = ADDRESS_1 , "test_target"
108
- aggregates = await get_aggregates_expect_success (ccn_api_client , address = address , keys = key )
110
+ aggregates = await get_aggregates_expect_success (
111
+ ccn_api_client , address = address , keys = key
112
+ )
109
113
assert aggregates ["address" ] == address
110
114
assert aggregates ["data" ][key ] == EXPECTED_AGGREGATES [address ][key ]
111
115
112
116
# Multiple keys
113
117
address , keys = ADDRESS_1 , ["test_target" , "test_reference" ]
114
- aggregates = await get_aggregates_expect_success (ccn_api_client , address = address , keys = "," .join (keys ))
118
+ aggregates = await get_aggregates_expect_success (
119
+ ccn_api_client , address = address , keys = "," .join (keys )
120
+ )
115
121
assert aggregates ["address" ] == address
116
122
for key in keys :
117
- assert aggregates ["data" ][key ] == EXPECTED_AGGREGATES [address ][key ], f"Key { key } does not match"
123
+ assert (
124
+ aggregates ["data" ][key ] == EXPECTED_AGGREGATES [address ][key ]
125
+ ), f"Key { key } does not match"
118
126
119
127
120
128
@pytest .mark .asyncio
@@ -124,13 +132,17 @@ async def test_get_aggregates_limit(ccn_api_client, fixture_aggregates: List[Dic
124
132
"""
125
133
126
134
address , key = ADDRESS_1 , "test_reference"
127
- aggregates = await get_aggregates_expect_success (ccn_api_client , address = address , keys = key , limit = 1 )
135
+ aggregates = await get_aggregates_expect_success (
136
+ ccn_api_client , address = address , keys = key , limit = 1
137
+ )
128
138
assert aggregates ["address" ] == address
129
139
assert aggregates ["data" ][key ] == {"c" : 3 , "d" : 4 }
130
140
131
141
132
142
@pytest .mark .asyncio
133
- async def test_get_aggregates_invalid_address (ccn_api_client , fixture_aggregates : List [Dict ]):
143
+ async def test_get_aggregates_invalid_address (
144
+ ccn_api_client , fixture_aggregates : List [Dict ]
145
+ ):
134
146
"""
135
147
Pass an unknown address.
136
148
"""
@@ -139,3 +151,21 @@ async def test_get_aggregates_invalid_address(ccn_api_client, fixture_aggregates
139
151
140
152
response = await get_aggregates (ccn_api_client , invalid_address )
141
153
assert response .status == 404
154
+
155
+
156
+ @pytest .mark .asyncio
157
+ async def test_get_aggregates_invalid_params (
158
+ ccn_api_client , fixture_aggregates : List [Dict ]
159
+ ):
160
+ """
161
+ Tests that passing invalid parameters returns a 422 error.
162
+ """
163
+
164
+ # A string as limit
165
+ response = await get_aggregates (ccn_api_client , ADDRESS_1 , limit = "abc" )
166
+ assert response .status == 422
167
+ assert response .content_type == "application/json"
168
+
169
+ errors = await response .json ()
170
+ assert len (errors ) == 1
171
+ assert errors [0 ]["loc" ] == ["limit" ], errors
0 commit comments