Coverage for tests/brokers/confluent/test_security.py: 40%

5 statements  

« prev     ^ index     » next       coverage.py v7.17.3, created at 2026-11-17 21:20 +0000

1import ssl 

2from collections.abc import Generator 

3from contextlib import contextmanager 

4from unittest.mock import AsyncMock, MagicMock, patch 

5 

6import pytest 

7 

8from faststream.confluent import KafkaBroker 

9from faststream.exceptions import SetupError 

10from faststream.security import BaseSecurity 

11 

12 

13@contextmanager 

14def patch_aio_consumer_and_producer() -> Generator[ 

15 tuple[MagicMock, MagicMock], None, None 

16]: 

17 producer = MagicMock(return_value=AsyncMock()) 

18 

19 with patch( 

20 "faststream.confluent.helpers.client.AsyncConfluentProducer", 

21 new=producer, 

22 ): 

23 yield producer 

24 

25 

26@pytest.mark.confluent() 

27@pytest.mark.asyncio() 

28async def test_base_security_pass_ssl_context() -> None: 

29 ssl_context = ssl.create_default_context() 

30 security = BaseSecurity(ssl_context=ssl_context) 

31 

32 with pytest.raises( 

33 SetupError, 

34 match=r"ssl_context is not supported by confluent-kafka-python, please use config instead.", 

35 ): 

36 KafkaBroker("localhost:9092", security=security)