Skip to content

Commit

Permalink
test: minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jrriehl committed Feb 25, 2025
1 parent d37d389 commit beb2a86
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions python/tests/test_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def setUp(self):
@self.bob.on_message(model=Message)
async def _(ctx, sender, msg):
await asyncio.sleep(1.1)
await ctx.send(sender, Message(message="hey hey"))
await ctx.send(sender, incoming)

self.loop = asyncio.get_event_loop()
self.loop.create_task(self.alice._dispenser.run())
Expand Down Expand Up @@ -316,15 +316,15 @@ async def test_send_and_receive_sync_success(self, mocked_responses):
session=context.session,
schema_digest=msg_digest,
)
env.encode_payload(msg.model_dump_json())
env.encode_payload(incoming.model_dump_json())
env.sign(self.clyde._identity.sign_digest)
payload = env.model_dump()
payload["session"] = str(env.session)
mocked_responses.post(endpoints[0], status=200, payload=payload)

# Perform the actual operation
response, status = await context.send_and_receive(
self.clyde.address, msg, response_type=Message, sync=True, timeout=5
self.clyde.address, msg, response_type=Incoming, sync=True, timeout=5
)

# Define the expected message status
Expand All @@ -338,11 +338,11 @@ async def test_send_and_receive_sync_success(self, mocked_responses):

# Assertions
self.assertEqual(status, exp_msg_status)
self.assertEqual(response, msg)
self.assertEqual(response, incoming)
self.assertEqual(len(dispatcher.pending_responses), 0)

@aioresponses()
async def test_send_and_receive_sync_timeout(self, mocked_responses):
async def test_send_and_receive_sync_delivery_failure(self, mocked_responses):
context = self.alice._build_context()

# Mock the HTTP POST request with a status code and response content
Expand All @@ -353,15 +353,15 @@ async def test_send_and_receive_sync_timeout(self, mocked_responses):
session=context.session,
schema_digest=msg_digest,
)
env.encode_payload(msg.model_dump_json())
env.encode_payload(incoming.model_dump_json())
env.sign(self.clyde._identity.sign_digest)
payload = env.model_dump()
payload["session"] = str(env.session)
mocked_responses.post(endpoints[0], status=200, payload=payload)

# Perform the actual operation
_, status = await context.send_and_receive(
self.clyde.address, msg, response_type=Message, sync=True, timeout=0
self.clyde.address, msg, response_type=Incoming, sync=True, timeout=0
)

# Define the expected message status
Expand All @@ -382,7 +382,7 @@ async def test_send_and_receive_async_success(self):

# Perform the actual operation
response, status = await context.send_and_receive(
self.bob.address, msg, response_type=Message, timeout=5
self.bob.address, msg, response_type=Incoming, timeout=5
)

# Define the expected message status
Expand All @@ -396,15 +396,15 @@ async def test_send_and_receive_async_success(self):

# Assertions
self.assertEqual(status, exp_msg_status)
self.assertEqual(response, Message(message="hey hey"))
self.assertEqual(response, incoming)
self.assertEqual(len(dispatcher.pending_responses), 0)

async def test_send_and_receive_async_timeout(self):
context = self.alice._build_context()

# Perform the actual operation
_, status = await context.send_and_receive(
self.bob.address, msg, response_type=Message, timeout=1
self.bob.address, msg, response_type=Incoming, timeout=1
)

# Define the expected message status
Expand All @@ -424,7 +424,7 @@ async def test_send_and_receive_async_wrong_response_type(self):
context = self.alice._build_context()

class WrongMessage(Model):
text: str
wrong: str

# Perform the actual operation
response, status = await context.send_and_receive(
Expand Down

0 comments on commit beb2a86

Please sign in to comment.