openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.13.2

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

263lines · 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.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.beta.threads.runs import RunStep
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16
17
18class TestSteps:
98d779fbStainless Bot2 years ago19parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago20
21@parametrize
22def test_method_retrieve(self, client: OpenAI) -> None:
23step = client.beta.threads.runs.steps.retrieve(
24"string",
25thread_id="string",
26run_id="string",
27)
28assert_matches_type(RunStep, step, path=["response"])
29
30@parametrize
31def test_raw_response_retrieve(self, client: OpenAI) -> None:
32response = client.beta.threads.runs.steps.with_raw_response.retrieve(
33"string",
34thread_id="string",
35run_id="string",
36)
86379b44Stainless Bot2 years ago37
38assert response.is_closed is True
baa9f07fRobert Craigie2 years ago39assert response.http_request.headers.get("X-Stainless-Lang") == "python"
40step = response.parse()
41assert_matches_type(RunStep, step, path=["response"])
42
86379b44Stainless Bot2 years ago43@parametrize
44def test_streaming_response_retrieve(self, client: OpenAI) -> None:
45with client.beta.threads.runs.steps.with_streaming_response.retrieve(
46"string",
47thread_id="string",
48run_id="string",
49) as response:
50assert not response.is_closed
51assert response.http_request.headers.get("X-Stainless-Lang") == "python"
52
53step = response.parse()
54assert_matches_type(RunStep, step, path=["response"])
55
56assert cast(Any, response.is_closed) is True
57
023a4e66Stainless Bot2 years ago58@parametrize
59def test_path_params_retrieve(self, client: OpenAI) -> None:
60with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
61client.beta.threads.runs.steps.with_raw_response.retrieve(
62"string",
63thread_id="",
64run_id="string",
65)
66
67with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
68client.beta.threads.runs.steps.with_raw_response.retrieve(
69"string",
70thread_id="string",
71run_id="",
72)
73
74with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
75client.beta.threads.runs.steps.with_raw_response.retrieve(
76"",
77thread_id="string",
78run_id="string",
79)
80
baa9f07fRobert Craigie2 years ago81@parametrize
82def test_method_list(self, client: OpenAI) -> None:
83step = client.beta.threads.runs.steps.list(
84"string",
85thread_id="string",
86)
87assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
88
89@parametrize
90def test_method_list_with_all_params(self, client: OpenAI) -> None:
91step = client.beta.threads.runs.steps.list(
92"string",
93thread_id="string",
94after="string",
95before="string",
96limit=0,
97order="asc",
98)
99assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
100
101@parametrize
102def test_raw_response_list(self, client: OpenAI) -> None:
103response = client.beta.threads.runs.steps.with_raw_response.list(
104"string",
105thread_id="string",
106)
86379b44Stainless Bot2 years ago107
108assert response.is_closed is True
baa9f07fRobert Craigie2 years ago109assert response.http_request.headers.get("X-Stainless-Lang") == "python"
110step = response.parse()
111assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
112
86379b44Stainless Bot2 years ago113@parametrize
114def test_streaming_response_list(self, client: OpenAI) -> None:
115with client.beta.threads.runs.steps.with_streaming_response.list(
116"string",
117thread_id="string",
118) as response:
119assert not response.is_closed
120assert response.http_request.headers.get("X-Stainless-Lang") == "python"
121
122step = response.parse()
123assert_matches_type(SyncCursorPage[RunStep], step, path=["response"])
124
125assert cast(Any, response.is_closed) is True
126
023a4e66Stainless Bot2 years ago127@parametrize
128def test_path_params_list(self, client: OpenAI) -> None:
129with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
130client.beta.threads.runs.steps.with_raw_response.list(
131"string",
132thread_id="",
133)
134
135with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
136client.beta.threads.runs.steps.with_raw_response.list(
137"",
138thread_id="string",
139)
140
baa9f07fRobert Craigie2 years ago141
142class TestAsyncSteps:
98d779fbStainless Bot2 years ago143parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
baa9f07fRobert Craigie2 years ago144
145@parametrize
98d779fbStainless Bot2 years ago146async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
147step = await async_client.beta.threads.runs.steps.retrieve(
baa9f07fRobert Craigie2 years ago148"string",
149thread_id="string",
150run_id="string",
151)
152assert_matches_type(RunStep, step, path=["response"])
153
154@parametrize
98d779fbStainless Bot2 years ago155async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
156response = await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
baa9f07fRobert Craigie2 years ago157"string",
158thread_id="string",
159run_id="string",
160)
86379b44Stainless Bot2 years ago161
162assert response.is_closed is True
baa9f07fRobert Craigie2 years ago163assert response.http_request.headers.get("X-Stainless-Lang") == "python"
164step = response.parse()
165assert_matches_type(RunStep, step, path=["response"])
166
86379b44Stainless Bot2 years ago167@parametrize
98d779fbStainless Bot2 years ago168async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
169async with async_client.beta.threads.runs.steps.with_streaming_response.retrieve(
86379b44Stainless Bot2 years ago170"string",
171thread_id="string",
172run_id="string",
173) as response:
174assert not response.is_closed
175assert response.http_request.headers.get("X-Stainless-Lang") == "python"
176
177step = await response.parse()
178assert_matches_type(RunStep, step, path=["response"])
179
180assert cast(Any, response.is_closed) is True
181
023a4e66Stainless Bot2 years ago182@parametrize
98d779fbStainless Bot2 years ago183async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago184with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago185await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago186"string",
187thread_id="",
188run_id="string",
189)
190
191with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
98d779fbStainless Bot2 years ago192await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago193"string",
194thread_id="string",
195run_id="",
196)
197
198with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"):
98d779fbStainless Bot2 years ago199await async_client.beta.threads.runs.steps.with_raw_response.retrieve(
023a4e66Stainless Bot2 years ago200"",
201thread_id="string",
202run_id="string",
203)
204
baa9f07fRobert Craigie2 years ago205@parametrize
98d779fbStainless Bot2 years ago206async def test_method_list(self, async_client: AsyncOpenAI) -> None:
207step = await async_client.beta.threads.runs.steps.list(
baa9f07fRobert Craigie2 years ago208"string",
209thread_id="string",
210)
211assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
212
213@parametrize
98d779fbStainless Bot2 years ago214async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
215step = await async_client.beta.threads.runs.steps.list(
baa9f07fRobert Craigie2 years ago216"string",
217thread_id="string",
218after="string",
219before="string",
220limit=0,
221order="asc",
222)
223assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
224
225@parametrize
98d779fbStainless Bot2 years ago226async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
227response = await async_client.beta.threads.runs.steps.with_raw_response.list(
baa9f07fRobert Craigie2 years ago228"string",
229thread_id="string",
230)
86379b44Stainless Bot2 years ago231
232assert response.is_closed is True
baa9f07fRobert Craigie2 years ago233assert response.http_request.headers.get("X-Stainless-Lang") == "python"
234step = response.parse()
235assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
86379b44Stainless Bot2 years ago236
237@parametrize
98d779fbStainless Bot2 years ago238async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
239async with async_client.beta.threads.runs.steps.with_streaming_response.list(
86379b44Stainless Bot2 years ago240"string",
241thread_id="string",
242) as response:
243assert not response.is_closed
244assert response.http_request.headers.get("X-Stainless-Lang") == "python"
245
246step = await response.parse()
247assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"])
248
249assert cast(Any, response.is_closed) is True
023a4e66Stainless Bot2 years ago250
251@parametrize
98d779fbStainless Bot2 years ago252async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
023a4e66Stainless Bot2 years ago253with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"):
98d779fbStainless Bot2 years ago254await async_client.beta.threads.runs.steps.with_raw_response.list(
023a4e66Stainless Bot2 years ago255"string",
256thread_id="",
257)
258
259with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"):
98d779fbStainless Bot2 years ago260await async_client.beta.threads.runs.steps.with_raw_response.list(
023a4e66Stainless Bot2 years ago261"",
262thread_id="string",
263)