Bases: TestBroker[RabbitBroker]
A class to test RabbitMQ brokers.
Source code in faststream/_internal/testing/broker.py
| def __init__(
self,
broker: Broker,
with_real: bool = False,
connect_only: bool | None = None,
) -> None:
self.with_real = with_real
self.broker = broker
if connect_only is None:
try:
connect_only = is_contains_context_name(
self.__class__.__name__,
TestApp.__name__,
)
except Exception: # pragma: no cover
warnings.warn(
(
"\nError `{e!r}` occurred at `{self.__class__.__name__}` AST parsing."
"\n`connect_only` is set to `False` by default."
),
category=RuntimeWarning,
stacklevel=1,
)
connect_only = False
self.connect_only = connect_only
self._fake_subscribers: list[SubscriberUsecase[Any]] = []
|
with_real
instance-attribute
broker
instance-attribute
connect_only
instance-attribute
connect_only = connect_only
create_publisher_fake_subscriber
staticmethod
create_publisher_fake_subscriber(broker, publisher)
Source code in faststream/rabbit/testing.py
| @staticmethod
def create_publisher_fake_subscriber(
broker: "RabbitBroker",
publisher: "RabbitPublisher",
) -> tuple["RabbitSubscriber", bool]:
sub: RabbitSubscriber | None = None
for handler in broker.subscribers:
handler = cast("RabbitSubscriber", handler)
if _is_handler_matches(
handler,
publisher.routing(),
{},
publisher.exchange,
):
sub = handler
break
if sub is None:
is_real = False
sub = broker.subscriber(
queue=publisher.routing(),
exchange=publisher.exchange,
persistent=False,
)
else:
is_real = True
return sub, is_real
|