|
| 1 | +import pytest |
| 2 | + |
| 3 | +from getstream import AsyncStream |
| 4 | + |
| 5 | + |
| 6 | +@pytest.mark.asyncio |
| 7 | +class TestAsyncStreamClose: |
| 8 | + async def test_aclose_closes_main_client(self): |
| 9 | + client = AsyncStream(api_key="fake", api_secret="fake") |
| 10 | + |
| 11 | + assert client.client.is_closed is False |
| 12 | + await client.aclose() |
| 13 | + assert client.client.is_closed is True |
| 14 | + |
| 15 | + async def test_aclose_closes_video_client(self): |
| 16 | + client = AsyncStream(api_key="fake", api_secret="fake") |
| 17 | + _ = client.video # trigger cached_property |
| 18 | + |
| 19 | + assert client.video.client.is_closed is False |
| 20 | + await client.aclose() |
| 21 | + assert client.video.client.is_closed is True |
| 22 | + |
| 23 | + async def test_aclose_closes_chat_client(self): |
| 24 | + client = AsyncStream(api_key="fake", api_secret="fake") |
| 25 | + _ = client.chat |
| 26 | + |
| 27 | + assert client.chat.client.is_closed is False |
| 28 | + await client.aclose() |
| 29 | + assert client.chat.client.is_closed is True |
| 30 | + |
| 31 | + async def test_aclose_closes_moderation_client(self): |
| 32 | + client = AsyncStream(api_key="fake", api_secret="fake") |
| 33 | + _ = client.moderation |
| 34 | + |
| 35 | + assert client.moderation.client.is_closed is False |
| 36 | + await client.aclose() |
| 37 | + assert client.moderation.client.is_closed is True |
| 38 | + |
| 39 | + async def test_aclose_without_child_clients(self): |
| 40 | + """aclose() should work even if video/chat were never accessed.""" |
| 41 | + client = AsyncStream(api_key="fake", api_secret="fake") |
| 42 | + await client.aclose() |
| 43 | + assert client.client.is_closed is True |
0 commit comments