Skip to content

Commit

Permalink
fix: serialize TestClient rpc output to mock the real message (#1452)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lancetnik committed May 16, 2024
1 parent 987d069 commit c555f0f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion faststream/broker/core/usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ async def publish(
**kwargs: Any,
) -> Optional[Any]:
"""Publish message directly."""
assert producer, NOT_CONNECTED_YET # nosec B101)
assert producer, NOT_CONNECTED_YET # nosec B101

publish: "AsyncFunc" = producer.publish
for m in self._middlewares:
Expand Down
6 changes: 5 additions & 1 deletion faststream/testing/broker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from unittest.mock import AsyncMock, MagicMock

from faststream.broker.core.usecase import BrokerUsecase
from faststream.broker.message import StreamMessage, decode_message, encode_message
from faststream.broker.middlewares.logging import CriticalLogMiddleware
from faststream.broker.wrapper.call import HandlerCallWrapper
from faststream.testing.app import TestApp
Expand Down Expand Up @@ -212,6 +213,9 @@ async def call_handler(
result = await handler.consume(message)

if rpc:
return result
message_body, content_type = encode_message(result)
msg_to_publish = StreamMessage(raw_message=None, body=message_body, content_type=content_type)
consumed_data = decode_message(msg_to_publish)
return consumed_data

return None

0 comments on commit c555f0f

Please sign in to comment.