From aa38b38384f77cf72e1f9714e7a2a634c21f49c2 Mon Sep 17 00:00:00 2001 From: Olivier Desenfans Date: Mon, 17 Oct 2022 17:35:50 +0200 Subject: [PATCH] Fix: parse refs and hashes fields correctly for messages API (#346) Problem: the new validation system did not parse the `refs` and `hashes` list parameters correctly. Solution: apply the list validator to these fields as well. --- src/aleph/web/controllers/messages.py | 2 ++ tests/api/test_messages.py | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/src/aleph/web/controllers/messages.py b/src/aleph/web/controllers/messages.py index b8630891e..f06f4a6bf 100644 --- a/src/aleph/web/controllers/messages.py +++ b/src/aleph/web/controllers/messages.py @@ -83,12 +83,14 @@ def validate_field_dependencies(cls, values): @validator( "addresses", + "refs", "content_hashes", "content_keys", "content_types", "chains", "channels", "tags", + "hashes", pre=True, ) def split_str(cls, v): diff --git a/tests/api/test_messages.py b/tests/api/test_messages.py index bd07f449c..81d97aa70 100644 --- a/tests/api/test_messages.py +++ b/tests/api/test_messages.py @@ -132,6 +132,18 @@ async def test_get_messages_filter_by_content_hash(fixture_messages, ccn_api_cli ) +@pytest.mark.asyncio +async def test_get_messages_multiple_hashes(fixture_messages, ccn_api_client): + hashes = [ + "2953f0b52beb79fc0ed1bc455346fdcb530611605e16c636778a0d673d7184af", + "bc411ae2ba89289458d0168714457e7c9394a29ca83159240585591f4f46444a", + ] + response = await ccn_api_client.get(MESSAGES_URI, params={"hashes": ",".join(hashes)}) + assert response.status == 200, await response.text() + messages = (await response.json())["messages"] + assert len(messages) == 2 + + @pytest.mark.asyncio async def test_get_messages_filter_by_invalid_content_hash( fixture_messages, ccn_api_client