openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.8.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/threads/runs/test_steps.py

269lines · modeblame

baa9f07fRobert Craigie2 years ago1# File generated from our OpenAPI spec by Stainless.
2
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._client import OpenAI, AsyncOpenAI
13from openai.pagination import SyncCursorPage, AsyncCursorPage
14from openai.types.beta.threads.runs import RunStep
15
16base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
17api_key = "My API Key"
18
19
20class TestSteps:
21strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
22loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
23parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
24
25@parametrize
26def test_method_retrieve(self, client: OpenAI) -> None:
27step = client.beta.threads.runs.steps.retrieve(
28"string",
29thread_id="string",
30run_id="string",
31)
32assert_matches_type(RunStep, step, path=["response"])
33
34@parametrize
35def test_raw_response_retrieve(self, client: OpenAI) -> None:
36response = client.beta.threads.runs.steps.with_raw_response.retrieve(
37"string",
38thread_id="string",
39run_id="string",
40)
86379b44Stainless Bot2 years ago41
42assert response.is_closed is True
baa9f07fRobert Craigie2 years ago43assert response.http_request.headers.get("X-Stainless-Lang") == "python"
44step = response.parse()
45assert_matches_type(RunStep, step, path=["response"])
46
86379b44Stainless Bot2 years ago47@parametrize
48def test_streaming_response_retrieve(self, client: OpenAI) -> None:
49with client.beta.threads.runs.steps.with_streaming_response.retrieve(
50"string",
51thread_id="string",
52run_id="string",
53) as response:
54assert not response.is_closed
55assert response.http_request.headers.get("X-Stainless-Lang") == "python"
56
57step = response.parse()
58assert_matches_type(RunStep, step, path=["response"])
59
60assert cast(Any, response.is_closed) is True
61
023a4e66Stainless Bot2 years ago62@parametrize
63def test_path_params_retrieve(self, client: OpenAI) -> None:
64with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
65client.beta.threads.runs.steps.with_raw_response.retrieve(
66"string",
67thread_id="",
68run_id="string",
69)
70
71with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
72client.beta.threads.runs.steps.with_raw_response.retrieve(
73"string",
74thread_id="string",
75run_id="",
76)
77
78with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
79client.beta.threads.runs.steps.with_raw_response.retrieve(
80"",
81thread_id="string",
82run_id="string",
83)
84
baa9f07fRobert Craigie2 years ago85@parametrize
86def test_method_list(self, client: OpenAI) -> None:
87step = client.beta.threads.runs.steps.list(
88"string",
89thread_id="string",
90)
91assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
92
93@parametrize
94def test_method_list_with_all_params(self, client: OpenAI) -> None:
95step = client.beta.threads.runs.steps.list(
96"string",
97thread_id="string",
98after="string",
99before="string",
100limit=0,
101order="asc",
102)
103assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
104
105@parametrize
106def test_raw_response_list(self, client: OpenAI) -> None:
107response = client.beta.threads.runs.steps.with_raw_response.list(
108"string",
109thread_id="string",
110)
86379b44Stainless Bot2 years ago111
112assert response.is_closed is True
baa9f07fRobert Craigie2 years ago113assert response.http_request.headers.get("X-Stainless-Lang") == "python"
114step = response.parse()
115assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
116
86379b44Stainless Bot2 years ago117@parametrize
118def test_streaming_response_list(self, client: OpenAI) -> None:
119with client.beta.threads.runs.steps.with_streaming_response.list(
120"string",
121thread_id="string",
122) as response:
123assert not response.is_closed
124assert response.http_request.headers.get("X-Stainless-Lang") == "python"
125
126step = response.parse()
127assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
128
129assert cast(Any, response.is_closed) is True
130
023a4e66Stainless Bot2 years ago131@parametrize
132def test_path_params_list(self, client: OpenAI) -> None:
133with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
134client.beta.threads.runs.steps.with_raw_response.list(
135"string",
136thread_id="",
137)
138
139with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
140client.beta.threads.runs.steps.with_raw_response.list(
141"",
142thread_id="string",
143)
144
baa9f07fRobert Craigie2 years ago145
146class TestAsyncSteps:
147strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
148loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
149parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
150
151@parametrize
152async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
153step = await client.beta.threads.runs.steps.retrieve(
154"string",
155thread_id="string",
156run_id="string",
157)
158assert_matches_type(RunStep, step, path=["response"])
159
160@parametrize
161async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
162response = await client.beta.threads.runs.steps.with_raw_response.retrieve(
163"string",
164thread_id="string",
165run_id="string",
166)
86379b44Stainless Bot2 years ago167
168assert response.is_closed is True
baa9f07fRobert Craigie2 years ago169assert response.http_request.headers.get("X-Stainless-Lang") == "python"
170step = response.parse()
171assert_matches_type(RunStep, step, path=["response"])
172
86379b44Stainless Bot2 years ago173@parametrize
174async def test_streaming_response_retrieve(self, client: AsyncOpenAI) -> None:
175async with client.beta.threads.runs.steps.with_streaming_response.retrieve(
176"string",
177thread_id="string",
178run_id="string",
179) as response:
180assert not response.is_closed
181assert response.http_request.headers.get("X-Stainless-Lang") == "python"
182
183step = await response.parse()
184assert_matches_type(RunStep, step, path=["response"])
185
186assert cast(Any, response.is_closed) is True
187
023a4e66Stainless Bot2 years ago188@parametrize
189async def test_path_params_retrieve(self, client: AsyncOpenAI) -> None:
190with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
191await client.beta.threads.runs.steps.with_raw_response.retrieve(
192"string",
193thread_id="",
194run_id="string",
195)
196
197with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
198await client.beta.threads.runs.steps.with_raw_response.retrieve(
199"string",
200thread_id="string",
201run_id="",
202)
203
204with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
205await client.beta.threads.runs.steps.with_raw_response.retrieve(
206"",
207thread_id="string",
208run_id="string",
209)
210
baa9f07fRobert Craigie2 years ago211@parametrize
212async def test_method_list(self, client: AsyncOpenAI) -> None:
213step = await client.beta.threads.runs.steps.list(
214"string",
215thread_id="string",
216)
217assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
218
219@parametrize
220async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None:
221step = await client.beta.threads.runs.steps.list(
222"string",
223thread_id="string",
224after="string",
225before="string",
226limit=0,
227order="asc",
228)
229assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
230
231@parametrize
232async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
233response = await client.beta.threads.runs.steps.with_raw_response.list(
234"string",
235thread_id="string",
236)
86379b44Stainless Bot2 years ago237
238assert response.is_closed is True
baa9f07fRobert Craigie2 years ago239assert response.http_request.headers.get("X-Stainless-Lang") == "python"
240step = response.parse()
241assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
86379b44Stainless Bot2 years ago242
243@parametrize
244async def test_streaming_response_list(self, client: AsyncOpenAI) -> None:
245async with client.beta.threads.runs.steps.with_streaming_response.list(
246"string",
247thread_id="string",
248) as response:
249assert not response.is_closed
250assert response.http_request.headers.get("X-Stainless-Lang") == "python"
251
252step = await response.parse()
253assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
254
255assert cast(Any, response.is_closed) is True
023a4e66Stainless Bot2 years ago256
257@parametrize
258async def test_path_params_list(self, client: AsyncOpenAI) -> None:
259with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
260await client.beta.threads.runs.steps.with_raw_response.list(
261"string",
262thread_id="",
263)
264
265with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
266await client.beta.threads.runs.steps.with_raw_response.list(
267"",
268thread_id="string",
269)