openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.78.1

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

317lines · modecode

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