openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.97.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_messages.py

622lines · modeblame

5cfb125aStainless Bot2 years ago1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
baa9f07fRobert Craigie2 years ago2
3from __future__ import annotations
4
5import os
86379b44Stainless Bot2 years ago6from typing import Any, cast
baa9f07fRobert Craigie2 years ago7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncCursorPage, AsyncCursorPage
d2738d42Stainless Bot2 years ago13from openai.types.beta.threads import (
14Message,
15MessageDeleted,
16)
baa9f07fRobert Craigie2 years ago17
cca09707stainless-app[bot]1 years ago18# pyright: reportDeprecated=false
19
baa9f07fRobert Craigie2 years ago20base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
21
22
23class TestMessages:
98d779fbStainless Bot2 years ago24parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago25
26@parametrize
27def test_method_create(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago28with pytest.warns(DeprecationWarning):
29message = client.beta.threads.messages.create(
30thread_id="thread_id",
31content="string",
32role="user",
33)
34
5429f696Stainless Bot2 years ago35assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago36
37@parametrize
38def test_method_create_with_all_params(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago39with pytest.warns(DeprecationWarning):
40message = client.beta.threads.messages.create(
41thread_id="thread_id",
42content="string",
43role="user",
44attachments=[
45{
46"file_id": "file_id",
47"tools": [{"type": "code_interpreter"}],
48}
49],
50metadata={"foo": "string"},
51)
52
5429f696Stainless Bot2 years ago53assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago54
55@parametrize
56def test_raw_response_create(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago57with pytest.warns(DeprecationWarning):
58response = client.beta.threads.messages.with_raw_response.create(
59thread_id="thread_id",
60content="string",
61role="user",
62)
86379b44Stainless Bot2 years ago63
64assert response.is_closed is True
baa9f07fRobert Craigie2 years ago65assert response.http_request.headers.get("X-Stainless-Lang") == "python"
66message = response.parse()
5429f696Stainless Bot2 years ago67assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago68
86379b44Stainless Bot2 years ago69@parametrize
70def test_streaming_response_create(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago71with pytest.warns(DeprecationWarning):
72with client.beta.threads.messages.with_streaming_response.create(
73thread_id="thread_id",
74content="string",
75role="user",
76) as response:
77assert not response.is_closed
78assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago79
cca09707stainless-app[bot]1 years ago80message = response.parse()
81assert_matches_type(Message, message, path=["response"])
86379b44Stainless Bot2 years ago82
83assert cast(Any, response.is_closed) is True
84
023a4e66Stainless Bot2 years ago85@parametrize
86def test_path_params_create(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago87with pytest.warns(DeprecationWarning):
88with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
89client.beta.threads.messages.with_raw_response.create(
90thread_id="",
91content="string",
92role="user",
93)
023a4e66Stainless Bot2 years ago94
baa9f07fRobert Craigie2 years ago95@parametrize
96def test_method_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago97with pytest.warns(DeprecationWarning):
98message = client.beta.threads.messages.retrieve(
99message_id="message_id",
100thread_id="thread_id",
101)
102
5429f696Stainless Bot2 years ago103assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago104
105@parametrize
106def test_raw_response_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago107with pytest.warns(DeprecationWarning):
108response = client.beta.threads.messages.with_raw_response.retrieve(
109message_id="message_id",
110thread_id="thread_id",
111)
86379b44Stainless Bot2 years ago112
113assert response.is_closed is True
baa9f07fRobert Craigie2 years ago114assert response.http_request.headers.get("X-Stainless-Lang") == "python"
115message = response.parse()
5429f696Stainless Bot2 years ago116assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago117
86379b44Stainless Bot2 years ago118@parametrize
119def test_streaming_response_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago120with pytest.warns(DeprecationWarning):
121with client.beta.threads.messages.with_streaming_response.retrieve(
122message_id="message_id",
123thread_id="thread_id",
124) as response:
125assert not response.is_closed
126assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago127
cca09707stainless-app[bot]1 years ago128message = response.parse()
129assert_matches_type(Message, message, path=["response"])
86379b44Stainless Bot2 years ago130
131assert cast(Any, response.is_closed) is True
132
023a4e66Stainless Bot2 years ago133@parametrize
134def test_path_params_retrieve(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago135with pytest.warns(DeprecationWarning):
136with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
137client.beta.threads.messages.with_raw_response.retrieve(
138message_id="message_id",
139thread_id="",
140)
023a4e66Stainless Bot2 years ago141
cca09707stainless-app[bot]1 years ago142with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"):
143client.beta.threads.messages.with_raw_response.retrieve(
144message_id="",
145thread_id="thread_id",
146)
023a4e66Stainless Bot2 years ago147
baa9f07fRobert Craigie2 years ago148@parametrize
149def test_method_update(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago150with pytest.warns(DeprecationWarning):
151message = client.beta.threads.messages.update(
152message_id="message_id",
153thread_id="thread_id",
154)
155
5429f696Stainless Bot2 years ago156assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago157
158@parametrize
159def test_method_update_with_all_params(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago160with pytest.warns(DeprecationWarning):
161message = client.beta.threads.messages.update(
162message_id="message_id",
163thread_id="thread_id",
164metadata={"foo": "string"},
165)
166
5429f696Stainless Bot2 years ago167assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago168
169@parametrize
170def test_raw_response_update(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago171with pytest.warns(DeprecationWarning):
172response = client.beta.threads.messages.with_raw_response.update(
173message_id="message_id",
174thread_id="thread_id",
175)
86379b44Stainless Bot2 years ago176
177assert response.is_closed is True
baa9f07fRobert Craigie2 years ago178assert response.http_request.headers.get("X-Stainless-Lang") == "python"
179message = response.parse()
5429f696Stainless Bot2 years ago180assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago181
86379b44Stainless Bot2 years ago182@parametrize
183def test_streaming_response_update(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago184with pytest.warns(DeprecationWarning):
185with client.beta.threads.messages.with_streaming_response.update(
186message_id="message_id",
187thread_id="thread_id",
188) as response:
189assert not response.is_closed
190assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago191
cca09707stainless-app[bot]1 years ago192message = response.parse()
193assert_matches_type(Message, message, path=["response"])
86379b44Stainless Bot2 years ago194
195assert cast(Any, response.is_closed) is True
196
023a4e66Stainless Bot2 years ago197@parametrize
198def test_path_params_update(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago199with pytest.warns(DeprecationWarning):
200with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
201client.beta.threads.messages.with_raw_response.update(
202message_id="message_id",
203thread_id="",
204)
023a4e66Stainless Bot2 years ago205
cca09707stainless-app[bot]1 years ago206with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"):
207client.beta.threads.messages.with_raw_response.update(
208message_id="",
209thread_id="thread_id",
210)
023a4e66Stainless Bot2 years ago211
baa9f07fRobert Craigie2 years ago212@parametrize
213def test_method_list(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago214with pytest.warns(DeprecationWarning):
215message = client.beta.threads.messages.list(
216thread_id="thread_id",
217)
218
5429f696Stainless Bot2 years ago219assert_matches_type(SyncCursorPage[Message], message, path=["response"])
baa9f07fRobert Craigie2 years ago220
221@parametrize
222def test_method_list_with_all_params(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago223with pytest.warns(DeprecationWarning):
224message = client.beta.threads.messages.list(
225thread_id="thread_id",
226after="after",
227before="before",
228limit=0,
229order="asc",
230run_id="run_id",
231)
232
5429f696Stainless Bot2 years ago233assert_matches_type(SyncCursorPage[Message], message, path=["response"])
baa9f07fRobert Craigie2 years ago234
235@parametrize
236def test_raw_response_list(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago237with pytest.warns(DeprecationWarning):
238response = client.beta.threads.messages.with_raw_response.list(
239thread_id="thread_id",
240)
86379b44Stainless Bot2 years ago241
242assert response.is_closed is True
baa9f07fRobert Craigie2 years ago243assert response.http_request.headers.get("X-Stainless-Lang") == "python"
244message = response.parse()
5429f696Stainless Bot2 years ago245assert_matches_type(SyncCursorPage[Message], message, path=["response"])
baa9f07fRobert Craigie2 years ago246
86379b44Stainless Bot2 years ago247@parametrize
248def test_streaming_response_list(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago249with pytest.warns(DeprecationWarning):
250with client.beta.threads.messages.with_streaming_response.list(
251thread_id="thread_id",
252) as response:
253assert not response.is_closed
254assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago255
cca09707stainless-app[bot]1 years ago256message = response.parse()
257assert_matches_type(SyncCursorPage[Message], message, path=["response"])
86379b44Stainless Bot2 years ago258
259assert cast(Any, response.is_closed) is True
260
023a4e66Stainless Bot2 years ago261@parametrize
262def test_path_params_list(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago263with pytest.warns(DeprecationWarning):
264with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
265client.beta.threads.messages.with_raw_response.list(
266thread_id="",
267)
023a4e66Stainless Bot2 years ago268
d2738d42Stainless Bot2 years ago269@parametrize
270def test_method_delete(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago271with pytest.warns(DeprecationWarning):
272message = client.beta.threads.messages.delete(
273message_id="message_id",
274thread_id="thread_id",
275)
276
d2738d42Stainless Bot2 years ago277assert_matches_type(MessageDeleted, message, path=["response"])
278
279@parametrize
280def test_raw_response_delete(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago281with pytest.warns(DeprecationWarning):
282response = client.beta.threads.messages.with_raw_response.delete(
283message_id="message_id",
284thread_id="thread_id",
285)
d2738d42Stainless Bot2 years ago286
287assert response.is_closed is True
288assert response.http_request.headers.get("X-Stainless-Lang") == "python"
289message = response.parse()
290assert_matches_type(MessageDeleted, message, path=["response"])
291
292@parametrize
293def test_streaming_response_delete(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago294with pytest.warns(DeprecationWarning):
295with client.beta.threads.messages.with_streaming_response.delete(
296message_id="message_id",
297thread_id="thread_id",
298) as response:
299assert not response.is_closed
300assert response.http_request.headers.get("X-Stainless-Lang") == "python"
d2738d42Stainless Bot2 years ago301
cca09707stainless-app[bot]1 years ago302message = response.parse()
303assert_matches_type(MessageDeleted, message, path=["response"])
d2738d42Stainless Bot2 years ago304
305assert cast(Any, response.is_closed) is True
306
307@parametrize
308def test_path_params_delete(self, client: OpenAI) -> None:
cca09707stainless-app[bot]1 years ago309with pytest.warns(DeprecationWarning):
310with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
311client.beta.threads.messages.with_raw_response.delete(
312message_id="message_id",
313thread_id="",
314)
d2738d42Stainless Bot2 years ago315
cca09707stainless-app[bot]1 years ago316with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"):
317client.beta.threads.messages.with_raw_response.delete(
318message_id="",
319thread_id="thread_id",
320)
d2738d42Stainless Bot2 years ago321
baa9f07fRobert Craigie2 years ago322
323class TestAsyncMessages:
c62e9907stainless-app[bot]1 years ago324parametrize = pytest.mark.parametrize(
325"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
326)
baa9f07fRobert Craigie2 years ago327
328@parametrize
98d779fbStainless Bot2 years ago329async def test_method_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago330with pytest.warns(DeprecationWarning):
331message = await async_client.beta.threads.messages.create(
332thread_id="thread_id",
333content="string",
334role="user",
335)
336
5429f696Stainless Bot2 years ago337assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago338
339@parametrize
98d779fbStainless Bot2 years ago340async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago341with pytest.warns(DeprecationWarning):
342message = await async_client.beta.threads.messages.create(
343thread_id="thread_id",
344content="string",
345role="user",
346attachments=[
347{
348"file_id": "file_id",
349"tools": [{"type": "code_interpreter"}],
350}
351],
352metadata={"foo": "string"},
353)
354
5429f696Stainless Bot2 years ago355assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago356
357@parametrize
98d779fbStainless Bot2 years ago358async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago359with pytest.warns(DeprecationWarning):
360response = await async_client.beta.threads.messages.with_raw_response.create(
361thread_id="thread_id",
362content="string",
363role="user",
364)
86379b44Stainless Bot2 years ago365
366assert response.is_closed is True
baa9f07fRobert Craigie2 years ago367assert response.http_request.headers.get("X-Stainless-Lang") == "python"
368message = response.parse()
5429f696Stainless Bot2 years ago369assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago370
86379b44Stainless Bot2 years ago371@parametrize
98d779fbStainless Bot2 years ago372async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago373with pytest.warns(DeprecationWarning):
374async with async_client.beta.threads.messages.with_streaming_response.create(
375thread_id="thread_id",
376content="string",
377role="user",
378) as response:
379assert not response.is_closed
380assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago381
cca09707stainless-app[bot]1 years ago382message = await response.parse()
383assert_matches_type(Message, message, path=["response"])
86379b44Stainless Bot2 years ago384
385assert cast(Any, response.is_closed) is True
386
023a4e66Stainless Bot2 years ago387@parametrize
98d779fbStainless Bot2 years ago388async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago389with pytest.warns(DeprecationWarning):
390with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
391await async_client.beta.threads.messages.with_raw_response.create(
392thread_id="",
393content="string",
394role="user",
395)
023a4e66Stainless Bot2 years ago396
baa9f07fRobert Craigie2 years ago397@parametrize
98d779fbStainless Bot2 years ago398async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago399with pytest.warns(DeprecationWarning):
400message = await async_client.beta.threads.messages.retrieve(
401message_id="message_id",
402thread_id="thread_id",
403)
404
5429f696Stainless Bot2 years ago405assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago406
407@parametrize
98d779fbStainless Bot2 years ago408async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago409with pytest.warns(DeprecationWarning):
410response = await async_client.beta.threads.messages.with_raw_response.retrieve(
411message_id="message_id",
412thread_id="thread_id",
413)
86379b44Stainless Bot2 years ago414
415assert response.is_closed is True
baa9f07fRobert Craigie2 years ago416assert response.http_request.headers.get("X-Stainless-Lang") == "python"
417message = response.parse()
5429f696Stainless Bot2 years ago418assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago419
86379b44Stainless Bot2 years ago420@parametrize
98d779fbStainless Bot2 years ago421async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago422with pytest.warns(DeprecationWarning):
423async with async_client.beta.threads.messages.with_streaming_response.retrieve(
424message_id="message_id",
425thread_id="thread_id",
426) as response:
427assert not response.is_closed
428assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago429
cca09707stainless-app[bot]1 years ago430message = await response.parse()
431assert_matches_type(Message, message, path=["response"])
86379b44Stainless Bot2 years ago432
433assert cast(Any, response.is_closed) is True
434
023a4e66Stainless Bot2 years ago435@parametrize
98d779fbStainless Bot2 years ago436async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago437with pytest.warns(DeprecationWarning):
438with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
439await async_client.beta.threads.messages.with_raw_response.retrieve(
440message_id="message_id",
441thread_id="",
442)
023a4e66Stainless Bot2 years ago443
cca09707stainless-app[bot]1 years ago444with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"):
445await async_client.beta.threads.messages.with_raw_response.retrieve(
446message_id="",
447thread_id="thread_id",
448)
023a4e66Stainless Bot2 years ago449
baa9f07fRobert Craigie2 years ago450@parametrize
98d779fbStainless Bot2 years ago451async def test_method_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago452with pytest.warns(DeprecationWarning):
453message = await async_client.beta.threads.messages.update(
454message_id="message_id",
455thread_id="thread_id",
456)
457
5429f696Stainless Bot2 years ago458assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago459
460@parametrize
98d779fbStainless Bot2 years ago461async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago462with pytest.warns(DeprecationWarning):
463message = await async_client.beta.threads.messages.update(
464message_id="message_id",
465thread_id="thread_id",
466metadata={"foo": "string"},
467)
468
5429f696Stainless Bot2 years ago469assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago470
471@parametrize
98d779fbStainless Bot2 years ago472async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago473with pytest.warns(DeprecationWarning):
474response = await async_client.beta.threads.messages.with_raw_response.update(
475message_id="message_id",
476thread_id="thread_id",
477)
86379b44Stainless Bot2 years ago478
479assert response.is_closed is True
baa9f07fRobert Craigie2 years ago480assert response.http_request.headers.get("X-Stainless-Lang") == "python"
481message = response.parse()
5429f696Stainless Bot2 years ago482assert_matches_type(Message, message, path=["response"])
baa9f07fRobert Craigie2 years ago483
86379b44Stainless Bot2 years ago484@parametrize
98d779fbStainless Bot2 years ago485async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago486with pytest.warns(DeprecationWarning):
487async with async_client.beta.threads.messages.with_streaming_response.update(
488message_id="message_id",
489thread_id="thread_id",
490) as response:
491assert not response.is_closed
492assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago493
cca09707stainless-app[bot]1 years ago494message = await response.parse()
495assert_matches_type(Message, message, path=["response"])
86379b44Stainless Bot2 years ago496
497assert cast(Any, response.is_closed) is True
498
023a4e66Stainless Bot2 years ago499@parametrize
98d779fbStainless Bot2 years ago500async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago501with pytest.warns(DeprecationWarning):
502with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
503await async_client.beta.threads.messages.with_raw_response.update(
504message_id="message_id",
505thread_id="",
506)
023a4e66Stainless Bot2 years ago507
cca09707stainless-app[bot]1 years ago508with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"):
509await async_client.beta.threads.messages.with_raw_response.update(
510message_id="",
511thread_id="thread_id",
512)
023a4e66Stainless Bot2 years ago513
baa9f07fRobert Craigie2 years ago514@parametrize
98d779fbStainless Bot2 years ago515async def test_method_list(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago516with pytest.warns(DeprecationWarning):
517message = await async_client.beta.threads.messages.list(
518thread_id="thread_id",
519)
520
5429f696Stainless Bot2 years ago521assert_matches_type(AsyncCursorPage[Message], message, path=["response"])
baa9f07fRobert Craigie2 years ago522
523@parametrize
98d779fbStainless Bot2 years ago524async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago525with pytest.warns(DeprecationWarning):
526message = await async_client.beta.threads.messages.list(
527thread_id="thread_id",
528after="after",
529before="before",
530limit=0,
531order="asc",
532run_id="run_id",
533)
534
5429f696Stainless Bot2 years ago535assert_matches_type(AsyncCursorPage[Message], message, path=["response"])
baa9f07fRobert Craigie2 years ago536
537@parametrize
98d779fbStainless Bot2 years ago538async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago539with pytest.warns(DeprecationWarning):
540response = await async_client.beta.threads.messages.with_raw_response.list(
541thread_id="thread_id",
542)
86379b44Stainless Bot2 years ago543
544assert response.is_closed is True
baa9f07fRobert Craigie2 years ago545assert response.http_request.headers.get("X-Stainless-Lang") == "python"
546message = response.parse()
5429f696Stainless Bot2 years ago547assert_matches_type(AsyncCursorPage[Message], message, path=["response"])
86379b44Stainless Bot2 years ago548
549@parametrize
98d779fbStainless Bot2 years ago550async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago551with pytest.warns(DeprecationWarning):
552async with async_client.beta.threads.messages.with_streaming_response.list(
553thread_id="thread_id",
554) as response:
555assert not response.is_closed
556assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86379b44Stainless Bot2 years ago557
cca09707stainless-app[bot]1 years ago558message = await response.parse()
559assert_matches_type(AsyncCursorPage[Message], message, path=["response"])
86379b44Stainless Bot2 years ago560
561assert cast(Any, response.is_closed) is True
023a4e66Stainless Bot2 years ago562
563@parametrize
98d779fbStainless Bot2 years ago564async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago565with pytest.warns(DeprecationWarning):
566with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
567await async_client.beta.threads.messages.with_raw_response.list(
568thread_id="",
569)
d2738d42Stainless Bot2 years ago570
571@parametrize
572async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago573with pytest.warns(DeprecationWarning):
574message = await async_client.beta.threads.messages.delete(
575message_id="message_id",
576thread_id="thread_id",
577)
578
d2738d42Stainless Bot2 years ago579assert_matches_type(MessageDeleted, message, path=["response"])
580
581@parametrize
582async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago583with pytest.warns(DeprecationWarning):
584response = await async_client.beta.threads.messages.with_raw_response.delete(
585message_id="message_id",
586thread_id="thread_id",
587)
d2738d42Stainless Bot2 years ago588
589assert response.is_closed is True
590assert response.http_request.headers.get("X-Stainless-Lang") == "python"
591message = response.parse()
592assert_matches_type(MessageDeleted, message, path=["response"])
593
594@parametrize
595async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago596with pytest.warns(DeprecationWarning):
597async with async_client.beta.threads.messages.with_streaming_response.delete(
598message_id="message_id",
599thread_id="thread_id",
600) as response:
601assert not response.is_closed
602assert response.http_request.headers.get("X-Stainless-Lang") == "python"
d2738d42Stainless Bot2 years ago603
cca09707stainless-app[bot]1 years ago604message = await response.parse()
605assert_matches_type(MessageDeleted, message, path=["response"])
d2738d42Stainless Bot2 years ago606
607assert cast(Any, response.is_closed) is True
608
609@parametrize
610async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
cca09707stainless-app[bot]1 years ago611with pytest.warns(DeprecationWarning):
612with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
613await async_client.beta.threads.messages.with_raw_response.delete(
614message_id="message_id",
615thread_id="",
616)
617
618with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"):
619await async_client.beta.threads.messages.with_raw_response.delete(
620message_id="",
621thread_id="thread_id",
622)