openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.38.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/containers/test_files.py

411lines · modeblame

71058dd6stainless-app[bot]1 years ago1# 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.containers import (
14FileListResponse,
15FileCreateResponse,
16FileRetrieveResponse,
17)
18
19base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
20
21
22class TestFiles:
23parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
24
25@parametrize
26def test_method_create(self, client: OpenAI) -> None:
27file = client.containers.files.create(
28container_id="container_id",
29)
30assert_matches_type(FileCreateResponse, file, path=["response"])
31
32@parametrize
33def test_method_create_with_all_params(self, client: OpenAI) -> None:
34file = client.containers.files.create(
35container_id="container_id",
0a4ca536stainless-app[bot]3 months ago36file=b"Example data",
71058dd6stainless-app[bot]1 years ago37file_id="file_id",
38)
39assert_matches_type(FileCreateResponse, file, path=["response"])
40
41@parametrize
42def test_raw_response_create(self, client: OpenAI) -> None:
43response = client.containers.files.with_raw_response.create(
44container_id="container_id",
45)
46
47assert response.is_closed is True
48assert response.http_request.headers.get("X-Stainless-Lang") == "python"
49file = response.parse()
50assert_matches_type(FileCreateResponse, file, path=["response"])
51
52@parametrize
53def test_streaming_response_create(self, client: OpenAI) -> None:
54with client.containers.files.with_streaming_response.create(
55container_id="container_id",
56) as response:
57assert not response.is_closed
58assert response.http_request.headers.get("X-Stainless-Lang") == "python"
59
60file = response.parse()
61assert_matches_type(FileCreateResponse, file, path=["response"])
62
63assert cast(Any, response.is_closed) is True
64
65@parametrize
66def test_path_params_create(self, client: OpenAI) -> None:
67with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"):
68client.containers.files.with_raw_response.create(
69container_id="",
70)
71
72@parametrize
73def test_method_retrieve(self, client: OpenAI) -> None:
74file = client.containers.files.retrieve(
75file_id="file_id",
76container_id="container_id",
77)
78assert_matches_type(FileRetrieveResponse, file, path=["response"])
79
80@parametrize
81def test_raw_response_retrieve(self, client: OpenAI) -> None:
82response = client.containers.files.with_raw_response.retrieve(
83file_id="file_id",
84container_id="container_id",
85)
86
87assert response.is_closed is True
88assert response.http_request.headers.get("X-Stainless-Lang") == "python"
89file = response.parse()
90assert_matches_type(FileRetrieveResponse, file, path=["response"])
91
92@parametrize
93def test_streaming_response_retrieve(self, client: OpenAI) -> None:
94with client.containers.files.with_streaming_response.retrieve(
95file_id="file_id",
96container_id="container_id",
97) as response:
98assert not response.is_closed
99assert response.http_request.headers.get("X-Stainless-Lang") == "python"
100
101file = response.parse()
102assert_matches_type(FileRetrieveResponse, file, path=["response"])
103
104assert cast(Any, response.is_closed) is True
105
106@parametrize
107def test_path_params_retrieve(self, client: OpenAI) -> None:
108with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"):
109client.containers.files.with_raw_response.retrieve(
110file_id="file_id",
111container_id="",
112)
113
114with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
115client.containers.files.with_raw_response.retrieve(
116file_id="",
117container_id="container_id",
118)
119
120@parametrize
121def test_method_list(self, client: OpenAI) -> None:
122file = client.containers.files.list(
123container_id="container_id",
124)
125assert_matches_type(SyncCursorPage[FileListResponse], file, path=["response"])
126
127@parametrize
128def test_method_list_with_all_params(self, client: OpenAI) -> None:
129file = client.containers.files.list(
130container_id="container_id",
131after="after",
132limit=0,
133order="asc",
134)
135assert_matches_type(SyncCursorPage[FileListResponse], file, path=["response"])
136
137@parametrize
138def test_raw_response_list(self, client: OpenAI) -> None:
139response = client.containers.files.with_raw_response.list(
140container_id="container_id",
141)
142
143assert response.is_closed is True
144assert response.http_request.headers.get("X-Stainless-Lang") == "python"
145file = response.parse()
146assert_matches_type(SyncCursorPage[FileListResponse], file, path=["response"])
147
148@parametrize
149def test_streaming_response_list(self, client: OpenAI) -> None:
150with client.containers.files.with_streaming_response.list(
151container_id="container_id",
152) as response:
153assert not response.is_closed
154assert response.http_request.headers.get("X-Stainless-Lang") == "python"
155
156file = response.parse()
157assert_matches_type(SyncCursorPage[FileListResponse], file, path=["response"])
158
159assert cast(Any, response.is_closed) is True
160
161@parametrize
162def test_path_params_list(self, client: OpenAI) -> None:
163with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"):
164client.containers.files.with_raw_response.list(
165container_id="",
166)
167
168@parametrize
169def test_method_delete(self, client: OpenAI) -> None:
170file = client.containers.files.delete(
171file_id="file_id",
172container_id="container_id",
173)
174assert file is None
175
176@parametrize
177def test_raw_response_delete(self, client: OpenAI) -> None:
178response = client.containers.files.with_raw_response.delete(
179file_id="file_id",
180container_id="container_id",
181)
182
183assert response.is_closed is True
184assert response.http_request.headers.get("X-Stainless-Lang") == "python"
185file = response.parse()
186assert file is None
187
188@parametrize
189def test_streaming_response_delete(self, client: OpenAI) -> None:
190with client.containers.files.with_streaming_response.delete(
191file_id="file_id",
192container_id="container_id",
193) as response:
194assert not response.is_closed
195assert response.http_request.headers.get("X-Stainless-Lang") == "python"
196
197file = response.parse()
198assert file is None
199
200assert cast(Any, response.is_closed) is True
201
202@parametrize
203def test_path_params_delete(self, client: OpenAI) -> None:
204with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"):
205client.containers.files.with_raw_response.delete(
206file_id="file_id",
207container_id="",
208)
209
210with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
211client.containers.files.with_raw_response.delete(
212file_id="",
213container_id="container_id",
214)
215
216
217class TestAsyncFiles:
c62e9907stainless-app[bot]1 years ago218parametrize = pytest.mark.parametrize(
219"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
220)
71058dd6stainless-app[bot]1 years ago221
222@parametrize
223async def test_method_create(self, async_client: AsyncOpenAI) -> None:
224file = await async_client.containers.files.create(
225container_id="container_id",
226)
227assert_matches_type(FileCreateResponse, file, path=["response"])
228
229@parametrize
230async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
231file = await async_client.containers.files.create(
232container_id="container_id",
0a4ca536stainless-app[bot]3 months ago233file=b"Example data",
71058dd6stainless-app[bot]1 years ago234file_id="file_id",
235)
236assert_matches_type(FileCreateResponse, file, path=["response"])
237
238@parametrize
239async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
240response = await async_client.containers.files.with_raw_response.create(
241container_id="container_id",
242)
243
244assert response.is_closed is True
245assert response.http_request.headers.get("X-Stainless-Lang") == "python"
246file = response.parse()
247assert_matches_type(FileCreateResponse, file, path=["response"])
248
249@parametrize
250async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
251async with async_client.containers.files.with_streaming_response.create(
252container_id="container_id",
253) as response:
254assert not response.is_closed
255assert response.http_request.headers.get("X-Stainless-Lang") == "python"
256
257file = await response.parse()
258assert_matches_type(FileCreateResponse, file, path=["response"])
259
260assert cast(Any, response.is_closed) is True
261
262@parametrize
263async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
264with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"):
265await async_client.containers.files.with_raw_response.create(
266container_id="",
267)
268
269@parametrize
270async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
271file = await async_client.containers.files.retrieve(
272file_id="file_id",
273container_id="container_id",
274)
275assert_matches_type(FileRetrieveResponse, file, path=["response"])
276
277@parametrize
278async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
279response = await async_client.containers.files.with_raw_response.retrieve(
280file_id="file_id",
281container_id="container_id",
282)
283
284assert response.is_closed is True
285assert response.http_request.headers.get("X-Stainless-Lang") == "python"
286file = response.parse()
287assert_matches_type(FileRetrieveResponse, file, path=["response"])
288
289@parametrize
290async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
291async with async_client.containers.files.with_streaming_response.retrieve(
292file_id="file_id",
293container_id="container_id",
294) as response:
295assert not response.is_closed
296assert response.http_request.headers.get("X-Stainless-Lang") == "python"
297
298file = await response.parse()
299assert_matches_type(FileRetrieveResponse, file, path=["response"])
300
301assert cast(Any, response.is_closed) is True
302
303@parametrize
304async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
305with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"):
306await async_client.containers.files.with_raw_response.retrieve(
307file_id="file_id",
308container_id="",
309)
310
311with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
312await async_client.containers.files.with_raw_response.retrieve(
313file_id="",
314container_id="container_id",
315)
316
317@parametrize
318async def test_method_list(self, async_client: AsyncOpenAI) -> None:
319file = await async_client.containers.files.list(
320container_id="container_id",
321)
322assert_matches_type(AsyncCursorPage[FileListResponse], file, path=["response"])
323
324@parametrize
325async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
326file = await async_client.containers.files.list(
327container_id="container_id",
328after="after",
329limit=0,
330order="asc",
331)
332assert_matches_type(AsyncCursorPage[FileListResponse], file, path=["response"])
333
334@parametrize
335async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
336response = await async_client.containers.files.with_raw_response.list(
337container_id="container_id",
338)
339
340assert response.is_closed is True
341assert response.http_request.headers.get("X-Stainless-Lang") == "python"
342file = response.parse()
343assert_matches_type(AsyncCursorPage[FileListResponse], file, path=["response"])
344
345@parametrize
346async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
347async with async_client.containers.files.with_streaming_response.list(
348container_id="container_id",
349) as response:
350assert not response.is_closed
351assert response.http_request.headers.get("X-Stainless-Lang") == "python"
352
353file = await response.parse()
354assert_matches_type(AsyncCursorPage[FileListResponse], file, path=["response"])
355
356assert cast(Any, response.is_closed) is True
357
358@parametrize
359async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
360with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"):
361await async_client.containers.files.with_raw_response.list(
362container_id="",
363)
364
365@parametrize
366async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
367file = await async_client.containers.files.delete(
368file_id="file_id",
369container_id="container_id",
370)
371assert file is None
372
373@parametrize
374async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
375response = await async_client.containers.files.with_raw_response.delete(
376file_id="file_id",
377container_id="container_id",
378)
379
380assert response.is_closed is True
381assert response.http_request.headers.get("X-Stainless-Lang") == "python"
382file = response.parse()
383assert file is None
384
385@parametrize
386async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
387async with async_client.containers.files.with_streaming_response.delete(
388file_id="file_id",
389container_id="container_id",
390) as response:
391assert not response.is_closed
392assert response.http_request.headers.get("X-Stainless-Lang") == "python"
393
394file = await response.parse()
395assert file is None
396
397assert cast(Any, response.is_closed) is True
398
399@parametrize
400async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
401with pytest.raises(ValueError, match=r"Expected a non-empty value for `container_id` but received ''"):
402await async_client.containers.files.with_raw_response.delete(
403file_id="file_id",
404container_id="",
405)
406
407with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
408await async_client.containers.files.with_raw_response.delete(
409file_id="",
410container_id="container_id",
411)