Skip to content

Commit 3006066

Browse files
authored
faststream-stomp: Fix testing routers (#165)
1 parent 4b39622 commit 3006066

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

packages/faststream-stomp/faststream_stomp/testing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import typing
12
import uuid
23
from collections.abc import Generator, Iterator
34
from contextlib import contextmanager
@@ -28,7 +29,6 @@ def create_publisher_fake_subscriber(
2829
if handler.config.full_destination == publisher.config.full_destination:
2930
subscriber = handler
3031
break
31-
3232
if subscriber is None:
3333
is_real = False
3434
subscriber = broker.subscriber(publisher.config.full_destination)
@@ -73,6 +73,6 @@ async def publish(self, cmd: StompPublishCommand) -> None:
7373
if content_type:
7474
all_headers["content-type"] = content_type
7575
frame = FakeAckableMessageFrame(headers=all_headers, body=body, _subscription=mock.AsyncMock())
76-
for handler in self.broker._subscribers:
77-
if handler.config.full_destination == cmd.destination:
76+
for handler in self.broker.subscribers:
77+
if typing.cast("StompSubscriber", handler).config.full_destination == cmd.destination:
7878
await handler.process_message(frame)

packages/faststream-stomp/test_faststream_stomp/test_main.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from faststream.message import gen_cor_id
88
from faststream_stomp.opentelemetry import StompTelemetryMiddleware
99
from faststream_stomp.prometheus import StompPrometheusMiddleware
10+
from faststream_stomp.router import StompRouter
1011
from opentelemetry.sdk.metrics import MeterProvider
1112
from opentelemetry.sdk.trace import TracerProvider
1213
from polyfactory.factories.pydantic_factory import ModelFactory
@@ -65,6 +66,18 @@ class SomePydanticModel(pydantic.BaseModel):
6566
async with faststream_stomp.TestStompBroker(broker) as br:
6667
await br.publish(ModelFactory.create_factory(SomePydanticModel).build(), faker.pystr())
6768

69+
async def test_routers(self, faker: faker.Faker, broker: faststream_stomp.StompBroker) -> None:
70+
router = StompRouter()
71+
broker.include_router(router)
72+
73+
@router.subscriber(destination := faker.pystr())
74+
def handle_message(body: str) -> None: ...
75+
76+
async with faststream_stomp.TestStompBroker(broker):
77+
await broker.publish(faker.pystr(), destination)
78+
assert handle_message.mock
79+
handle_message.mock.assert_called_once()
80+
6881

6982
class TestNotImplemented:
7083
async def test_broker_request(self, faker: faker.Faker, broker: faststream_stomp.StompBroker) -> None:

0 commit comments

Comments
 (0)