openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.3.7

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/test_messages.py

234lines · modeblame

baa9f07fRobert Craigie2 years ago1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
6
7import pytest
8
9from openai import OpenAI, AsyncOpenAI
10from tests.utils import assert_matches_type
11from openai._client import OpenAI, AsyncOpenAI
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.beta.threads import ThreadMessage
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestMessages:
20strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
21loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
22parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
23
24@parametrize
25def test_method_create(self, client: OpenAI) -> None:
26message = client.beta.threads.messages.create(
27"string",
28content="x",
29role="user",
30)
31assert_matches_type(ThreadMessage, message, path=["response"])
32
33@parametrize
34def test_method_create_with_all_params(self, client: OpenAI) -> None:
35message = client.beta.threads.messages.create(
36"string",
37content="x",
38role="user",
39file_ids=["string"],
40metadata={},
41)
42assert_matches_type(ThreadMessage, message, path=["response"])
43
44@parametrize
45def test_raw_response_create(self, client: OpenAI) -> None:
46response = client.beta.threads.messages.with_raw_response.create(
47"string",
48content="x",
49role="user",
50)
51assert response.http_request.headers.get("X-Stainless-Lang") == "python"
52message = response.parse()
53assert_matches_type(ThreadMessage, message, path=["response"])
54
55@parametrize
56def test_method_retrieve(self, client: OpenAI) -> None:
57message = client.beta.threads.messages.retrieve(
58"string",
59thread_id="string",
60)
61assert_matches_type(ThreadMessage, message, path=["response"])
62
63@parametrize
64def test_raw_response_retrieve(self, client: OpenAI) -> None:
65response = client.beta.threads.messages.with_raw_response.retrieve(
66"string",
67thread_id="string",
68)
69assert response.http_request.headers.get("X-Stainless-Lang") == "python"
70message = response.parse()
71assert_matches_type(ThreadMessage, message, path=["response"])
72
73@parametrize
74def test_method_update(self, client: OpenAI) -> None:
75message = client.beta.threads.messages.update(
76"string",
77thread_id="string",
78)
79assert_matches_type(ThreadMessage, message, path=["response"])
80
81@parametrize
82def test_method_update_with_all_params(self, client: OpenAI) -> None:
83message = client.beta.threads.messages.update(
84"string",
85thread_id="string",
86metadata={},
87)
88assert_matches_type(ThreadMessage, message, path=["response"])
89
90@parametrize
91def test_raw_response_update(self, client: OpenAI) -> None:
92response = client.beta.threads.messages.with_raw_response.update(
93"string",
94thread_id="string",
95)
96assert response.http_request.headers.get("X-Stainless-Lang") == "python"
97message = response.parse()
98assert_matches_type(ThreadMessage, message, path=["response"])
99
100@parametrize
101def test_method_list(self, client: OpenAI) -> None:
102message = client.beta.threads.messages.list(
103"string",
104)
105assert_matches_type(SyncCursorPage[ThreadMessage], message, path=["response"])
106
107@parametrize
108def test_method_list_with_all_params(self, client: OpenAI) -> None:
109message = client.beta.threads.messages.list(
110"string",
111after="string",
112before="string",
113limit=0,
114order="asc",
115)
116assert_matches_type(SyncCursorPage[ThreadMessage], message, path=["response"])
117
118@parametrize
119def test_raw_response_list(self, client: OpenAI) -> None:
120response = client.beta.threads.messages.with_raw_response.list(
121"string",
122)
123assert response.http_request.headers.get("X-Stainless-Lang") == "python"
124message = response.parse()
125assert_matches_type(SyncCursorPage[ThreadMessage], message, path=["response"])
126
127
128class TestAsyncMessages:
129strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
130loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
131parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
132
133@parametrize
134async def test_method_create(self, client: AsyncOpenAI) -> None:
135message = await client.beta.threads.messages.create(
136"string",
137content="x",
138role="user",
139)
140assert_matches_type(ThreadMessage, message, path=["response"])
141
142@parametrize
143async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
144message = await client.beta.threads.messages.create(
145"string",
146content="x",
147role="user",
148file_ids=["string"],
149metadata={},
150)
151assert_matches_type(ThreadMessage, message, path=["response"])
152
153@parametrize
154async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
155response = await client.beta.threads.messages.with_raw_response.create(
156"string",
157content="x",
158role="user",
159)
160assert response.http_request.headers.get("X-Stainless-Lang") == "python"
161message = response.parse()
162assert_matches_type(ThreadMessage, message, path=["response"])
163
164@parametrize
165async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
166message = await client.beta.threads.messages.retrieve(
167"string",
168thread_id="string",
169)
170assert_matches_type(ThreadMessage, message, path=["response"])
171
172@parametrize
173async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
174response = await client.beta.threads.messages.with_raw_response.retrieve(
175"string",
176thread_id="string",
177)
178assert response.http_request.headers.get("X-Stainless-Lang") == "python"
179message = response.parse()
180assert_matches_type(ThreadMessage, message, path=["response"])
181
182@parametrize
183async def test_method_update(self, client: AsyncOpenAI) -> None:
184message = await client.beta.threads.messages.update(
185"string",
186thread_id="string",
187)
188assert_matches_type(ThreadMessage, message, path=["response"])
189
190@parametrize
191async def test_method_update_with_all_params(self, client: AsyncOpenAI) -> None:
192message = await client.beta.threads.messages.update(
193"string",
194thread_id="string",
195metadata={},
196)
197assert_matches_type(ThreadMessage, message, path=["response"])
198
199@parametrize
200async def test_raw_response_update(self, client: AsyncOpenAI) -> None:
201response = await client.beta.threads.messages.with_raw_response.update(
202"string",
203thread_id="string",
204)
205assert response.http_request.headers.get("X-Stainless-Lang") == "python"
206message = response.parse()
207assert_matches_type(ThreadMessage, message, path=["response"])
208
209@parametrize
210async def test_method_list(self, client: AsyncOpenAI) -> None:
211message = await client.beta.threads.messages.list(
212"string",
213)
214assert_matches_type(AsyncCursorPage[ThreadMessage], message, path=["response"])
215
216@parametrize
217async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None:
218message = await client.beta.threads.messages.list(
219"string",
220after="string",
221before="string",
222limit=0,
223order="asc",
224)
225assert_matches_type(AsyncCursorPage[ThreadMessage], message, path=["response"])
226
227@parametrize
228async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
229response = await client.beta.threads.messages.with_raw_response.list(
230"string",
231)
232assert response.http_request.headers.get("X-Stainless-Lang") == "python"
233message = response.parse()
234assert_matches_type(AsyncCursorPage[ThreadMessage], message, path=["response"])