diff --git a/packages/faststream-stomp/faststream_stomp/testing.py b/packages/faststream-stomp/faststream_stomp/testing.py index f9da31b..f85703b 100644 --- a/packages/faststream-stomp/faststream_stomp/testing.py +++ b/packages/faststream-stomp/faststream_stomp/testing.py @@ -1,3 +1,4 @@ +import typing import uuid from collections.abc import Generator, Iterator from contextlib import contextmanager @@ -28,7 +29,6 @@ def create_publisher_fake_subscriber( if handler.config.full_destination == publisher.config.full_destination: subscriber = handler break - if subscriber is None: is_real = False subscriber = broker.subscriber(publisher.config.full_destination) @@ -73,6 +73,6 @@ async def publish(self, cmd: StompPublishCommand) -> None: if content_type: all_headers["content-type"] = content_type frame = FakeAckableMessageFrame(headers=all_headers, body=body, _subscription=mock.AsyncMock()) - for handler in self.broker._subscribers: - if handler.config.full_destination == cmd.destination: + for handler in self.broker.subscribers: + if typing.cast("StompSubscriber", handler).config.full_destination == cmd.destination: await handler.process_message(frame) diff --git a/packages/faststream-stomp/test_faststream_stomp/test_main.py b/packages/faststream-stomp/test_faststream_stomp/test_main.py index f6c6cb8..cac17d6 100644 --- a/packages/faststream-stomp/test_faststream_stomp/test_main.py +++ b/packages/faststream-stomp/test_faststream_stomp/test_main.py @@ -7,6 +7,7 @@ from faststream.message import gen_cor_id from faststream_stomp.opentelemetry import StompTelemetryMiddleware from faststream_stomp.prometheus import StompPrometheusMiddleware +from faststream_stomp.router import StompRouter from opentelemetry.sdk.metrics import MeterProvider from opentelemetry.sdk.trace import TracerProvider from polyfactory.factories.pydantic_factory import ModelFactory @@ -65,6 +66,18 @@ class SomePydanticModel(pydantic.BaseModel): async with faststream_stomp.TestStompBroker(broker) as br: await br.publish(ModelFactory.create_factory(SomePydanticModel).build(), faker.pystr()) + async def test_routers(self, faker: faker.Faker, broker: faststream_stomp.StompBroker) -> None: + router = StompRouter() + broker.include_router(router) + + @router.subscriber(destination := faker.pystr()) + def handle_message(body: str) -> None: ... + + async with faststream_stomp.TestStompBroker(broker): + await broker.publish(faker.pystr(), destination) + assert handle_message.mock + handle_message.mock.assert_called_once() + class TestNotImplemented: async def test_broker_request(self, faker: faker.Faker, broker: faststream_stomp.StompBroker) -> None: