Skip to content

Commit 8db8a23

Browse files
authored
Align test broker behavior with real one: dump (and validate by doing that) SendFrame on fake publish (#184)
1 parent 81a2047 commit 8db8a23

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

packages/faststream-stomp/faststream_stomp/testing.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import stompman
1111
from faststream._internal.testing.broker import TestBroker, change_producer
1212
from faststream.message import encode_message
13+
from stompman.frames import SendFrame
14+
from stompman.serde import dump_frame
1315

1416
from faststream_stomp.broker import StompBroker
1517
from faststream_stomp.models import StompPublishCommand
@@ -72,6 +74,16 @@ async def publish(self, cmd: StompPublishCommand) -> None:
7274
all_headers["correlation-id"] = cmd.correlation_id # type: ignore[typeddict-unknown-key]
7375
if content_type:
7476
all_headers["content-type"] = content_type
77+
dump_frame(
78+
SendFrame.build(
79+
body=body,
80+
destination=cmd.destination,
81+
transaction=None,
82+
content_type=content_type,
83+
add_content_length=False,
84+
headers=cmd.headers,
85+
)
86+
)
7587
frame = FakeAckableMessageFrame(headers=all_headers, body=body, _subscription=mock.AsyncMock())
7688
for handler in self.broker.subscribers:
7789
if typing.cast("StompSubscriber", handler).config.full_destination == cmd.destination:

packages/faststream-stomp/test_faststream_stomp/test_main.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import typing
2+
13
import faker
24
import faststream_stomp
35
import pydantic
@@ -59,6 +61,19 @@ def second_handle(body: str) -> None:
5961
assert third_publisher.mock
6062
third_publisher.mock.assert_called_once_with(expected_body)
6163

64+
async def test_non_string_header_values_raise_type_error(
65+
self, faker: faker.Faker, broker: faststream_stomp.StompBroker
66+
) -> None:
67+
# gotcha: dict[str, typing.Any] is easily happily into dict[str, str]
68+
headers: dict[str, typing.Any] = {"key": 123}
69+
70+
@broker.subscriber(destination := faker.pystr())
71+
def handle(body: str) -> None: ...
72+
73+
async with faststream_stomp.TestStompBroker(broker) as br:
74+
with pytest.raises(TypeError):
75+
await br.publish(faker.pystr(), destination, headers=headers)
76+
6277
async def test_publish_pydantic(self, faker: faker.Faker, broker: faststream_stomp.StompBroker) -> None:
6378
class SomePydanticModel(pydantic.BaseModel):
6479
foo: str

0 commit comments

Comments
 (0)