|
| 1 | +import asyncio |
| 2 | +from typing import Any |
| 3 | + |
| 4 | +import faker |
| 5 | +import pytest |
| 6 | +from stompman import ( |
| 7 | + SendFrame, |
| 8 | +) |
| 9 | +from stompman.frames import SendHeaders |
| 10 | + |
| 11 | +from test_stompman.conftest import ( |
| 12 | + EnrichedClient, |
| 13 | + create_spying_connection, |
| 14 | + enrich_expected_frames, |
| 15 | + get_read_frames_with_lifespan, |
| 16 | +) |
| 17 | + |
| 18 | +pytestmark = pytest.mark.anyio |
| 19 | + |
| 20 | + |
| 21 | +@pytest.mark.parametrize( |
| 22 | + ("args", "expected_body", "expected_headers"), |
| 23 | + [ |
| 24 | + ( |
| 25 | + {"body": b"Some body", "destination": "Some/queue"}, |
| 26 | + b"Some body", |
| 27 | + {"content-length": "9", "destination": "Some/queue"}, |
| 28 | + ), |
| 29 | + ( |
| 30 | + {"body": b"Some body", "destination": "Some/queue", "add_content_length": True}, |
| 31 | + b"Some body", |
| 32 | + {"content-length": "9", "destination": "Some/queue"}, |
| 33 | + ), |
| 34 | + ( |
| 35 | + {"body": b"Some body", "destination": "Some/queue", "content_type": "text/plain"}, |
| 36 | + b"Some body", |
| 37 | + {"content-length": "9", "destination": "Some/queue", "content-type": "text/plain"}, |
| 38 | + ), |
| 39 | + ( |
| 40 | + {"body": b"Some body", "destination": "Some/queue", "add_content_length": False}, |
| 41 | + b"Some body", |
| 42 | + {"destination": "Some/queue"}, |
| 43 | + ), |
| 44 | + ], |
| 45 | +) |
| 46 | +async def test_send_message(args: dict[str, Any], expected_body: bytes, expected_headers: SendHeaders) -> None: |
| 47 | + connection_class, collected_frames = create_spying_connection(*get_read_frames_with_lifespan([])) |
| 48 | + |
| 49 | + async with EnrichedClient(connection_class=connection_class) as client: |
| 50 | + await client.send(**args) |
| 51 | + await asyncio.sleep(0) |
| 52 | + |
| 53 | + assert collected_frames == enrich_expected_frames( |
| 54 | + SendFrame(headers=expected_headers, body=expected_body), |
| 55 | + ) |
0 commit comments