openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/threads/runs/test_steps.py
285lines · modeblame
5cfb125aStainless Bot2 years ago | 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
baa9f07fRobert Craigie2 years ago | 2 | |
| 3 | from __future__ import annotations | |
| 4 | | |
| 5 | import os | |
86379b44Stainless Bot2 years ago | 6 | from typing import Any, cast |
baa9f07fRobert Craigie2 years ago | 7 | |
| 8 | import pytest | |
| 9 | | |
| 10 | from openai import OpenAI, AsyncOpenAI | |
| 11 | from tests.utils import assert_matches_type | |
| 12 | from openai.pagination import SyncCursorPage, AsyncCursorPage | |
4a0f0fa0Stainless Bot2 years ago | 13 | from openai.types.beta.threads.runs import RunStep |
baa9f07fRobert Craigie2 years ago | 14 | |
| 15 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") | |
| 16 | | |
| 17 | | |
| 18 | class TestSteps: | |
98d779fbStainless Bot2 years ago | 19 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
baa9f07fRobert Craigie2 years ago | 20 | |
| 21 | @parametrize | |
| 22 | def test_method_retrieve(self, client: OpenAI) -> None: | |
| 23 | step = client.beta.threads.runs.steps.retrieve( | |
| 24 | "string", | |
| 25 | thread_id="string", | |
| 26 | run_id="string", | |
| 27 | ) | |
| 28 | assert_matches_type(RunStep, step, path=["response"]) | |
| 29 | | |
5d3111a8Stainless Bot1 years ago | 30 | @parametrize |
| 31 | def test_method_retrieve_with_all_params(self, client: OpenAI) -> None: | |
| 32 | step = client.beta.threads.runs.steps.retrieve( | |
| 33 | step_id="step_id", | |
| 34 | thread_id="thread_id", | |
| 35 | run_id="run_id", | |
| 36 | include=["step_details.tool_calls[*].file_search.results[*].content"], | |
| 37 | ) | |
| 38 | assert_matches_type(RunStep, step, path=["response"]) | |
| 39 | | |
baa9f07fRobert Craigie2 years ago | 40 | @parametrize |
| 41 | def test_raw_response_retrieve(self, client: OpenAI) -> None: | |
| 42 | response = client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 43 | "string", | |
| 44 | thread_id="string", | |
| 45 | run_id="string", | |
| 46 | ) | |
86379b44Stainless Bot2 years ago | 47 | |
| 48 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 49 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 50 | step = response.parse() | |
| 51 | assert_matches_type(RunStep, step, path=["response"]) | |
| 52 | | |
86379b44Stainless Bot2 years ago | 53 | @parametrize |
| 54 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: | |
| 55 | with client.beta.threads.runs.steps.with_streaming_response.retrieve( | |
| 56 | "string", | |
| 57 | thread_id="string", | |
| 58 | run_id="string", | |
| 59 | ) as response: | |
| 60 | assert not response.is_closed | |
| 61 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 62 | | |
| 63 | step = response.parse() | |
| 64 | assert_matches_type(RunStep, step, path=["response"]) | |
| 65 | | |
| 66 | assert cast(Any, response.is_closed) is True | |
| 67 | | |
023a4e66Stainless Bot2 years ago | 68 | @parametrize |
| 69 | def test_path_params_retrieve(self, client: OpenAI) -> None: | |
| 70 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 71 | client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 72 | "string", | |
| 73 | thread_id="", | |
| 74 | run_id="string", | |
| 75 | ) | |
| 76 | | |
| 77 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): | |
| 78 | client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 79 | "string", | |
| 80 | thread_id="string", | |
| 81 | run_id="", | |
| 82 | ) | |
| 83 | | |
| 84 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"): | |
| 85 | client.beta.threads.runs.steps.with_raw_response.retrieve( | |
| 86 | "", | |
| 87 | thread_id="string", | |
| 88 | run_id="string", | |
| 89 | ) | |
| 90 | | |
baa9f07fRobert Craigie2 years ago | 91 | @parametrize |
| 92 | def test_method_list(self, client: OpenAI) -> None: | |
| 93 | step = client.beta.threads.runs.steps.list( | |
| 94 | "string", | |
| 95 | thread_id="string", | |
| 96 | ) | |
| 97 | assert_matches_type(SyncCursorPage[RunStep], step, path=["response"]) | |
| 98 | | |
| 99 | @parametrize | |
| 100 | def test_method_list_with_all_params(self, client: OpenAI) -> None: | |
| 101 | step = client.beta.threads.runs.steps.list( | |
5d3111a8Stainless Bot1 years ago | 102 | run_id="run_id", |
| 103 | thread_id="thread_id", | |
| 104 | after="after", | |
| 105 | before="before", | |
| 106 | include=["step_details.tool_calls[*].file_search.results[*].content"], | |
baa9f07fRobert Craigie2 years ago | 107 | limit=0, |
| 108 | order="asc", | |
| 109 | ) | |
| 110 | assert_matches_type(SyncCursorPage[RunStep], step, path=["response"]) | |
| 111 | | |
| 112 | @parametrize | |
| 113 | def test_raw_response_list(self, client: OpenAI) -> None: | |
| 114 | response = client.beta.threads.runs.steps.with_raw_response.list( | |
| 115 | "string", | |
| 116 | thread_id="string", | |
| 117 | ) | |
86379b44Stainless Bot2 years ago | 118 | |
| 119 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 120 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 121 | step = response.parse() | |
| 122 | assert_matches_type(SyncCursorPage[RunStep], step, path=["response"]) | |
| 123 | | |
86379b44Stainless Bot2 years ago | 124 | @parametrize |
| 125 | def test_streaming_response_list(self, client: OpenAI) -> None: | |
| 126 | with client.beta.threads.runs.steps.with_streaming_response.list( | |
| 127 | "string", | |
| 128 | thread_id="string", | |
| 129 | ) as response: | |
| 130 | assert not response.is_closed | |
| 131 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 132 | | |
| 133 | step = response.parse() | |
| 134 | assert_matches_type(SyncCursorPage[RunStep], step, path=["response"]) | |
| 135 | | |
| 136 | assert cast(Any, response.is_closed) is True | |
| 137 | | |
023a4e66Stainless Bot2 years ago | 138 | @parametrize |
| 139 | def test_path_params_list(self, client: OpenAI) -> None: | |
| 140 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 141 | client.beta.threads.runs.steps.with_raw_response.list( | |
| 142 | "string", | |
| 143 | thread_id="", | |
| 144 | ) | |
| 145 | | |
| 146 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): | |
| 147 | client.beta.threads.runs.steps.with_raw_response.list( | |
| 148 | "", | |
| 149 | thread_id="string", | |
| 150 | ) | |
| 151 | | |
baa9f07fRobert Craigie2 years ago | 152 | |
| 153 | class TestAsyncSteps: | |
98d779fbStainless Bot2 years ago | 154 | parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) |
baa9f07fRobert Craigie2 years ago | 155 | |
| 156 | @parametrize | |
98d779fbStainless Bot2 years ago | 157 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 158 | step = await async_client.beta.threads.runs.steps.retrieve( | |
baa9f07fRobert Craigie2 years ago | 159 | "string", |
| 160 | thread_id="string", | |
| 161 | run_id="string", | |
| 162 | ) | |
| 163 | assert_matches_type(RunStep, step, path=["response"]) | |
| 164 | | |
5d3111a8Stainless Bot1 years ago | 165 | @parametrize |
| 166 | async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None: | |
| 167 | step = await async_client.beta.threads.runs.steps.retrieve( | |
| 168 | step_id="step_id", | |
| 169 | thread_id="thread_id", | |
| 170 | run_id="run_id", | |
| 171 | include=["step_details.tool_calls[*].file_search.results[*].content"], | |
| 172 | ) | |
| 173 | assert_matches_type(RunStep, step, path=["response"]) | |
| 174 | | |
baa9f07fRobert Craigie2 years ago | 175 | @parametrize |
98d779fbStainless Bot2 years ago | 176 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 177 | response = await async_client.beta.threads.runs.steps.with_raw_response.retrieve( | |
baa9f07fRobert Craigie2 years ago | 178 | "string", |
| 179 | thread_id="string", | |
| 180 | run_id="string", | |
| 181 | ) | |
86379b44Stainless Bot2 years ago | 182 | |
| 183 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 184 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 185 | step = response.parse() | |
| 186 | assert_matches_type(RunStep, step, path=["response"]) | |
| 187 | | |
86379b44Stainless Bot2 years ago | 188 | @parametrize |
98d779fbStainless Bot2 years ago | 189 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 190 | async with async_client.beta.threads.runs.steps.with_streaming_response.retrieve( | |
86379b44Stainless Bot2 years ago | 191 | "string", |
| 192 | thread_id="string", | |
| 193 | run_id="string", | |
| 194 | ) as response: | |
| 195 | assert not response.is_closed | |
| 196 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 197 | | |
| 198 | step = await response.parse() | |
| 199 | assert_matches_type(RunStep, step, path=["response"]) | |
| 200 | | |
| 201 | assert cast(Any, response.is_closed) is True | |
| 202 | | |
023a4e66Stainless Bot2 years ago | 203 | @parametrize |
98d779fbStainless Bot2 years ago | 204 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
023a4e66Stainless Bot2 years ago | 205 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
98d779fbStainless Bot2 years ago | 206 | await async_client.beta.threads.runs.steps.with_raw_response.retrieve( |
023a4e66Stainless Bot2 years ago | 207 | "string", |
| 208 | thread_id="", | |
| 209 | run_id="string", | |
| 210 | ) | |
| 211 | | |
| 212 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): | |
98d779fbStainless Bot2 years ago | 213 | await async_client.beta.threads.runs.steps.with_raw_response.retrieve( |
023a4e66Stainless Bot2 years ago | 214 | "string", |
| 215 | thread_id="string", | |
| 216 | run_id="", | |
| 217 | ) | |
| 218 | | |
| 219 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `step_id` but received ''"): | |
98d779fbStainless Bot2 years ago | 220 | await async_client.beta.threads.runs.steps.with_raw_response.retrieve( |
023a4e66Stainless Bot2 years ago | 221 | "", |
| 222 | thread_id="string", | |
| 223 | run_id="string", | |
| 224 | ) | |
| 225 | | |
baa9f07fRobert Craigie2 years ago | 226 | @parametrize |
98d779fbStainless Bot2 years ago | 227 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 228 | step = await async_client.beta.threads.runs.steps.list( | |
baa9f07fRobert Craigie2 years ago | 229 | "string", |
| 230 | thread_id="string", | |
| 231 | ) | |
| 232 | assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"]) | |
| 233 | | |
| 234 | @parametrize | |
98d779fbStainless Bot2 years ago | 235 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 236 | step = await async_client.beta.threads.runs.steps.list( | |
5d3111a8Stainless Bot1 years ago | 237 | run_id="run_id", |
| 238 | thread_id="thread_id", | |
| 239 | after="after", | |
| 240 | before="before", | |
| 241 | include=["step_details.tool_calls[*].file_search.results[*].content"], | |
baa9f07fRobert Craigie2 years ago | 242 | limit=0, |
| 243 | order="asc", | |
| 244 | ) | |
| 245 | assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"]) | |
| 246 | | |
| 247 | @parametrize | |
98d779fbStainless Bot2 years ago | 248 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 249 | response = await async_client.beta.threads.runs.steps.with_raw_response.list( | |
baa9f07fRobert Craigie2 years ago | 250 | "string", |
| 251 | thread_id="string", | |
| 252 | ) | |
86379b44Stainless Bot2 years ago | 253 | |
| 254 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 255 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 256 | step = response.parse() | |
| 257 | assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"]) | |
86379b44Stainless Bot2 years ago | 258 | |
| 259 | @parametrize | |
98d779fbStainless Bot2 years ago | 260 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 261 | async with async_client.beta.threads.runs.steps.with_streaming_response.list( | |
86379b44Stainless Bot2 years ago | 262 | "string", |
| 263 | thread_id="string", | |
| 264 | ) as response: | |
| 265 | assert not response.is_closed | |
| 266 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 267 | | |
| 268 | step = await response.parse() | |
| 269 | assert_matches_type(AsyncCursorPage[RunStep], step, path=["response"]) | |
| 270 | | |
| 271 | assert cast(Any, response.is_closed) is True | |
023a4e66Stainless Bot2 years ago | 272 | |
| 273 | @parametrize | |
98d779fbStainless Bot2 years ago | 274 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
023a4e66Stainless Bot2 years ago | 275 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
98d779fbStainless Bot2 years ago | 276 | await async_client.beta.threads.runs.steps.with_raw_response.list( |
023a4e66Stainless Bot2 years ago | 277 | "string", |
| 278 | thread_id="", | |
| 279 | ) | |
| 280 | | |
| 281 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `run_id` but received ''"): | |
98d779fbStainless Bot2 years ago | 282 | await async_client.beta.threads.runs.steps.with_raw_response.list( |
023a4e66Stainless Bot2 years ago | 283 | "", |
| 284 | thread_id="string", | |
| 285 | ) |