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