Skip to content

Commit 6efdcc6

Browse files
committed
:wq
erge branch 'asyncapi-post-form' of github.com:vvlrff/faststream into asyncapi-post-form
2 parents 359d9c5 + cc0002e commit 6efdcc6

File tree

4 files changed

+55
-1
lines changed

4 files changed

+55
-1
lines changed

faststream/rabbit/testing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import aiormq
88
import anyio
9-
from aio_pika.message import IncomingMessage
9+
from aio_pika.message import IncomingMessage, encode_expiration
1010
from pamqp import commands as spec
1111
from pamqp.header import ContentHeader
1212
from typing_extensions import override
@@ -178,6 +178,7 @@ def build_message(
178178
content_encoding=msg.content_encoding,
179179
priority=msg.priority,
180180
correlation_id=msg.correlation_id,
181+
expiration=encode_expiration(msg.expiration),
181182
message_id=msg.message_id,
182183
timestamp=msg.timestamp,
183184
message_type=message_type,

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ test-core = [
131131
"pytest-xdist>=3.8.0",
132132
"pytest-cov>=6.2.1",
133133
"covdefaults>=2.3.0",
134+
"freezegun>=1.5.5",
134135
]
135136

136137
testing = [

tests/brokers/rabbit/test_test_client.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import asyncio
2+
import datetime as dt
23
from typing import Any
4+
from unittest.mock import MagicMock
35

46
import pytest
7+
from freezegun import freeze_time
58

69
from faststream import BaseMiddleware
710
from faststream.exceptions import SubscriberNotFound
@@ -18,6 +21,8 @@
1821
from .basic import RabbitMemoryTestcaseConfig
1922
from .test_publish import TestPublishWithExchange as PublishWithExchangeCase
2023

24+
_frozen_time = dt.datetime(2026, 2, 10, 12, 0, 0, tzinfo=dt.timezone.utc)
25+
2126

2227
@pytest.mark.rabbit()
2328
@pytest.mark.asyncio()
@@ -187,6 +192,35 @@ async def test_broker_with_real_patches_publishers_and_subscribers(
187192
) -> None:
188193
await super().test_broker_with_real_patches_publishers_and_subscribers(queue)
189194

195+
@pytest.mark.asyncio()
196+
@pytest.mark.parametrize(
197+
("expiration", "expected"),
198+
(
199+
pytest.param(None, None, id="none"),
200+
pytest.param(1, 1, id="int"),
201+
pytest.param(1.5, 1.5, id="float"),
202+
pytest.param(dt.timedelta(seconds=1.1), 1.1, id="timedelta"),
203+
pytest.param(_frozen_time, 0, id="datetime"),
204+
),
205+
)
206+
@freeze_time(_frozen_time)
207+
async def test_publish_expiration_propagated(
208+
self, expiration: Any, expected: Any, queue: str, mock: MagicMock
209+
) -> None:
210+
broker = self.get_broker(apply_types=True)
211+
212+
args, kwargs = self.get_subscriber_params(queue)
213+
214+
@broker.subscriber(*args, **kwargs)
215+
async def m(msg: RabbitMessage) -> None:
216+
mock(msg)
217+
218+
async with self.patch_broker(broker) as br:
219+
await br.start()
220+
await br.publish("hello", queue, expiration=expiration)
221+
msg = mock.call_args[0][0]
222+
assert msg.raw_message.expiration == expected
223+
190224

191225
@pytest.mark.parametrize(
192226
("pattern", "current", "result"),

uv.lock

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)