openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.29.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/beta/chatkit/test_threads.py

348lines · modeblame

9ada2c74stainless-app[bot]8 months ago1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncConversationCursorPage, AsyncConversationCursorPage
13from openai.types.beta.chatkit import ChatKitThread, ThreadDeleteResponse
14from openai.types.beta.chatkit.chatkit_thread_item_list import Data
15
16base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
17
18
19class TestThreads:
20parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
21
22@parametrize
23def test_method_retrieve(self, client: OpenAI) -> None:
24thread = client.beta.chatkit.threads.retrieve(
25"cthr_123",
26)
27assert_matches_type(ChatKitThread, thread, path=["response"])
28
29@parametrize
30def test_raw_response_retrieve(self, client: OpenAI) -> None:
31response = client.beta.chatkit.threads.with_raw_response.retrieve(
32"cthr_123",
33)
34
35assert response.is_closed is True
36assert response.http_request.headers.get("X-Stainless-Lang") == "python"
37thread = response.parse()
38assert_matches_type(ChatKitThread, thread, path=["response"])
39
40@parametrize
41def test_streaming_response_retrieve(self, client: OpenAI) -> None:
42with client.beta.chatkit.threads.with_streaming_response.retrieve(
43"cthr_123",
44) as response:
45assert not response.is_closed
46assert response.http_request.headers.get("X-Stainless-Lang") == "python"
47
48thread = response.parse()
49assert_matches_type(ChatKitThread, thread, path=["response"])
50
51assert cast(Any, response.is_closed) is True
52
53@parametrize
54def test_path_params_retrieve(self, client: OpenAI) -> None:
55with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
56client.beta.chatkit.threads.with_raw_response.retrieve(
57"",
58)
59
60@parametrize
61def test_method_list(self, client: OpenAI) -> None:
62thread = client.beta.chatkit.threads.list()
63assert_matches_type(SyncConversationCursorPage[ChatKitThread], thread, path=["response"])
64
65@parametrize
66def test_method_list_with_all_params(self, client: OpenAI) -> None:
67thread = client.beta.chatkit.threads.list(
68after="after",
69before="before",
70limit=0,
71order="asc",
72user="x",
73)
74assert_matches_type(SyncConversationCursorPage[ChatKitThread], thread, path=["response"])
75
76@parametrize
77def test_raw_response_list(self, client: OpenAI) -> None:
78response = client.beta.chatkit.threads.with_raw_response.list()
79
80assert response.is_closed is True
81assert response.http_request.headers.get("X-Stainless-Lang") == "python"
82thread = response.parse()
83assert_matches_type(SyncConversationCursorPage[ChatKitThread], thread, path=["response"])
84
85@parametrize
86def test_streaming_response_list(self, client: OpenAI) -> None:
87with client.beta.chatkit.threads.with_streaming_response.list() as response:
88assert not response.is_closed
89assert response.http_request.headers.get("X-Stainless-Lang") == "python"
90
91thread = response.parse()
92assert_matches_type(SyncConversationCursorPage[ChatKitThread], thread, path=["response"])
93
94assert cast(Any, response.is_closed) is True
95
96@parametrize
97def test_method_delete(self, client: OpenAI) -> None:
98thread = client.beta.chatkit.threads.delete(
99"cthr_123",
100)
101assert_matches_type(ThreadDeleteResponse, thread, path=["response"])
102
103@parametrize
104def test_raw_response_delete(self, client: OpenAI) -> None:
105response = client.beta.chatkit.threads.with_raw_response.delete(
106"cthr_123",
107)
108
109assert response.is_closed is True
110assert response.http_request.headers.get("X-Stainless-Lang") == "python"
111thread = response.parse()
112assert_matches_type(ThreadDeleteResponse, thread, path=["response"])
113
114@parametrize
115def test_streaming_response_delete(self, client: OpenAI) -> None:
116with client.beta.chatkit.threads.with_streaming_response.delete(
117"cthr_123",
118) as response:
119assert not response.is_closed
120assert response.http_request.headers.get("X-Stainless-Lang") == "python"
121
122thread = response.parse()
123assert_matches_type(ThreadDeleteResponse, thread, path=["response"])
124
125assert cast(Any, response.is_closed) is True
126
127@parametrize
128def test_path_params_delete(self, client: OpenAI) -> None:
129with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
130client.beta.chatkit.threads.with_raw_response.delete(
131"",
132)
133
134@parametrize
135def test_method_list_items(self, client: OpenAI) -> None:
136thread = client.beta.chatkit.threads.list_items(
137thread_id="cthr_123",
138)
139assert_matches_type(SyncConversationCursorPage[Data], thread, path=["response"])
140
141@parametrize
142def test_method_list_items_with_all_params(self, client: OpenAI) -> None:
143thread = client.beta.chatkit.threads.list_items(
144thread_id="cthr_123",
145after="after",
146before="before",
147limit=0,
148order="asc",
149)
150assert_matches_type(SyncConversationCursorPage[Data], thread, path=["response"])
151
152@parametrize
153def test_raw_response_list_items(self, client: OpenAI) -> None:
154response = client.beta.chatkit.threads.with_raw_response.list_items(
155thread_id="cthr_123",
156)
157
158assert response.is_closed is True
159assert response.http_request.headers.get("X-Stainless-Lang") == "python"
160thread = response.parse()
161assert_matches_type(SyncConversationCursorPage[Data], thread, path=["response"])
162
163@parametrize
164def test_streaming_response_list_items(self, client: OpenAI) -> None:
165with client.beta.chatkit.threads.with_streaming_response.list_items(
166thread_id="cthr_123",
167) as response:
168assert not response.is_closed
169assert response.http_request.headers.get("X-Stainless-Lang") == "python"
170
171thread = response.parse()
172assert_matches_type(SyncConversationCursorPage[Data], thread, path=["response"])
173
174assert cast(Any, response.is_closed) is True
175
176@parametrize
177def test_path_params_list_items(self, client: OpenAI) -> None:
178with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
179client.beta.chatkit.threads.with_raw_response.list_items(
180thread_id="",
181)
182
183
184class TestAsyncThreads:
185parametrize = pytest.mark.parametrize(
186"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
187)
188
189@parametrize
190async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
191thread = await async_client.beta.chatkit.threads.retrieve(
192"cthr_123",
193)
194assert_matches_type(ChatKitThread, thread, path=["response"])
195
196@parametrize
197async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
198response = await async_client.beta.chatkit.threads.with_raw_response.retrieve(
199"cthr_123",
200)
201
202assert response.is_closed is True
203assert response.http_request.headers.get("X-Stainless-Lang") == "python"
204thread = response.parse()
205assert_matches_type(ChatKitThread, thread, path=["response"])
206
207@parametrize
208async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
209async with async_client.beta.chatkit.threads.with_streaming_response.retrieve(
210"cthr_123",
211) as response:
212assert not response.is_closed
213assert response.http_request.headers.get("X-Stainless-Lang") == "python"
214
215thread = await response.parse()
216assert_matches_type(ChatKitThread, thread, path=["response"])
217
218assert cast(Any, response.is_closed) is True
219
220@parametrize
221async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
222with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
223await async_client.beta.chatkit.threads.with_raw_response.retrieve(
224"",
225)
226
227@parametrize
228async def test_method_list(self, async_client: AsyncOpenAI) -> None:
229thread = await async_client.beta.chatkit.threads.list()
230assert_matches_type(AsyncConversationCursorPage[ChatKitThread], thread, path=["response"])
231
232@parametrize
233async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
234thread = await async_client.beta.chatkit.threads.list(
235after="after",
236before="before",
237limit=0,
238order="asc",
239user="x",
240)
241assert_matches_type(AsyncConversationCursorPage[ChatKitThread], thread, path=["response"])
242
243@parametrize
244async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
245response = await async_client.beta.chatkit.threads.with_raw_response.list()
246
247assert response.is_closed is True
248assert response.http_request.headers.get("X-Stainless-Lang") == "python"
249thread = response.parse()
250assert_matches_type(AsyncConversationCursorPage[ChatKitThread], thread, path=["response"])
251
252@parametrize
253async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
254async with async_client.beta.chatkit.threads.with_streaming_response.list() as response:
255assert not response.is_closed
256assert response.http_request.headers.get("X-Stainless-Lang") == "python"
257
258thread = await response.parse()
259assert_matches_type(AsyncConversationCursorPage[ChatKitThread], thread, path=["response"])
260
261assert cast(Any, response.is_closed) is True
262
263@parametrize
264async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
265thread = await async_client.beta.chatkit.threads.delete(
266"cthr_123",
267)
268assert_matches_type(ThreadDeleteResponse, thread, path=["response"])
269
270@parametrize
271async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
272response = await async_client.beta.chatkit.threads.with_raw_response.delete(
273"cthr_123",
274)
275
276assert response.is_closed is True
277assert response.http_request.headers.get("X-Stainless-Lang") == "python"
278thread = response.parse()
279assert_matches_type(ThreadDeleteResponse, thread, path=["response"])
280
281@parametrize
282async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
283async with async_client.beta.chatkit.threads.with_streaming_response.delete(
284"cthr_123",
285) as response:
286assert not response.is_closed
287assert response.http_request.headers.get("X-Stainless-Lang") == "python"
288
289thread = await response.parse()
290assert_matches_type(ThreadDeleteResponse, thread, path=["response"])
291
292assert cast(Any, response.is_closed) is True
293
294@parametrize
295async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
296with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
297await async_client.beta.chatkit.threads.with_raw_response.delete(
298"",
299)
300
301@parametrize
302async def test_method_list_items(self, async_client: AsyncOpenAI) -> None:
303thread = await async_client.beta.chatkit.threads.list_items(
304thread_id="cthr_123",
305)
306assert_matches_type(AsyncConversationCursorPage[Data], thread, path=["response"])
307
308@parametrize
309async def test_method_list_items_with_all_params(self, async_client: AsyncOpenAI) -> None:
310thread = await async_client.beta.chatkit.threads.list_items(
311thread_id="cthr_123",
312after="after",
313before="before",
314limit=0,
315order="asc",
316)
317assert_matches_type(AsyncConversationCursorPage[Data], thread, path=["response"])
318
319@parametrize
320async def test_raw_response_list_items(self, async_client: AsyncOpenAI) -> None:
321response = await async_client.beta.chatkit.threads.with_raw_response.list_items(
322thread_id="cthr_123",
323)
324
325assert response.is_closed is True
326assert response.http_request.headers.get("X-Stainless-Lang") == "python"
327thread = response.parse()
328assert_matches_type(AsyncConversationCursorPage[Data], thread, path=["response"])
329
330@parametrize
331async def test_streaming_response_list_items(self, async_client: AsyncOpenAI) -> None:
332async with async_client.beta.chatkit.threads.with_streaming_response.list_items(
333thread_id="cthr_123",
334) as response:
335assert not response.is_closed
336assert response.http_request.headers.get("X-Stainless-Lang") == "python"
337
338thread = await response.parse()
339assert_matches_type(AsyncConversationCursorPage[Data], thread, path=["response"])
340
341assert cast(Any, response.is_closed) is True
342
343@parametrize
344async def test_path_params_list_items(self, async_client: AsyncOpenAI) -> None:
345with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
346await async_client.beta.chatkit.threads.with_raw_response.list_items(
347thread_id="",
348)