main
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(
173 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
174 )
175
176 @parametrize
177 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
178 permission = await async_client.fine_tuning.checkpoints.permissions.create(
179 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
180 project_ids=["string"],
181 )
182 assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
183
184 @parametrize
185 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
186 response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.create(
187 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
188 project_ids=["string"],
189 )
190
191 assert response.is_closed is True
192 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
193 permission = response.parse()
194 assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
195
196 @parametrize
197 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
198 async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.create(
199 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
200 project_ids=["string"],
201 ) as response:
202 assert not response.is_closed
203 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
204
205 permission = await response.parse()
206 assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
207
208 assert cast(Any, response.is_closed) is True
209
210 @parametrize
211 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
212 with pytest.raises(
213 ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
214 ):
215 await async_client.fine_tuning.checkpoints.permissions.with_raw_response.create(
216 fine_tuned_model_checkpoint="",
217 project_ids=["string"],
218 )
219
220 @parametrize
221 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
222 permission = await async_client.fine_tuning.checkpoints.permissions.retrieve(
223 fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
224 )
225 assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
226
227 @parametrize
228 async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
229 permission = await async_client.fine_tuning.checkpoints.permissions.retrieve(
230 fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
231 after="after",
232 limit=0,
233 order="ascending",
234 project_id="project_id",
235 )
236 assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
237
238 @parametrize
239 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
240 response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
241 fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
242 )
243
244 assert response.is_closed is True
245 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
246 permission = response.parse()
247 assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
248
249 @parametrize
250 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
251 async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.retrieve(
252 fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
253 ) as response:
254 assert not response.is_closed
255 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
256
257 permission = await response.parse()
258 assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
259
260 assert cast(Any, response.is_closed) is True
261
262 @parametrize
263 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
264 with pytest.raises(
265 ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
266 ):
267 await async_client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
268 fine_tuned_model_checkpoint="",
269 )
270
271 @parametrize
272 async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
273 permission = await async_client.fine_tuning.checkpoints.permissions.delete(
274 permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
275 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
276 )
277 assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
278
279 @parametrize
280 async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
281 response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
282 permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
283 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
284 )
285
286 assert response.is_closed is True
287 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
288 permission = response.parse()
289 assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
290
291 @parametrize
292 async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
293 async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.delete(
294 permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
295 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
296 ) as response:
297 assert not response.is_closed
298 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
299
300 permission = await response.parse()
301 assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
302
303 assert cast(Any, response.is_closed) is True
304
305 @parametrize
306 async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
307 with pytest.raises(
308 ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
309 ):
310 await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
311 permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
312 fine_tuned_model_checkpoint="",
313 )
314
315 with pytest.raises(ValueError, match=r"Expected a non-empty value for `permission_id` but received ''"):
316 await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
317 permission_id="",
318 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
319 )