From ae5d0ddbd7a539d3481c2ee3959e4b327b25076e Mon Sep 17 00:00:00 2001 From: chyroc Date: Sat, 8 Mar 2025 08:38:19 +0800 Subject: [PATCH] update --- tests/test_websockets.py | 76 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/test_websockets.py diff --git a/tests/test_websockets.py b/tests/test_websockets.py new file mode 100644 index 0000000..40098ba --- /dev/null +++ b/tests/test_websockets.py @@ -0,0 +1,76 @@ +import pytest + +from cozepy import ( + AsyncWebsocketsAudioSpeechEventHandler, + AsyncWebsocketsAudioTranscriptionsEventHandler, + AsyncWebsocketsChatEventHandler, + WebsocketsAudioSpeechEventHandler, + WebsocketsAudioTranscriptionsEventHandler, + WebsocketsChatEventHandler, +) + + +@pytest.mark.respx(base_url="https://api.coze.com") +class TestSyncWebsocketsHandler: + def test_sync_rooms_create(self, respx_mock): + # init handlers + speech = WebsocketsAudioSpeechEventHandler() + transcriptions = WebsocketsAudioTranscriptionsEventHandler() + chat = WebsocketsChatEventHandler() + + # call event_handlers + speech_handlers = speech.event_handlers() + transcriptions_handlers = transcriptions.event_handlers() + chat_handlers = chat.event_handlers() + + # call twice + speech_handlers_2 = speech.event_handlers() + transcriptions_handlers_2 = transcriptions.event_handlers() + chat_handlers_2 = chat.event_handlers() + + # assert that they are the same + assert speech_handlers == speech_handlers_2 + assert transcriptions_handlers == transcriptions_handlers_2 + assert chat_handlers == chat_handlers_2 + + # assert that they are not the same + assert speech_handlers != transcriptions_handlers + assert speech_handlers != chat_handlers + assert speech_handlers != transcriptions_handlers_2 + assert speech_handlers != chat_handlers_2 + + assert transcriptions_handlers != chat_handlers + assert transcriptions_handlers != chat_handlers_2 + + +@pytest.mark.respx(base_url="https://api.coze.com") +class TestAsyncWebsocketsHandler: + def test_sync_rooms_create(self, respx_mock): + # init handlers + speech = AsyncWebsocketsAudioSpeechEventHandler() + transcriptions = AsyncWebsocketsAudioTranscriptionsEventHandler() + chat = AsyncWebsocketsChatEventHandler() + + # call event_handlers + speech_handlers = speech.event_handlers() + transcriptions_handlers = transcriptions.event_handlers() + chat_handlers = chat.event_handlers() + + # call twice + speech_handlers_2 = speech.event_handlers() + transcriptions_handlers_2 = transcriptions.event_handlers() + chat_handlers_2 = chat.event_handlers() + + # assert that they are the same + assert speech_handlers == speech_handlers_2 + assert transcriptions_handlers == transcriptions_handlers_2 + assert chat_handlers == chat_handlers_2 + + # assert that they are not the same + assert speech_handlers != transcriptions_handlers + assert speech_handlers != chat_handlers + assert speech_handlers != transcriptions_handlers_2 + assert speech_handlers != chat_handlers_2 + + assert transcriptions_handlers != chat_handlers + assert transcriptions_handlers != chat_handlers_2