Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
chyroc committed Mar 8, 2025
1 parent a79aec6 commit ae5d0dd
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions tests/test_websockets.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ae5d0dd

Please sign in to comment.