11import faker
22import faststream_stomp
3+ import pydantic
34import pytest
45import stompman
56from faststream import FastStream
89from faststream_stomp .prometheus import StompPrometheusMiddleware
910from opentelemetry .sdk .metrics import MeterProvider
1011from opentelemetry .sdk .trace import TracerProvider
12+ from polyfactory .factories .pydantic_factory import ModelFactory
1113from prometheus_client import CollectorRegistry
1214from test_stompman .conftest import build_dataclass
1315
@@ -24,36 +26,44 @@ def broker(fake_connection_params: stompman.ConnectionParameters) -> faststream_
2426 return faststream_stomp .StompBroker (stompman .Client ([fake_connection_params ]))
2527
2628
27- async def test_testing (faker : faker .Faker , broker : faststream_stomp .StompBroker ) -> None :
28- expected_body , first_destination , second_destination , third_destination , correlation_id = (
29- faker .pystr (),
30- faker .pystr (),
31- faker .pystr (),
32- faker .pystr (),
33- gen_cor_id (),
34- )
35- second_publisher = broker .publisher (second_destination )
36- third_publisher = broker .publisher (third_destination )
37-
38- @broker .subscriber (first_destination )
39- @second_publisher
40- @third_publisher
41- def first_handle (body : str ) -> str :
42- assert body == expected_body
43- return body
44-
45- @broker .subscriber (second_destination )
46- def second_handle (body : str ) -> None :
47- assert body == expected_body
48-
49- async with faststream_stomp .TestStompBroker (broker ) as br :
50- await br .publish (expected_body , first_destination , correlation_id = correlation_id )
51- assert first_handle .mock
52- first_handle .mock .assert_called_once_with (expected_body )
53- assert second_publisher .mock
54- second_publisher .mock .assert_called_once_with (expected_body )
55- assert third_publisher .mock
56- third_publisher .mock .assert_called_once_with (expected_body )
29+ class TestTesting :
30+ async def test_integration (self , faker : faker .Faker , broker : faststream_stomp .StompBroker ) -> None :
31+ expected_body , first_destination , second_destination , third_destination , correlation_id = (
32+ faker .pystr (),
33+ faker .pystr (),
34+ faker .pystr (),
35+ faker .pystr (),
36+ gen_cor_id (),
37+ )
38+ second_publisher = broker .publisher (second_destination )
39+ third_publisher = broker .publisher (third_destination )
40+
41+ @broker .subscriber (first_destination )
42+ @second_publisher
43+ @third_publisher
44+ def first_handle (body : str ) -> str :
45+ assert body == expected_body
46+ return body
47+
48+ @broker .subscriber (second_destination )
49+ def second_handle (body : str ) -> None :
50+ assert body == expected_body
51+
52+ async with faststream_stomp .TestStompBroker (broker ) as br :
53+ await br .publish (expected_body , first_destination , correlation_id = correlation_id )
54+ assert first_handle .mock
55+ first_handle .mock .assert_called_once_with (expected_body )
56+ assert second_publisher .mock
57+ second_publisher .mock .assert_called_once_with (expected_body )
58+ assert third_publisher .mock
59+ third_publisher .mock .assert_called_once_with (expected_body )
60+
61+ async def test_publish_pydantic (self , faker : faker .Faker , broker : faststream_stomp .StompBroker ) -> None :
62+ class SomePydanticModel (pydantic .BaseModel ):
63+ foo : str
64+
65+ async with faststream_stomp .TestStompBroker (broker ) as br :
66+ await br .publish (ModelFactory .create_factory (SomePydanticModel ).build (), faker .pystr ())
5767
5868
5969class TestNotImplemented :
0 commit comments