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_runs.py

308lines · 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 Run
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestRuns:
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:
26run = client.beta.threads.runs.create(
27"string",
28assistant_id="string",
29)
30assert_matches_type(Run, run, path=["response"])
31
32@parametrize
33def test_method_create_with_all_params(self, client: OpenAI) -> None:
34run = client.beta.threads.runs.create(
35"string",
36assistant_id="string",
37instructions="string",
38metadata={},
39model="string",
40tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
41)
42assert_matches_type(Run, run, path=["response"])
43
44@parametrize
45def test_raw_response_create(self, client: OpenAI) -> None:
46response = client.beta.threads.runs.with_raw_response.create(
47"string",
48assistant_id="string",
49)
50assert response.http_request.headers.get("X-Stainless-Lang") == "python"
51run = response.parse()
52assert_matches_type(Run, run, path=["response"])
53
54@parametrize
55def test_method_retrieve(self, client: OpenAI) -> None:
56run = client.beta.threads.runs.retrieve(
57"string",
58thread_id="string",
59)
60assert_matches_type(Run, run, path=["response"])
61
62@parametrize
63def test_raw_response_retrieve(self, client: OpenAI) -> None:
64response = client.beta.threads.runs.with_raw_response.retrieve(
65"string",
66thread_id="string",
67)
68assert response.http_request.headers.get("X-Stainless-Lang") == "python"
69run = response.parse()
70assert_matches_type(Run, run, path=["response"])
71
72@parametrize
73def test_method_update(self, client: OpenAI) -> None:
74run = client.beta.threads.runs.update(
75"string",
76thread_id="string",
77)
78assert_matches_type(Run, run, path=["response"])
79
80@parametrize
81def test_method_update_with_all_params(self, client: OpenAI) -> None:
82run = client.beta.threads.runs.update(
83"string",
84thread_id="string",
85metadata={},
86)
87assert_matches_type(Run, run, path=["response"])
88
89@parametrize
90def test_raw_response_update(self, client: OpenAI) -> None:
91response = client.beta.threads.runs.with_raw_response.update(
92"string",
93thread_id="string",
94)
95assert response.http_request.headers.get("X-Stainless-Lang") == "python"
96run = response.parse()
97assert_matches_type(Run, run, path=["response"])
98
99@parametrize
100def test_method_list(self, client: OpenAI) -> None:
101run = client.beta.threads.runs.list(
102"string",
103)
104assert_matches_type(SyncCursorPage[Run], run, path=["response"])
105
106@parametrize
107def test_method_list_with_all_params(self, client: OpenAI) -> None:
108run = client.beta.threads.runs.list(
109"string",
110after="string",
111before="string",
112limit=0,
113order="asc",
114)
115assert_matches_type(SyncCursorPage[Run], run, path=["response"])
116
117@parametrize
118def test_raw_response_list(self, client: OpenAI) -> None:
119response = client.beta.threads.runs.with_raw_response.list(
120"string",
121)
122assert response.http_request.headers.get("X-Stainless-Lang") == "python"
123run = response.parse()
124assert_matches_type(SyncCursorPage[Run], run, path=["response"])
125
126@parametrize
127def test_method_cancel(self, client: OpenAI) -> None:
128run = client.beta.threads.runs.cancel(
129"string",
130thread_id="string",
131)
132assert_matches_type(Run, run, path=["response"])
133
134@parametrize
135def test_raw_response_cancel(self, client: OpenAI) -> None:
136response = client.beta.threads.runs.with_raw_response.cancel(
137"string",
138thread_id="string",
139)
140assert response.http_request.headers.get("X-Stainless-Lang") == "python"
141run = response.parse()
142assert_matches_type(Run, run, path=["response"])
143
144@parametrize
145def test_method_submit_tool_outputs(self, client: OpenAI) -> None:
146run = client.beta.threads.runs.submit_tool_outputs(
147"string",
148thread_id="string",
149tool_outputs=[{}, {}, {}],
150)
151assert_matches_type(Run, run, path=["response"])
152
153@parametrize
154def test_raw_response_submit_tool_outputs(self, client: OpenAI) -> None:
155response = client.beta.threads.runs.with_raw_response.submit_tool_outputs(
156"string",
157thread_id="string",
158tool_outputs=[{}, {}, {}],
159)
160assert response.http_request.headers.get("X-Stainless-Lang") == "python"
161run = response.parse()
162assert_matches_type(Run, run, path=["response"])
163
164
165class TestAsyncRuns:
166strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
167loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
168parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
169
170@parametrize
171async def test_method_create(self, client: AsyncOpenAI) -> None:
172run = await client.beta.threads.runs.create(
173"string",
174assistant_id="string",
175)
176assert_matches_type(Run, run, path=["response"])
177
178@parametrize
179async def test_method_create_with_all_params(self, client: AsyncOpenAI) -> None:
180run = await client.beta.threads.runs.create(
181"string",
182assistant_id="string",
183instructions="string",
184metadata={},
185model="string",
186tools=[{"type": "code_interpreter"}, {"type": "code_interpreter"}, {"type": "code_interpreter"}],
187)
188assert_matches_type(Run, run, path=["response"])
189
190@parametrize
191async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
192response = await client.beta.threads.runs.with_raw_response.create(
193"string",
194assistant_id="string",
195)
196assert response.http_request.headers.get("X-Stainless-Lang") == "python"
197run = response.parse()
198assert_matches_type(Run, run, path=["response"])
199
200@parametrize
201async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
202run = await client.beta.threads.runs.retrieve(
203"string",
204thread_id="string",
205)
206assert_matches_type(Run, run, path=["response"])
207
208@parametrize
209async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
210response = await client.beta.threads.runs.with_raw_response.retrieve(
211"string",
212thread_id="string",
213)
214assert response.http_request.headers.get("X-Stainless-Lang") == "python"
215run = response.parse()
216assert_matches_type(Run, run, path=["response"])
217
218@parametrize
219async def test_method_update(self, client: AsyncOpenAI) -> None:
220run = await client.beta.threads.runs.update(
221"string",
222thread_id="string",
223)
224assert_matches_type(Run, run, path=["response"])
225
226@parametrize
227async def test_method_update_with_all_params(self, client: AsyncOpenAI) -> None:
228run = await client.beta.threads.runs.update(
229"string",
230thread_id="string",
231metadata={},
232)
233assert_matches_type(Run, run, path=["response"])
234
235@parametrize
236async def test_raw_response_update(self, client: AsyncOpenAI) -> None:
237response = await client.beta.threads.runs.with_raw_response.update(
238"string",
239thread_id="string",
240)
241assert response.http_request.headers.get("X-Stainless-Lang") == "python"
242run = response.parse()
243assert_matches_type(Run, run, path=["response"])
244
245@parametrize
246async def test_method_list(self, client: AsyncOpenAI) -> None:
247run = await client.beta.threads.runs.list(
248"string",
249)
250assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
251
252@parametrize
253async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None:
254run = await client.beta.threads.runs.list(
255"string",
256after="string",
257before="string",
258limit=0,
259order="asc",
260)
261assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
262
263@parametrize
264async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
265response = await client.beta.threads.runs.with_raw_response.list(
266"string",
267)
268assert response.http_request.headers.get("X-Stainless-Lang") == "python"
269run = response.parse()
270assert_matches_type(AsyncCursorPage[Run], run, path=["response"])
271
272@parametrize
273async def test_method_cancel(self, client: AsyncOpenAI) -> None:
274run = await client.beta.threads.runs.cancel(
275"string",
276thread_id="string",
277)
278assert_matches_type(Run, run, path=["response"])
279
280@parametrize
281async def test_raw_response_cancel(self, client: AsyncOpenAI) -> None:
282response = await client.beta.threads.runs.with_raw_response.cancel(
283"string",
284thread_id="string",
285)
286assert response.http_request.headers.get("X-Stainless-Lang") == "python"
287run = response.parse()
288assert_matches_type(Run, run, path=["response"])
289
290@parametrize
291async def test_method_submit_tool_outputs(self, client: AsyncOpenAI) -> None:
292run = await client.beta.threads.runs.submit_tool_outputs(
293"string",
294thread_id="string",
295tool_outputs=[{}, {}, {}],
296)
297assert_matches_type(Run, run, path=["response"])
298
299@parametrize
300async def test_raw_response_submit_tool_outputs(self, client: AsyncOpenAI) -> None:
301response = await client.beta.threads.runs.with_raw_response.submit_tool_outputs(
302"string",
303thread_id="string",
304tool_outputs=[{}, {}, {}],
305)
306assert response.http_request.headers.get("X-Stainless-Lang") == "python"
307run = response.parse()
308assert_matches_type(Run, run, path=["response"])