Skip to content

Commit

Permalink
fix test case using AsyncAuth for AsyncCoze
Browse files Browse the repository at this point in the history
  • Loading branch information
mbb1234567890 committed Mar 5, 2025
1 parent ab826b4 commit 3627d58
Show file tree
Hide file tree
Showing 19 changed files with 83 additions and 77 deletions.
4 changes: 2 additions & 2 deletions tests/test_audio_rooms.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import httpx
import pytest

from cozepy import AsyncCoze, Coze, CreateRoomResp, TokenAuth
from cozepy import AsyncCoze, AsyncTokenAuth, Coze, CreateRoomResp, TokenAuth
from cozepy.util import random_hex
from tests.test_util import logid_key

Expand Down Expand Up @@ -45,7 +45,7 @@ def test_sync_rooms_create(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncAudioRooms:
async def test_async_rooms_create(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

bot_id = random_hex(10)
voice_id = random_hex(10)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_audio_speech.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import httpx
import pytest

from cozepy import AsyncCoze, Coze, TokenAuth
from cozepy import AsyncCoze, AsyncTokenAuth, Coze, TokenAuth
from cozepy.util import random_hex
from tests.test_util import logid_key

Expand Down Expand Up @@ -39,7 +39,7 @@ def test_sync_speech_create(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncAudioSpeech:
async def test_async_speech_create(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_logid = mock_create_speech(respx_mock)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_audio_translations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import httpx
import pytest

from cozepy import AsyncCoze, Coze, TokenAuth
from cozepy import AsyncCoze, AsyncTokenAuth, Coze, TokenAuth
from cozepy.util import random_hex
from tests.test_util import logid_key

Expand Down Expand Up @@ -41,7 +41,7 @@ def test_sync_transcriptions_create(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncAudioTranscriptions:
async def test_async_transcriptions_create(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_logid = mock_create_transcriptions(respx_mock)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_audio_voices.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import httpx
import pytest

from cozepy import AsyncCoze, AudioFormat, Coze, TokenAuth, Voice
from cozepy import AsyncCoze, AsyncTokenAuth, AudioFormat, Coze, TokenAuth, Voice
from cozepy.util import random_hex
from tests.test_util import logid_key

Expand Down Expand Up @@ -88,7 +88,7 @@ def test_clone_voice(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncAudioVoices:
async def test_async_voices_list(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_logid = mock_list_voices(respx_mock)

Expand All @@ -100,7 +100,7 @@ async def test_async_voices_list(self, respx_mock):
assert len(voices) == 1

async def test_async_clone_voice(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_voice = mock_clone_voice(respx_mock)

Expand Down
12 changes: 6 additions & 6 deletions tests/test_bots.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import httpx
import pytest

from cozepy import AsyncCoze, Bot, Coze, SimpleBot, TokenAuth
from cozepy import AsyncCoze, AsyncTokenAuth, Bot, Coze, SimpleBot, TokenAuth
from cozepy.util import random_hex
from tests.test_util import logid_key

Expand Down Expand Up @@ -189,7 +189,7 @@ def test_sync_bots_list(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncBots:
async def test_async_bots_create(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_bot = mock_create_bot(respx_mock)

Expand All @@ -200,7 +200,7 @@ async def test_async_bots_create(self, respx_mock):
assert bot.bot_id == mock_bot.bot_id

async def test_async_bots_update(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_logid = mock_update_bot(respx_mock)

Expand All @@ -210,7 +210,7 @@ async def test_async_bots_update(self, respx_mock):
assert res.response.logid == mock_logid

async def test_async_bots_publish(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_bot = mock_publish_bot(respx_mock)

Expand All @@ -221,7 +221,7 @@ async def test_async_bots_publish(self, respx_mock):
assert bot.bot_id == mock_bot.bot_id

async def test_async_bots_retrieve(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_bot = mock_retrieve_bot(respx_mock)

Expand All @@ -232,7 +232,7 @@ async def test_async_bots_retrieve(self, respx_mock):
assert bot.bot_id == mock_bot.bot_id

async def test_async_bots_list(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

space_id = random_hex(10)
total = 10
Expand Down
21 changes: 11 additions & 10 deletions tests/test_chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from cozepy import (
AsyncCoze,
AsyncTokenAuth,
Chat,
ChatError,
ChatEvent,
Expand Down Expand Up @@ -357,7 +358,7 @@ def test_sync_chat_poll(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncChatConversationMessage:
async def test_async_chat_create(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

conversation_id = "conversation_id"
mock_logid = mock_chat_create(respx_mock, conversation_id, ChatStatus.FAILED)
Expand All @@ -369,7 +370,7 @@ async def test_async_chat_create(self, respx_mock):
assert res.conversation_id == conversation_id

async def test_async_chat_stream(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_chat_stream(respx_mock, read_file("testdata/chat_text_stream_resp.txt"))
stream = coze.chat.stream(bot_id="bot", user_id="user")
Expand Down Expand Up @@ -399,7 +400,7 @@ async def test_async_chat_stream(self, respx_mock):
assert events[len(events) - 1].event == ChatEventType.CONVERSATION_CHAT_COMPLETED

async def test_async_chat_audio_stream(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_logid = mock_chat_stream(respx_mock, read_file("testdata/chat_audio_stream_resp.txt")) # noqa: F841
stream = coze.chat.stream(
Expand All @@ -424,7 +425,7 @@ async def test_async_chat_audio_stream(self, respx_mock):
assert os.path.exists(temp_filename)

async def test_async_chat_stream_error(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_logid = mock_chat_stream(respx_mock, read_file("testdata/chat_error_resp.txt")) # noqa: F841
stream = coze.chat.stream(bot_id="bot", user_id="user")
Expand All @@ -433,7 +434,7 @@ async def test_async_chat_stream_error(self, respx_mock):
[event async for event in stream]

async def test_async_chat_stream_failed(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_logid = mock_chat_stream(respx_mock, read_file("testdata/chat_failed_resp.txt")) # noqa: F841
stream = coze.chat.stream(bot_id="bot", user_id="user")
Expand All @@ -444,7 +445,7 @@ async def test_async_chat_stream_failed(self, respx_mock):
assert events[0].chat.last_error.code == 5000

async def test_async_chat_stream_invalid_event(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_logid = mock_chat_stream(respx_mock, read_file("testdata/chat_invalid_resp.txt")) # noqa: F841

Expand All @@ -454,7 +455,7 @@ async def test_async_chat_stream_invalid_event(self, respx_mock):
[event async for event in stream]

async def test_async_chat_retrieve(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

conversation_id = "conversation_id"
mock_logid = mock_chat_retrieve(respx_mock, conversation_id, ChatStatus.FAILED)
Expand All @@ -466,7 +467,7 @@ async def test_async_chat_retrieve(self, respx_mock):
assert res.conversation_id == conversation_id

async def test_async_submit_tool_outputs_not_stream(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

conversation_id = "conversation_id"
mock_logid = mock_chat_submit_tool_outputs(respx_mock, conversation_id, ChatStatus.FAILED)
Expand All @@ -478,7 +479,7 @@ async def test_async_submit_tool_outputs_not_stream(self, respx_mock):
assert res.conversation_id == conversation_id

async def test_async_submit_tool_outputs_stream(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_chat_submit_tool_outputs_stream(respx_mock, read_file("testdata/chat_text_stream_resp.txt"))
stream = coze.chat.submit_tool_outputs_stream(conversation_id="conversation", chat_id="chat", tool_outputs=[])
Expand Down Expand Up @@ -508,7 +509,7 @@ async def test_async_submit_tool_outputs_stream(self, respx_mock):
assert events[len(events) - 1].event == ChatEventType.CONVERSATION_CHAT_COMPLETED

async def test_async_chat_cancel(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

conversation_id = "conversation_id"
mock_logid = mock_chat_cancel(respx_mock, conversation_id, ChatStatus.FAILED)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_chat_messages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import httpx
import pytest

from cozepy import AsyncCoze, Coze, Message, TokenAuth
from cozepy import AsyncCoze, AsyncTokenAuth, Coze, Message, TokenAuth
from cozepy.util import random_hex
from tests.test_util import logid_key

Expand Down Expand Up @@ -39,7 +39,7 @@ def test_sync_chat_messages_list(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncChatMessages:
async def test_async_chat_messages_list(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

msg, msg2, logid = mock_chat_messages_list(respx_mock)

Expand Down
10 changes: 5 additions & 5 deletions tests/test_conversations.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import httpx
import pytest

from cozepy import AsyncCoze, Conversation, Coze, Section, TokenAuth
from cozepy import AsyncCoze, AsyncTokenAuth, Conversation, Coze, Section, TokenAuth
from cozepy.util import random_hex
from tests.test_util import logid_key

Expand Down Expand Up @@ -152,7 +152,7 @@ def test_sync_conversations_clear(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncConversation:
async def test_async_conversations_create(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

bot_id = random_hex(10)
mock_conversation = mock_create_conversations(respx_mock)
Expand All @@ -164,7 +164,7 @@ async def test_async_conversations_create(self, respx_mock):
assert res.last_section_id == mock_conversation.last_section_id

async def test_async_conversations_list(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

total = 10
size = 1
Expand Down Expand Up @@ -196,7 +196,7 @@ async def test_async_conversations_list(self, respx_mock):
assert total_result == total

async def test_async_conversations_retrieve(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_conversation = mock_retrieve_conversation(respx_mock)

Expand All @@ -207,7 +207,7 @@ async def test_async_conversations_retrieve(self, respx_mock):
assert res.last_section_id == mock_conversation.last_section_id

async def test_async_conversations_clear(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_section = mock_clear_conversation(respx_mock)

Expand Down
12 changes: 6 additions & 6 deletions tests/test_conversations_messages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import httpx
import pytest

from cozepy import AsyncCoze, Coze, Message, TokenAuth
from cozepy import AsyncCoze, AsyncTokenAuth, Coze, Message, TokenAuth
from cozepy.util import random_hex
from tests.test_util import logid_key

Expand Down Expand Up @@ -159,7 +159,7 @@ def test_sync_conversations_messages_delete(self, respx_mock):
@pytest.mark.asyncio
class TestAsyncConversationMessage:
async def test_async_conversations_messages_create(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_msg = mock_create_conversations_messages(respx_mock, Message.build_assistant_answer("hi"))

Expand All @@ -174,7 +174,7 @@ async def test_async_conversations_messages_create(self, respx_mock):
assert message.content == mock_msg.content

async def test_async_conversations_messages_list(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

total = 10
size = 1
Expand Down Expand Up @@ -206,7 +206,7 @@ async def test_async_conversations_messages_list(self, respx_mock):
assert total_result == total

async def test_async_conversations_messages_retrieve(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_msg = mock_retrieve_conversations_messages(respx_mock, Message.build_user_question_text("hi"))

Expand All @@ -216,7 +216,7 @@ async def test_async_conversations_messages_retrieve(self, respx_mock):
assert message.content == mock_msg.content

async def test_async_conversations_messages_update(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))
mock_msg = mock_update_conversations_messages(respx_mock, Message.build_user_question_text("hi"))

message = await coze.conversations.messages.update(conversation_id="conversation id", message_id="message id")
Expand All @@ -225,7 +225,7 @@ async def test_async_conversations_messages_update(self, respx_mock):
assert message.content == mock_msg.content

async def test_async_conversations_messages_delete(self, respx_mock):
coze = AsyncCoze(auth=TokenAuth(token="token"))
coze = AsyncCoze(auth=AsyncTokenAuth(token="token"))

mock_msg = mock_delete_conversations_messages(respx_mock, Message.build_user_question_text("hi"))

Expand Down
Loading

0 comments on commit 3627d58

Please sign in to comment.