openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
custom-code-from-generated-20260521

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/fine_tuning/checkpoints/test_permissions.py

438lines · modeblame

7e8b3171stainless-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
0c14b4b9stainless-app[bot]4 months ago12from openai.pagination import SyncPage, AsyncPage, SyncConversationCursorPage, AsyncConversationCursorPage
7e8b3171stainless-app[bot]1 years ago13from openai.types.fine_tuning.checkpoints import (
0c14b4b9stainless-app[bot]4 months ago14PermissionListResponse,
7e8b3171stainless-app[bot]1 years ago15PermissionCreateResponse,
16PermissionDeleteResponse,
17PermissionRetrieveResponse,
18)
19
0c14b4b9stainless-app[bot]4 months ago20# pyright: reportDeprecated=false
21
7e8b3171stainless-app[bot]1 years ago22base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
23
24
25class TestPermissions:
26parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
27
28@parametrize
29def test_method_create(self, client: OpenAI) -> None:
30permission = client.fine_tuning.checkpoints.permissions.create(
31fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
32project_ids=["string"],
33)
34assert_matches_type(SyncPage[PermissionCreateResponse], permission, path=["response"])
35
36@parametrize
37def test_raw_response_create(self, client: OpenAI) -> None:
38response = client.fine_tuning.checkpoints.permissions.with_raw_response.create(
39fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
40project_ids=["string"],
41)
42
43assert response.is_closed is True
44assert response.http_request.headers.get("X-Stainless-Lang") == "python"
45permission = response.parse()
46assert_matches_type(SyncPage[PermissionCreateResponse], permission, path=["response"])
47
48@parametrize
49def test_streaming_response_create(self, client: OpenAI) -> None:
50with client.fine_tuning.checkpoints.permissions.with_streaming_response.create(
51fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
52project_ids=["string"],
53) as response:
54assert not response.is_closed
55assert response.http_request.headers.get("X-Stainless-Lang") == "python"
56
57permission = response.parse()
58assert_matches_type(SyncPage[PermissionCreateResponse], permission, path=["response"])
59
60assert cast(Any, response.is_closed) is True
61
62@parametrize
63def test_path_params_create(self, client: OpenAI) -> None:
64with pytest.raises(
65ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
66):
67client.fine_tuning.checkpoints.permissions.with_raw_response.create(
68fine_tuned_model_checkpoint="",
69project_ids=["string"],
70)
71
72@parametrize
73def test_method_retrieve(self, client: OpenAI) -> None:
0c14b4b9stainless-app[bot]4 months ago74with pytest.warns(DeprecationWarning):
75permission = client.fine_tuning.checkpoints.permissions.retrieve(
76fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
77)
78
8707913dstainless-app[bot]1 years ago79assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
7e8b3171stainless-app[bot]1 years ago80
81@parametrize
82def test_method_retrieve_with_all_params(self, client: OpenAI) -> None:
0c14b4b9stainless-app[bot]4 months ago83with pytest.warns(DeprecationWarning):
84permission = client.fine_tuning.checkpoints.permissions.retrieve(
85fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
86after="after",
87limit=0,
88order="ascending",
89project_id="project_id",
90)
91
92assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
93
94@parametrize
95def test_raw_response_retrieve(self, client: OpenAI) -> None:
96with pytest.warns(DeprecationWarning):
97response = client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
98fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
99)
100
101assert response.is_closed is True
102assert response.http_request.headers.get("X-Stainless-Lang") == "python"
103permission = response.parse()
104assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
105
106@parametrize
107def test_streaming_response_retrieve(self, client: OpenAI) -> None:
108with pytest.warns(DeprecationWarning):
109with client.fine_tuning.checkpoints.permissions.with_streaming_response.retrieve(
110fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
111) as response:
112assert not response.is_closed
113assert response.http_request.headers.get("X-Stainless-Lang") == "python"
114
115permission = response.parse()
116assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
117
118assert cast(Any, response.is_closed) is True
119
120@parametrize
121def test_path_params_retrieve(self, client: OpenAI) -> None:
122with pytest.warns(DeprecationWarning):
123with pytest.raises(
124ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
125):
126client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
127fine_tuned_model_checkpoint="",
128)
129
130@parametrize
131def test_method_list(self, client: OpenAI) -> None:
132permission = client.fine_tuning.checkpoints.permissions.list(
133fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
134)
135assert_matches_type(SyncConversationCursorPage[PermissionListResponse], permission, path=["response"])
136
137@parametrize
138def test_method_list_with_all_params(self, client: OpenAI) -> None:
139permission = client.fine_tuning.checkpoints.permissions.list(
7e8b3171stainless-app[bot]1 years ago140fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
141after="after",
142limit=0,
143order="ascending",
144project_id="project_id",
145)
0c14b4b9stainless-app[bot]4 months ago146assert_matches_type(SyncConversationCursorPage[PermissionListResponse], permission, path=["response"])
7e8b3171stainless-app[bot]1 years ago147
148@parametrize
0c14b4b9stainless-app[bot]4 months ago149def test_raw_response_list(self, client: OpenAI) -> None:
150response = client.fine_tuning.checkpoints.permissions.with_raw_response.list(
7e8b3171stainless-app[bot]1 years ago151fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
152)
153
154assert response.is_closed is True
155assert response.http_request.headers.get("X-Stainless-Lang") == "python"
156permission = response.parse()
0c14b4b9stainless-app[bot]4 months ago157assert_matches_type(SyncConversationCursorPage[PermissionListResponse], permission, path=["response"])
7e8b3171stainless-app[bot]1 years ago158
159@parametrize
0c14b4b9stainless-app[bot]4 months ago160def test_streaming_response_list(self, client: OpenAI) -> None:
161with client.fine_tuning.checkpoints.permissions.with_streaming_response.list(
7e8b3171stainless-app[bot]1 years ago162fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
163) as response:
164assert not response.is_closed
165assert response.http_request.headers.get("X-Stainless-Lang") == "python"
166
167permission = response.parse()
0c14b4b9stainless-app[bot]4 months ago168assert_matches_type(SyncConversationCursorPage[PermissionListResponse], permission, path=["response"])
7e8b3171stainless-app[bot]1 years ago169
170assert cast(Any, response.is_closed) is True
171
172@parametrize
0c14b4b9stainless-app[bot]4 months ago173def test_path_params_list(self, client: OpenAI) -> None:
7e8b3171stainless-app[bot]1 years ago174with pytest.raises(
175ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
176):
0c14b4b9stainless-app[bot]4 months ago177client.fine_tuning.checkpoints.permissions.with_raw_response.list(
7e8b3171stainless-app[bot]1 years ago178fine_tuned_model_checkpoint="",
179)
180
181@parametrize
182def test_method_delete(self, client: OpenAI) -> None:
183permission = client.fine_tuning.checkpoints.permissions.delete(
13640c08stainless-app[bot]1 years ago184permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
185fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
7e8b3171stainless-app[bot]1 years ago186)
187assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
188
189@parametrize
190def test_raw_response_delete(self, client: OpenAI) -> None:
191response = client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
13640c08stainless-app[bot]1 years ago192permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
193fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
7e8b3171stainless-app[bot]1 years ago194)
195
196assert response.is_closed is True
197assert response.http_request.headers.get("X-Stainless-Lang") == "python"
198permission = response.parse()
199assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
200
201@parametrize
202def test_streaming_response_delete(self, client: OpenAI) -> None:
203with client.fine_tuning.checkpoints.permissions.with_streaming_response.delete(
13640c08stainless-app[bot]1 years ago204permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
205fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
7e8b3171stainless-app[bot]1 years ago206) as response:
207assert not response.is_closed
208assert response.http_request.headers.get("X-Stainless-Lang") == "python"
209
210permission = response.parse()
211assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
212
213assert cast(Any, response.is_closed) is True
214
215@parametrize
216def test_path_params_delete(self, client: OpenAI) -> None:
217with pytest.raises(
218ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
219):
220client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
13640c08stainless-app[bot]1 years ago221permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
222fine_tuned_model_checkpoint="",
223)
224
225with pytest.raises(ValueError, match=r"Expected a non-empty value for `permission_id` but received ''"):
226client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
227permission_id="",
228fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
7e8b3171stainless-app[bot]1 years ago229)
230
231
232class TestAsyncPermissions:
d7700afdstainless-app[bot]1 years ago233parametrize = pytest.mark.parametrize(
234"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
235)
7e8b3171stainless-app[bot]1 years ago236
237@parametrize
238async def test_method_create(self, async_client: AsyncOpenAI) -> None:
239permission = await async_client.fine_tuning.checkpoints.permissions.create(
240fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
241project_ids=["string"],
242)
243assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
244
245@parametrize
246async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
247response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.create(
248fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
249project_ids=["string"],
250)
251
252assert response.is_closed is True
253assert response.http_request.headers.get("X-Stainless-Lang") == "python"
254permission = response.parse()
255assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
256
257@parametrize
258async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
259async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.create(
260fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
261project_ids=["string"],
262) as response:
263assert not response.is_closed
264assert response.http_request.headers.get("X-Stainless-Lang") == "python"
265
266permission = await response.parse()
267assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
268
269assert cast(Any, response.is_closed) is True
270
271@parametrize
272async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
273with pytest.raises(
274ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
275):
276await async_client.fine_tuning.checkpoints.permissions.with_raw_response.create(
277fine_tuned_model_checkpoint="",
278project_ids=["string"],
279)
280
281@parametrize
282async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
0c14b4b9stainless-app[bot]4 months ago283with pytest.warns(DeprecationWarning):
284permission = await async_client.fine_tuning.checkpoints.permissions.retrieve(
285fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
286)
287
8707913dstainless-app[bot]1 years ago288assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
7e8b3171stainless-app[bot]1 years ago289
290@parametrize
291async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
0c14b4b9stainless-app[bot]4 months ago292with pytest.warns(DeprecationWarning):
293permission = await async_client.fine_tuning.checkpoints.permissions.retrieve(
294fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
295after="after",
296limit=0,
297order="ascending",
298project_id="project_id",
299)
300
301assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
302
303@parametrize
304async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
305with pytest.warns(DeprecationWarning):
306response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
307fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
308)
309
310assert response.is_closed is True
311assert response.http_request.headers.get("X-Stainless-Lang") == "python"
312permission = response.parse()
313assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
314
315@parametrize
316async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
317with pytest.warns(DeprecationWarning):
318async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.retrieve(
319fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
320) as response:
321assert not response.is_closed
322assert response.http_request.headers.get("X-Stainless-Lang") == "python"
323
324permission = await response.parse()
325assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
326
327assert cast(Any, response.is_closed) is True
328
329@parametrize
330async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
331with pytest.warns(DeprecationWarning):
332with pytest.raises(
333ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
334):
335await async_client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
336fine_tuned_model_checkpoint="",
337)
338
339@parametrize
340async def test_method_list(self, async_client: AsyncOpenAI) -> None:
341permission = await async_client.fine_tuning.checkpoints.permissions.list(
342fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
343)
344assert_matches_type(AsyncConversationCursorPage[PermissionListResponse], permission, path=["response"])
345
346@parametrize
347async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
348permission = await async_client.fine_tuning.checkpoints.permissions.list(
7e8b3171stainless-app[bot]1 years ago349fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
350after="after",
351limit=0,
352order="ascending",
353project_id="project_id",
354)
0c14b4b9stainless-app[bot]4 months ago355assert_matches_type(AsyncConversationCursorPage[PermissionListResponse], permission, path=["response"])
7e8b3171stainless-app[bot]1 years ago356
357@parametrize
0c14b4b9stainless-app[bot]4 months ago358async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
359response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.list(
7e8b3171stainless-app[bot]1 years ago360fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
361)
362
363assert response.is_closed is True
364assert response.http_request.headers.get("X-Stainless-Lang") == "python"
365permission = response.parse()
0c14b4b9stainless-app[bot]4 months ago366assert_matches_type(AsyncConversationCursorPage[PermissionListResponse], permission, path=["response"])
7e8b3171stainless-app[bot]1 years ago367
368@parametrize
0c14b4b9stainless-app[bot]4 months ago369async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
370async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.list(
7e8b3171stainless-app[bot]1 years ago371fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
372) as response:
373assert not response.is_closed
374assert response.http_request.headers.get("X-Stainless-Lang") == "python"
375
376permission = await response.parse()
0c14b4b9stainless-app[bot]4 months ago377assert_matches_type(AsyncConversationCursorPage[PermissionListResponse], permission, path=["response"])
7e8b3171stainless-app[bot]1 years ago378
379assert cast(Any, response.is_closed) is True
380
381@parametrize
0c14b4b9stainless-app[bot]4 months ago382async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
7e8b3171stainless-app[bot]1 years ago383with pytest.raises(
384ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
385):
0c14b4b9stainless-app[bot]4 months ago386await async_client.fine_tuning.checkpoints.permissions.with_raw_response.list(
7e8b3171stainless-app[bot]1 years ago387fine_tuned_model_checkpoint="",
388)
389
390@parametrize
391async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
392permission = await async_client.fine_tuning.checkpoints.permissions.delete(
13640c08stainless-app[bot]1 years ago393permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
394fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
7e8b3171stainless-app[bot]1 years ago395)
396assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
397
398@parametrize
399async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
400response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
13640c08stainless-app[bot]1 years ago401permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
402fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
7e8b3171stainless-app[bot]1 years ago403)
404
405assert response.is_closed is True
406assert response.http_request.headers.get("X-Stainless-Lang") == "python"
407permission = response.parse()
408assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
409
410@parametrize
411async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
412async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.delete(
13640c08stainless-app[bot]1 years ago413permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
414fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
7e8b3171stainless-app[bot]1 years ago415) as response:
416assert not response.is_closed
417assert response.http_request.headers.get("X-Stainless-Lang") == "python"
418
419permission = await response.parse()
420assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
421
422assert cast(Any, response.is_closed) is True
423
424@parametrize
425async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
426with pytest.raises(
427ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
428):
429await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
13640c08stainless-app[bot]1 years ago430permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
431fine_tuned_model_checkpoint="",
432)
433
434with pytest.raises(ValueError, match=r"Expected a non-empty value for `permission_id` but received ''"):
435await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
436permission_id="",
437fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
7e8b3171stainless-app[bot]1 years ago438)