diff --git a/src/aleph/schemas/pending_messages.py b/src/aleph/schemas/pending_messages.py index e3cec651..28b74156 100644 --- a/src/aleph/schemas/pending_messages.py +++ b/src/aleph/schemas/pending_messages.py @@ -45,9 +45,9 @@ class BasePendingMessage(AlephBaseMessage, Generic[MType, ContentType]): A raw Aleph message, as sent by users to the Aleph network. """ - @classmethod @model_validator(mode="before") - def load_content(cls, values): + @classmethod + def load_content(cls, values: Any): """ Preload inline content. We let the CCN populate this field later on for ipfs and storage item types. diff --git a/src/aleph/toolkit/timestamp.py b/src/aleph/toolkit/timestamp.py index 5fb2cf23..8fae474c 100644 --- a/src/aleph/toolkit/timestamp.py +++ b/src/aleph/toolkit/timestamp.py @@ -10,7 +10,7 @@ def timestamp_to_datetime(timestamp: float) -> dt.datetime: object. """ - return pytz.utc.localize(dt.datetime.fromtimestamp(timestamp, dt.UTC)) + return pytz.utc.localize(dt.datetime.utcfromtimestamp(timestamp)) def coerce_to_datetime( diff --git a/tests/api/test_list_messages.py b/tests/api/test_list_messages.py index 9c618f9a..48fe1e81 100644 --- a/tests/api/test_list_messages.py +++ b/tests/api/test_list_messages.py @@ -70,7 +70,9 @@ async def test_get_messages(fixture_messages: Sequence[Dict[str, Any]], ccn_api_ @pytest.mark.asyncio async def test_get_messages_filter_by_channel(fixture_messages, ccn_api_client): async def fetch_messages_by_channel(channel: str) -> Dict: - response = await ccn_api_client.get(MESSAGES_URI, params={"channels": [channel]}) + response = await ccn_api_client.get( + MESSAGES_URI, params={"channels": [channel]} + ) assert response.status == 200, await response.text() return await response.json() @@ -192,7 +194,9 @@ async def test_get_messages_filter_by_tags( assert len(messages) == 2 # Matching tags for both messages - response = await ccn_api_client.get(MESSAGES_URI, params={"tags": ["original,amend"]}) + response = await ccn_api_client.get( + MESSAGES_URI, params={"tags": ["original,amend"]} + ) assert response.status == 200, await response.text() messages = (await response.json())["messages"] assert len(messages) == 2 @@ -227,16 +231,32 @@ async def test_get_messages_filter_by_tags( assert messages[0]["item_hash"] == amend_message_db.item_hash -@pytest.mark.parametrize("type_field", ("msgType", "msgTypes")) @pytest.mark.asyncio -async def test_get_by_message_type(fixture_messages, ccn_api_client, type_field: str): +async def test_get_by_deprecated_message_type(fixture_messages, ccn_api_client): + messages_by_type = defaultdict(list) + for message in fixture_messages: + messages_by_type[message["type"]].append(message) + + for message_type, expected_messages in messages_by_type.items(): + response = await ccn_api_client.get( + MESSAGES_URI, params={"msgType": message_type} + ) + assert response.status == 200, await response.text() + messages = (await response.json())["messages"] + assert set(msg["item_hash"] for msg in messages) == set( + msg["item_hash"] for msg in expected_messages + ) + + +@pytest.mark.asyncio +async def test_get_by_message_type(fixture_messages, ccn_api_client): messages_by_type = defaultdict(list) for message in fixture_messages: messages_by_type[message["type"]].append(message) for message_type, expected_messages in messages_by_type.items(): response = await ccn_api_client.get( - MESSAGES_URI, params={type_field: message_type} + MESSAGES_URI, params={"msgTypes": [message_type]} ) assert response.status == 200, await response.text() messages = (await response.json())["messages"] diff --git a/tests/api/test_posts.py b/tests/api/test_posts.py index 3b824560..1f5b88ef 100644 --- a/tests/api/test_posts.py +++ b/tests/api/test_posts.py @@ -261,7 +261,9 @@ async def test_get_amended_posts_tags( session.commit() # Match one tag - response = await ccn_api_client.get("/api/v0/posts.json", params={"tags": ["amend"]}) + response = await ccn_api_client.get( + "/api/v0/posts.json", params={"tags": ["amend"]} + ) assert response.status == 200 response_json = await response.json() assert len(response_json["posts"]) == 1 diff --git a/tests/message_processing/test_process_instances.py b/tests/message_processing/test_process_instances.py index d1739f6a..5334b43f 100644 --- a/tests/message_processing/test_process_instances.py +++ b/tests/message_processing/test_process_instances.py @@ -375,7 +375,9 @@ async def test_process_instance_missing_volumes( assert rejected_message.error_code == ErrorCode.VM_VOLUME_NOT_FOUND if fixture_instance_message.item_content: - content = InstanceContent.model_validate_json(fixture_instance_message.item_content) + content = InstanceContent.model_validate_json( + fixture_instance_message.item_content + ) volume_refs = set(volume.ref for volume in get_volume_refs(content)) assert isinstance(rejected_message.details, dict) assert set(rejected_message.details["errors"]) == volume_refs @@ -453,7 +455,9 @@ async def test_get_volume_size( session.commit() if fixture_instance_message.item_content: - content = InstanceContent.model_validate_json(fixture_instance_message.item_content) + content = InstanceContent.model_validate_json( + fixture_instance_message.item_content + ) with session_factory() as session: volume_size = get_volume_size(session=session, content=content) assert volume_size == 21512585216 @@ -469,7 +473,9 @@ async def test_get_additional_storage_price( session.commit() if fixture_instance_message.item_content: - content = InstanceContent.model_validate_json(fixture_instance_message.item_content) + content = InstanceContent.model_validate_json( + fixture_instance_message.item_content + ) with session_factory() as session: additional_price = get_additional_storage_price( content=content, session=session @@ -487,7 +493,9 @@ async def test_get_compute_cost( session.commit() if fixture_instance_message.item_content: - content = InstanceContent.model_validate_json(fixture_instance_message.item_content) + content = InstanceContent.model_validate_json( + fixture_instance_message.item_content + ) with session_factory() as session: price: Decimal = compute_cost(content=content, session=session) assert price == Decimal("2001.8")