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 · modeblame

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