Skip to content

Commit b11349b

Browse files
committed
Add prepare_aleph_message test
1 parent 5ded5c3 commit b11349b

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

tests/unit/test_asynchronous.py

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
1+
import datetime
12
from unittest.mock import AsyncMock
23

34
import pytest as pytest
45
from aleph_message.models import (
56
AggregateMessage,
67
ForgetMessage,
78
InstanceMessage,
9+
MessageType,
810
PostMessage,
911
ProgramMessage,
1012
StoreMessage,
1113
)
14+
from aleph_message.models.execution.environment import MachineResources
1215
from aleph_message.status import MessageStatus
1316

1417
from aleph.sdk.types import StorageEnum
@@ -121,3 +124,63 @@ async def test_forget(mock_session_with_post_success):
121124

122125
assert mock_session_with_post_success.http_session.post.called_once
123126
assert isinstance(forget_message, ForgetMessage)
127+
128+
129+
@pytest.mark.asyncio
130+
@pytest.mark.parametrize(
131+
"message_type, content",
132+
[
133+
(
134+
MessageType.aggregate,
135+
{
136+
"content": {"Hello": datetime.datetime.now()},
137+
"key": "test",
138+
"address": "0x1",
139+
"time": 1.0,
140+
},
141+
),
142+
(
143+
MessageType.aggregate,
144+
{
145+
"content": {"Hello": datetime.date.today()},
146+
"key": "test",
147+
"address": "0x1",
148+
"time": 1.0,
149+
},
150+
),
151+
(
152+
MessageType.aggregate,
153+
{
154+
"content": {"Hello": datetime.time()},
155+
"key": "test",
156+
"address": "0x1",
157+
"time": 1.0,
158+
},
159+
),
160+
(
161+
MessageType.aggregate,
162+
{
163+
"content": {
164+
"Hello": MachineResources(
165+
vcpus=1,
166+
memory=1024,
167+
seconds=1,
168+
)
169+
},
170+
"key": "test",
171+
"address": "0x1",
172+
"time": 1.0,
173+
},
174+
),
175+
],
176+
)
177+
async def test_prepare_aleph_message(
178+
mock_session_with_post_success, message_type, content
179+
):
180+
# Call the function under test
181+
async with mock_session_with_post_success as session:
182+
await session._prepare_aleph_message(
183+
message_type=message_type,
184+
content=content,
185+
channel="TEST",
186+
)

0 commit comments

Comments
 (0)