openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
3e60c2bebe0e8accd950ca92dab2251f2932d3ca

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

305lines · 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 @pytest.mark.skip(reason="OpenAPI spec is slightly incorrect")
121 @parametrize
122 def test_method_delete(self, client: OpenAI) -> None:
123 permission = client.fine_tuning.checkpoints.permissions.delete(
124 "ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
125 )
126 assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
127
128 @pytest.mark.skip(reason="OpenAPI spec is slightly incorrect")
129 @parametrize
130 def test_raw_response_delete(self, client: OpenAI) -> None:
131 response = client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
132 "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 @pytest.mark.skip(reason="OpenAPI spec is slightly incorrect")
141 @parametrize
142 def test_streaming_response_delete(self, client: OpenAI) -> None:
143 with client.fine_tuning.checkpoints.permissions.with_streaming_response.delete(
144 "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 @pytest.mark.skip(reason="OpenAPI spec is slightly incorrect")
155 @parametrize
156 def test_path_params_delete(self, client: OpenAI) -> None:
157 with pytest.raises(
158 ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
159 ):
160 client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
161 "",
162 )
163
164
165class TestAsyncPermissions:
166 parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
167
168 @parametrize
169 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
170 permission = await async_client.fine_tuning.checkpoints.permissions.create(
171 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
172 project_ids=["string"],
173 )
174 assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
175
176 @parametrize
177 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
178 response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.create(
179 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
180 project_ids=["string"],
181 )
182
183 assert response.is_closed is True
184 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
185 permission = response.parse()
186 assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
187
188 @parametrize
189 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
190 async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.create(
191 fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
192 project_ids=["string"],
193 ) as response:
194 assert not response.is_closed
195 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
196
197 permission = await response.parse()
198 assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
199
200 assert cast(Any, response.is_closed) is True
201
202 @parametrize
203 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
204 with pytest.raises(
205 ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
206 ):
207 await async_client.fine_tuning.checkpoints.permissions.with_raw_response.create(
208 fine_tuned_model_checkpoint="",
209 project_ids=["string"],
210 )
211
212 @parametrize
213 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
214 permission = await async_client.fine_tuning.checkpoints.permissions.retrieve(
215 fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
216 )
217 assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
218
219 @parametrize
220 async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
221 permission = await async_client.fine_tuning.checkpoints.permissions.retrieve(
222 fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
223 after="after",
224 limit=0,
225 order="ascending",
226 project_id="project_id",
227 )
228 assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
229
230 @parametrize
231 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
232 response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
233 fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
234 )
235
236 assert response.is_closed is True
237 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
238 permission = response.parse()
239 assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
240
241 @parametrize
242 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
243 async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.retrieve(
244 fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
245 ) as response:
246 assert not response.is_closed
247 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
248
249 permission = await response.parse()
250 assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
251
252 assert cast(Any, response.is_closed) is True
253
254 @parametrize
255 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
256 with pytest.raises(
257 ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
258 ):
259 await async_client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
260 fine_tuned_model_checkpoint="",
261 )
262
263 @pytest.mark.skip(reason="OpenAPI spec is slightly incorrect")
264 @parametrize
265 async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
266 permission = await async_client.fine_tuning.checkpoints.permissions.delete(
267 "ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
268 )
269 assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
270
271 @pytest.mark.skip(reason="OpenAPI spec is slightly incorrect")
272 @parametrize
273 async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
274 response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
275 "ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
276 )
277
278 assert response.is_closed is True
279 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
280 permission = response.parse()
281 assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
282
283 @pytest.mark.skip(reason="OpenAPI spec is slightly incorrect")
284 @parametrize
285 async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
286 async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.delete(
287 "ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
288 ) as response:
289 assert not response.is_closed
290 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
291
292 permission = await response.parse()
293 assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
294
295 assert cast(Any, response.is_closed) is True
296
297 @pytest.mark.skip(reason="OpenAPI spec is slightly incorrect")
298 @parametrize
299 async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
300 with pytest.raises(
301 ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
302 ):
303 await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
304 "",
305 )
306