From c6fd8924c66c7368f75f27123d62d16185498db7 Mon Sep 17 00:00:00 2001 From: admin Date: Tue, 4 Mar 2025 10:20:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=9B=E5=BB=BAAsyncJWTAuth=E7=B1=BB?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=BC=82=E6=AD=A5=E6=9B=B4=E6=96=B0=E9=89=B4?= =?UTF-8?q?=E6=9D=83=E7=A0=81=20=E4=BF=AE=E5=A4=8D=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E7=9A=84=E9=89=B4=E6=9D=83=E8=B0=83=E7=94=A8=EF=BC=8C=E5=8C=85?= =?UTF-8?q?=E6=8B=ACRequester=E5=92=8C=E4=B8=8A=E5=B1=82=E5=BC=82=E6=AD=A5?= =?UTF-8?q?=E8=B0=83=E7=94=A8=20=E4=BF=AE=E6=94=B9AsyncCoze=E5=AF=B9?= =?UTF-8?q?=E8=B1=A1=E7=9A=84auth=E5=B1=9E=E6=80=A7=E4=B8=BAAsyncAuth?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cozepy/bots/__init__.py | 4 ++-- cozepy/chat/__init__.py | 4 ++-- cozepy/chat/message/__init__.py | 4 ++-- cozepy/conversations/__init__.py | 4 ++-- cozepy/conversations/message/__init__.py | 4 ++-- cozepy/coze.py | 2 +- cozepy/files/__init__.py | 4 ++-- cozepy/knowledge/__init__.py | 4 ++-- cozepy/knowledge/documents/__init__.py | 4 ++-- tests/test_audio_rooms.py | 3 ++- tests/test_audio_speech.py | 3 ++- tests/test_audio_translations.py | 3 ++- tests/test_audio_voices.py | 5 +++-- tests/test_bots.py | 11 ++++++----- tests/test_chat.py | 21 +++++++++++---------- tests/test_chat_messages.py | 3 ++- tests/test_conversations.py | 9 +++++---- tests/test_conversations_messages.py | 11 ++++++----- tests/test_datasets.py | 11 ++++++----- tests/test_datasets_documents.py | 11 ++++++----- tests/test_datasets_images.py | 5 +++-- tests/test_file.py | 5 +++-- tests/test_knowledge_documents.py | 15 ++++++++------- tests/test_template.py | 3 ++- tests/test_users.py | 3 ++- tests/test_workflows.py | 13 +++++++------ tests/test_workflows_chat.py | 9 +++++---- tests/test_workspaces.py | 3 ++- 28 files changed, 100 insertions(+), 81 deletions(-) diff --git a/cozepy/bots/__init__.py b/cozepy/bots/__init__.py index 180b699..0db348c 100644 --- a/cozepy/bots/__init__.py +++ b/cozepy/bots/__init__.py @@ -1,7 +1,7 @@ from enum import IntEnum from typing import List, Optional -from cozepy.auth import Auth +from cozepy.auth import Auth, AsyncAuth from cozepy.model import AsyncNumberPaged, CozeModel, NumberPaged, NumberPagedResponse from cozepy.request import HTTPRequest, Requester from cozepy.util import remove_url_trailing_slash @@ -284,7 +284,7 @@ class AsyncBotsClient(object): Bot class. """ - def __init__(self, base_url: str, auth: Auth, requester: Requester): + def __init__(self, base_url: str, auth: AsyncAuth, requester: Requester): self._base_url = remove_url_trailing_slash(base_url) self._auth = auth self._requester = requester diff --git a/cozepy/chat/__init__.py b/cozepy/chat/__init__.py index 984d7eb..c358c19 100644 --- a/cozepy/chat/__init__.py +++ b/cozepy/chat/__init__.py @@ -7,7 +7,7 @@ import httpx from typing_extensions import Literal -from cozepy.auth import Auth +from cozepy.auth import Auth, AsyncAuth from cozepy.model import AsyncIteratorHTTPResponse, AsyncStream, CozeModel, IteratorHTTPResponse, ListResponse, Stream from cozepy.request import Requester from cozepy.util import remove_url_trailing_slash @@ -763,7 +763,7 @@ def messages( class AsyncChatClient(object): - def __init__(self, base_url: str, auth: Auth, requester: Requester): + def __init__(self, base_url: str, auth: AsyncAuth, requester: Requester): self._base_url = remove_url_trailing_slash(base_url) self._auth = auth self._requester = requester diff --git a/cozepy/chat/message/__init__.py b/cozepy/chat/message/__init__.py index 01c0577..b08b5ae 100644 --- a/cozepy/chat/message/__init__.py +++ b/cozepy/chat/message/__init__.py @@ -1,4 +1,4 @@ -from cozepy.auth import Auth +from cozepy.auth import Auth, AsyncAuth from cozepy.chat import Message from cozepy.model import ListResponse from cozepy.request import Requester @@ -37,7 +37,7 @@ def list( class AsyncChatMessagesClient(object): - def __init__(self, base_url: str, auth: Auth, requester: Requester): + def __init__(self, base_url: str, auth: AsyncAuth, requester: Requester): self._base_url = remove_url_trailing_slash(base_url) self._auth = auth self._requester = requester diff --git a/cozepy/conversations/__init__.py b/cozepy/conversations/__init__.py index 710daad..219f1c4 100644 --- a/cozepy/conversations/__init__.py +++ b/cozepy/conversations/__init__.py @@ -1,6 +1,6 @@ from typing import Any, Dict, List, Optional -from cozepy.auth import Auth +from cozepy.auth import Auth, AsyncAuth from cozepy.chat import Message from cozepy.model import AsyncNumberPaged, CozeModel, HTTPRequest, NumberPaged from cozepy.request import Requester @@ -129,7 +129,7 @@ def messages(self): class AsyncConversationsClient(object): - def __init__(self, base_url: str, auth: Auth, requester: Requester): + def __init__(self, base_url: str, auth: AsyncAuth, requester: Requester): self._base_url = remove_url_trailing_slash(base_url) self._auth = auth self._requester = requester diff --git a/cozepy/conversations/message/__init__.py b/cozepy/conversations/message/__init__.py index 36b42d4..30bbd24 100644 --- a/cozepy/conversations/message/__init__.py +++ b/cozepy/conversations/message/__init__.py @@ -1,6 +1,6 @@ from typing import Dict, List, Optional -from cozepy.auth import Auth +from cozepy.auth import Auth, AsyncAuth from cozepy.chat import Message, MessageContentType, MessageRole from cozepy.model import AsyncLastIDPaged, CozeModel, HTTPRequest, LastIDPaged, LastIDPagedResponse from cozepy.request import Requester @@ -215,7 +215,7 @@ class AsyncMessagesClient(object): Message class. """ - def __init__(self, base_url: str, auth: Auth, requester: Requester): + def __init__(self, base_url: str, auth: AsyncAuth, requester: Requester): self._base_url = remove_url_trailing_slash(base_url) self._auth = auth self._requester = requester diff --git a/cozepy/coze.py b/cozepy/coze.py index 333b5b2..86c418d 100644 --- a/cozepy/coze.py +++ b/cozepy/coze.py @@ -149,7 +149,7 @@ def __init__( ): self._auth = auth self._base_url = remove_url_trailing_slash(base_url) - self._requester = Requester(auth=auth, async_client=http_client) + self._requester = Requester(async_auth=auth, async_client=http_client) # service client self._bots: Optional[AsyncBotsClient] = None diff --git a/cozepy/files/__init__.py b/cozepy/files/__init__.py index 0414214..7e1a947 100644 --- a/cozepy/files/__init__.py +++ b/cozepy/files/__init__.py @@ -2,7 +2,7 @@ from pathlib import Path from typing import IO, Optional, Tuple, Union -from cozepy.auth import Auth +from cozepy.auth import Auth, AsyncAuth from cozepy.model import CozeModel from cozepy.request import Requester from cozepy.util import remove_url_trailing_slash @@ -93,7 +93,7 @@ def retrieve(self, *, file_id: str): class AsyncFilesClient(object): - def __init__(self, base_url: str, auth: Auth, requester: Requester): + def __init__(self, base_url: str, auth: AsyncAuth, requester: Requester): self._base_url = remove_url_trailing_slash(base_url) self._auth = auth self._requester = requester diff --git a/cozepy/knowledge/__init__.py b/cozepy/knowledge/__init__.py index 507584e..088871f 100644 --- a/cozepy/knowledge/__init__.py +++ b/cozepy/knowledge/__init__.py @@ -1,7 +1,7 @@ import warnings from typing import TYPE_CHECKING, Optional -from cozepy.auth import Auth +from cozepy.auth import Auth, AsyncAuth from cozepy.request import Requester from cozepy.util import remove_url_trailing_slash @@ -38,7 +38,7 @@ def documents(self) -> "DocumentsClient": class AsyncKnowledgeClient(object): - def __init__(self, base_url: str, auth: Auth, requester: Requester): + def __init__(self, base_url: str, auth: AsyncAuth, requester: Requester): warnings.warn( "The 'coze.knowledge' module is deprecated and will be removed in a future version. " "Please use 'coze.datasets' instead.", diff --git a/cozepy/knowledge/documents/__init__.py b/cozepy/knowledge/documents/__init__.py index 7a1fe14..57f9938 100644 --- a/cozepy/knowledge/documents/__init__.py +++ b/cozepy/knowledge/documents/__init__.py @@ -1,7 +1,7 @@ import warnings from typing import List, Optional -from cozepy.auth import Auth +from cozepy.auth import Auth, AsyncAuth from cozepy.datasets.documents import ( Document, # noqa DocumentBase, # noqa @@ -212,7 +212,7 @@ def request_maker(i_page_num: int, i_page_size: int) -> HTTPRequest: class AsyncDocumentsClient(object): - def __init__(self, base_url: str, auth: Auth, requester: Requester): + def __init__(self, base_url: str, auth: AsyncAuth, requester: Requester): warnings.warn( "The 'coze.knowledge.documents' module is deprecated and will be removed in a future version. " "Please use 'coze.datasets.documents' instead.", diff --git a/tests/test_audio_rooms.py b/tests/test_audio_rooms.py index 9198d2c..d8302a8 100644 --- a/tests/test_audio_rooms.py +++ b/tests/test_audio_rooms.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, CreateRoomResp, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -45,7 +46,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) diff --git a/tests/test_audio_speech.py b/tests/test_audio_speech.py index 1aef630..6bc5bbc 100644 --- a/tests/test_audio_speech.py +++ b/tests/test_audio_speech.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -39,7 +40,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) diff --git a/tests/test_audio_translations.py b/tests/test_audio_translations.py index b494cb5..1704b3b 100644 --- a/tests/test_audio_translations.py +++ b/tests/test_audio_translations.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -41,7 +42,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) diff --git a/tests/test_audio_voices.py b/tests/test_audio_voices.py index 3746b71..c82d7f3 100644 --- a/tests/test_audio_voices.py +++ b/tests/test_audio_voices.py @@ -4,6 +4,7 @@ import pytest from cozepy import AsyncCoze, AudioFormat, Coze, TokenAuth, Voice +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -88,7 +89,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) @@ -100,7 +101,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) diff --git a/tests/test_bots.py b/tests/test_bots.py index 222f475..48e77e6 100644 --- a/tests/test_bots.py +++ b/tests/test_bots.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Bot, Coze, SimpleBot, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -189,7 +190,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) @@ -200,7 +201,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) @@ -210,7 +211,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) @@ -221,7 +222,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) @@ -232,7 +233,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 diff --git a/tests/test_chat.py b/tests/test_chat.py index 14a4137..40728da 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -18,6 +18,7 @@ MessageObjectString, TokenAuth, ) +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex, write_pcm_to_wav_file from tests.test_util import logid_key, read_file @@ -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) @@ -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") @@ -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( @@ -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") @@ -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") @@ -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 @@ -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) @@ -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) @@ -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=[]) @@ -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) diff --git a/tests/test_chat_messages.py b/tests/test_chat_messages.py index 3bc7dea..4079eb1 100644 --- a/tests/test_chat_messages.py +++ b/tests/test_chat_messages.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, Message, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -39,7 +40,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) diff --git a/tests/test_conversations.py b/tests/test_conversations.py index 53437b7..2c285c7 100644 --- a/tests/test_conversations.py +++ b/tests/test_conversations.py @@ -4,6 +4,7 @@ import pytest from cozepy import AsyncCoze, Conversation, Coze, Section, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -152,7 +153,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) @@ -164,7 +165,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 @@ -196,7 +197,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) @@ -207,7 +208,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) diff --git a/tests/test_conversations_messages.py b/tests/test_conversations_messages.py index 2922255..40bad5a 100644 --- a/tests/test_conversations_messages.py +++ b/tests/test_conversations_messages.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, Message, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -159,7 +160,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")) @@ -174,7 +175,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 @@ -206,7 +207,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")) @@ -216,7 +217,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") @@ -225,7 +226,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")) diff --git a/tests/test_datasets.py b/tests/test_datasets.py index 09be4c5..d16a210 100644 --- a/tests/test_datasets.py +++ b/tests/test_datasets.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.datasets import Dataset, DatasetStatus, DocumentFormatType, DocumentProgress from cozepy.datasets.documents import DocumentStatus, DocumentUpdateType from cozepy.util import random_hex @@ -182,7 +183,7 @@ def test_sync_datasets_process(self, respx_mock): @pytest.mark.asyncio class TestAsyncDataset: async def test_async_datasets_create(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) dataset_id, mock_logid = mock_create_datasets(respx_mock) @@ -192,7 +193,7 @@ async def test_async_datasets_create(self, respx_mock): assert dataset.dataset_id == dataset_id async def test_async_datasets_list(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) space_id = random_hex(10) total = 10 @@ -225,7 +226,7 @@ async def test_async_datasets_list(self, respx_mock): assert total_result == total async def test_async_datasets_update(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) dataset_id, mock_logid = mock_update_datasets(respx_mock) @@ -234,7 +235,7 @@ async def test_async_datasets_update(self, respx_mock): assert res.response.logid == mock_logid async def test_async_datasets_delete(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) dataset_id, mock_logid = mock_delete_datasets(respx_mock) @@ -243,7 +244,7 @@ async def test_async_datasets_delete(self, respx_mock): assert res.response.logid == mock_logid async def test_async_datasets_process(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) dataset_id, document_id, mock_logid = mock_process_datasets(respx_mock) diff --git a/tests/test_datasets_documents.py b/tests/test_datasets_documents.py index 33ed206..8f81ae6 100644 --- a/tests/test_datasets_documents.py +++ b/tests/test_datasets_documents.py @@ -17,6 +17,7 @@ DocumentUpdateType, TokenAuth, ) +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -200,7 +201,7 @@ def test_sync_datasets_documents_list(self, respx_mock): @pytest.mark.asyncio class TestAsyncDatasetsDocuments: async def test_async_datasets_documents_create_web_auto_update(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_document = mock_create_datasets_documents(respx_mock) @@ -220,7 +221,7 @@ async def test_async_datasets_documents_create_web_auto_update(self, respx_mock) assert len(documents) == 1 async def test_async_datasets_documents_create_local_custom(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_document = mock_create_datasets_documents(respx_mock) @@ -240,7 +241,7 @@ async def test_async_datasets_documents_create_local_custom(self, respx_mock): assert len(documents) == 1 async def test_async_datasets_documents_update(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_document = mock_update_datasets_documents(respx_mock) @@ -249,7 +250,7 @@ async def test_async_datasets_documents_update(self, respx_mock): assert res.response.logid == mock_document.response.logid async def test_async_datasets_documents_delete(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_document = mock_delete_datasets_documents(respx_mock) @@ -258,7 +259,7 @@ async def test_async_datasets_documents_delete(self, respx_mock): assert res.response.logid == mock_document.response.logid async def test_async_datasets_documents_list(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) total = 10 size = 1 diff --git a/tests/test_datasets_images.py b/tests/test_datasets_images.py index 58708a0..0656b77 100644 --- a/tests/test_datasets_images.py +++ b/tests/test_datasets_images.py @@ -6,6 +6,7 @@ Coze, TokenAuth, ) +from cozepy.auth import AsyncTokenAuth from cozepy.datasets.documents import DocumentSourceType from cozepy.datasets.images import Photo, PhotoStatus from cozepy.util import random_hex @@ -101,7 +102,7 @@ def test_sync_datasets_images_list(self, respx_mock): @pytest.mark.asyncio class TestAsyncDatasetsDocuments: async def test_sync_datasets_images_update(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) dataset_id, document_id, mock_logid = mock_update_datasets_images(respx_mock) @@ -110,7 +111,7 @@ async def test_sync_datasets_images_update(self, respx_mock): assert res.response.logid == mock_logid async def test_sync_datasets_images_list(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) dataset_id = random_hex(10) total = 10 diff --git a/tests/test_file.py b/tests/test_file.py index 5889f42..d5b18a2 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -5,6 +5,7 @@ import pytest from cozepy import AsyncCoze, Coze, File, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.files import _try_fix_file from cozepy.util import random_hex from tests.test_util import logid_key @@ -70,7 +71,7 @@ def test_sync_files_retrieve(self, respx_mock): @pytest.mark.asyncio class TestAsyncFiles: async def test_async_files_upload(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_file = mock_upload_files(respx_mock) @@ -81,7 +82,7 @@ async def test_async_files_upload(self, respx_mock): assert file.file_name == "name" async def test_async_files_retrieve(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_file = mock_retrieve_files(respx_mock) diff --git a/tests/test_knowledge_documents.py b/tests/test_knowledge_documents.py index 253a97a..808ca2c 100644 --- a/tests/test_knowledge_documents.py +++ b/tests/test_knowledge_documents.py @@ -17,6 +17,7 @@ DocumentUpdateType, TokenAuth, ) +from cozepy.auth import AsyncTokenAuth @pytest.fixture(autouse=True) @@ -223,7 +224,7 @@ def test_sync_knowledge_documents_page_iterator(self, respx_mock): @pytest.mark.asyncio class TestAsyncKnowledgeDocuments: async def test_sync_knowledge_documents_create_web_auto_update(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) respx_mock.post("/open_api/knowledge/document/create").mock( httpx.Response( @@ -247,7 +248,7 @@ async def test_sync_knowledge_documents_create_web_auto_update(self, respx_mock) assert len(documents) == 1 async def test_sync_knowledge_documents_create_local_custom(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) respx_mock.post("/open_api/knowledge/document/create").mock( httpx.Response( @@ -271,21 +272,21 @@ async def test_sync_knowledge_documents_create_local_custom(self, respx_mock): assert len(documents) == 1 async def test_sync_knowledge_documents_update(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) respx_mock.post("/open_api/knowledge/document/update").mock(httpx.Response(200, json={"data": None})) await coze.knowledge.documents.update(document_id="id", document_name="name") async def test_sync_knowledge_documents_delete(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) respx_mock.post("/open_api/knowledge/document/delete").mock(httpx.Response(200, json={"data": None})) await coze.knowledge.documents.delete(document_ids=["id"]) async def test_sync_knowledge_documents_list(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) total = 10 mock_documents_list(respx_mock, total, 1) @@ -295,7 +296,7 @@ async def test_sync_knowledge_documents_list(self, respx_mock): assert resp.total == total async def test_async_knowledge_documents_iterator(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) total = 10 for idx in range(total): @@ -311,7 +312,7 @@ async def test_async_knowledge_documents_iterator(self, respx_mock): assert total_result == total async def test_async_knowledge_documents_page_iterator(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) total = 10 for idx in range(total): diff --git a/tests/test_template.py b/tests/test_template.py index 635d5f8..6b9e35d 100644 --- a/tests/test_template.py +++ b/tests/test_template.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, TemplateDuplicateResp, TokenAuth +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex @@ -39,7 +40,7 @@ def test_sync_template_duplicate(self, respx_mock): @pytest.mark.asyncio class TestAsyncTemplate: async def test_async_template_duplicate(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) entity_id = random_hex(10) entity_type = "agent" diff --git a/tests/test_users.py b/tests/test_users.py index 288fcf5..1cf21c8 100644 --- a/tests/test_users.py +++ b/tests/test_users.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, TokenAuth, User +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key @@ -41,7 +42,7 @@ def test_sync_users_retrieve_me(self, respx_mock): @pytest.mark.asyncio class TestAsyncUsers: async def test_async_users_retrieve_me(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_user = mock_retrieve_users_me(respx_mock) diff --git a/tests/test_workflows.py b/tests/test_workflows.py index ef26b9a..64f6b19 100644 --- a/tests/test_workflows.py +++ b/tests/test_workflows.py @@ -10,6 +10,7 @@ WorkflowRunMode, WorkflowRunResult, ) +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key, read_file @@ -166,7 +167,7 @@ def test_sync_workflows_runs_run_histories_retrieve(self, respx_mock): @pytest.mark.asyncio class TestAsyncWorkflowsRuns: async def test_async_workflows_runs_create_no_async(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_res = mock_create_workflows_runs(respx_mock, False) @@ -176,7 +177,7 @@ async def test_async_workflows_runs_create_no_async(self, respx_mock): assert res.data == "data" async def test_async_workflows_runs_create_async(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_res = mock_create_workflows_runs(respx_mock, True) @@ -187,7 +188,7 @@ async def test_async_workflows_runs_create_async(self, respx_mock): assert res.execute_id == mock_res.execute_id async def test_async_workflows_runs_stream(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_create_workflows_runs_stream(respx_mock, read_file("testdata/workflow_run_stream_resp.txt")) stream = coze.workflows.runs.stream(workflow_id="id") @@ -196,7 +197,7 @@ async def test_async_workflows_runs_stream(self, respx_mock): assert len(events) == 9 async def test_async_workflows_runs_resume(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_create_workflows_runs_resume(respx_mock, read_file("testdata/workflow_run_stream_resp.txt")) stream = coze.workflows.runs.resume( @@ -210,7 +211,7 @@ async def test_async_workflows_runs_resume(self, respx_mock): assert len(events) == 9 async def test_async_workflows_runs_invalid_stream_event(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_create_workflows_runs_resume(respx_mock, read_file("testdata/workflow_run_invalid_stream_resp.txt")) stream = coze.workflows.runs.resume( @@ -223,7 +224,7 @@ async def test_async_workflows_runs_invalid_stream_event(self, respx_mock): [event async for event in stream] async def test_async_workflows_runs_run_histories_retrieve(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) workflow_id, execute_id, current_logid, execute_logid = mock_create_workflows_runs_run_histories_retrieve( respx_mock diff --git a/tests/test_workflows_chat.py b/tests/test_workflows_chat.py index 5a87579..82c087d 100644 --- a/tests/test_workflows_chat.py +++ b/tests/test_workflows_chat.py @@ -12,6 +12,7 @@ Coze, TokenAuth, ) +from cozepy.auth import AsyncTokenAuth from cozepy.util import random_hex from tests.test_util import logid_key, read_file @@ -118,7 +119,7 @@ def test_sync_chat_stream_invalid_event(self, respx_mock): @pytest.mark.asyncio class TestAsyncWorkflowsChat: async def test_async_workflows_chat_stream(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_workflows_chat_stream(respx_mock, read_file("testdata/workflows_chat_stream_resp.txt")) stream = coze.workflows.chat.stream(workflow_id="workflow", bot_id="bot") @@ -147,7 +148,7 @@ async def test_async_workflows_chat_stream(self, respx_mock): assert events[len(events) - 1].event == ChatEventType.CONVERSATION_CHAT_COMPLETED async def test_async_chat_stream_error(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) mock_workflows_chat_stream(respx_mock, read_file("testdata/chat_error_resp.txt")) stream = coze.workflows.chat.stream(workflow_id="workflow", bot_id="bot") @@ -157,7 +158,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_workflows_chat_stream(respx_mock, read_file("testdata/chat_failed_resp.txt")) stream = coze.workflows.chat.stream(workflow_id="workflow", bot_id="bot") @@ -169,7 +170,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_workflows_chat_stream(respx_mock, read_file("testdata/chat_invalid_resp.txt")) diff --git a/tests/test_workspaces.py b/tests/test_workspaces.py index d0f25a9..9cb859a 100644 --- a/tests/test_workspaces.py +++ b/tests/test_workspaces.py @@ -2,6 +2,7 @@ import pytest from cozepy import AsyncCoze, Coze, TokenAuth, Workspace, WorkspaceRoleType, WorkspaceType +from cozepy.auth import AsyncTokenAuth def mock_list_workspaces(respx_mock, total_count, page): @@ -70,7 +71,7 @@ def test_sync_workspaces_list(self, respx_mock): @pytest.mark.asyncio class TestAsyncWorkspaces: async def test_async_workspaces_list(self, respx_mock): - coze = AsyncCoze(auth=TokenAuth(token="token")) + coze = AsyncCoze(auth=AsyncTokenAuth(token="token")) total = 10 size = 1