Coverage for faststream/rabbit/publisher/fake.py: 94%
15 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 21:20 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-17 21:20 +0000
1from typing import TYPE_CHECKING, Any, Union
3from faststream._internal.endpoint.publisher.fake import FakePublisher
4from faststream.rabbit.response import RabbitPublishCommand
5from faststream.rabbit.schemas import RabbitExchange
7if TYPE_CHECKING:
8 from faststream._internal.producer import ProducerProto
9 from faststream.response.response import PublishCommand
12class RabbitFakePublisher(FakePublisher):
13 """Publisher Interface implementation to use as RPC or REPLY TO answer publisher."""
15 __slots__ = (
16 "app_id",
17 "exchange",
18 "routing_key",
19 )
21 def __init__(
22 self,
23 producer: "ProducerProto[Any]",
24 routing_key: str,
25 app_id: str | None,
26 exchange: RabbitExchange,
27 ) -> None:
28 super().__init__(producer=producer)
29 self.routing_key = routing_key
30 self.exchange = exchange
31 self.app_id = app_id
33 def patch_command(
34 self,
35 cmd: Union["PublishCommand", "RabbitPublishCommand"],
36 ) -> "RabbitPublishCommand":
37 cmd = super().patch_command(cmd)
38 real_cmd = RabbitPublishCommand.from_cmd(cmd)
39 real_cmd.destination = self.routing_key
40 real_cmd.exchange = self.exchange
41 if self.app_id: 41 ↛ 43line 41 didn't jump to line 43 because the condition on line 41 was always true
42 real_cmd.message_options["app_id"] = self.app_id
43 return real_cmd