openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.100.2

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

319lines · 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
0673da62stainless-app[bot]1 years ago12from openai.pagination import SyncPage, AsyncPage
8da9f46bstainless-app[bot]1 years ago13from 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)
0673da62stainless-app[bot]1 years ago74assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
8da9f46bstainless-app[bot]1 years ago75
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)
0673da62stainless-app[bot]1 years ago85assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
8da9f46bstainless-app[bot]1 years ago86
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()
0673da62stainless-app[bot]1 years ago96assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
8da9f46bstainless-app[bot]1 years ago97
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()
0673da62stainless-app[bot]1 years ago107assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
8da9f46bstainless-app[bot]1 years ago108
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:
c62e9907stainless-app[bot]1 years ago172parametrize = pytest.mark.parametrize(
173"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
174)
8da9f46bstainless-app[bot]1 years ago175
176@parametrize
177async def test_method_create(self, async_client: AsyncOpenAI) -> None:
178permission = await async_client.fine_tuning.checkpoints.permissions.create(
179fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
180project_ids=["string"],
181)
182assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
183
184@parametrize
185async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
186response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.create(
187fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
188project_ids=["string"],
189)
190
191assert response.is_closed is True
192assert response.http_request.headers.get("X-Stainless-Lang") == "python"
193permission = response.parse()
194assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
195
196@parametrize
197async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
198async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.create(
199fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
200project_ids=["string"],
201) as response:
202assert not response.is_closed
203assert response.http_request.headers.get("X-Stainless-Lang") == "python"
204
205permission = await response.parse()
206assert_matches_type(AsyncPage[PermissionCreateResponse], permission, path=["response"])
207
208assert cast(Any, response.is_closed) is True
209
210@parametrize
211async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
212with pytest.raises(
213ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
214):
215await async_client.fine_tuning.checkpoints.permissions.with_raw_response.create(
216fine_tuned_model_checkpoint="",
217project_ids=["string"],
218)
219
220@parametrize
221async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
222permission = await async_client.fine_tuning.checkpoints.permissions.retrieve(
223fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
224)
0673da62stainless-app[bot]1 years ago225assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
8da9f46bstainless-app[bot]1 years ago226
227@parametrize
228async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
229permission = await async_client.fine_tuning.checkpoints.permissions.retrieve(
230fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
231after="after",
232limit=0,
233order="ascending",
234project_id="project_id",
235)
0673da62stainless-app[bot]1 years ago236assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
8da9f46bstainless-app[bot]1 years ago237
238@parametrize
239async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
240response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
241fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
242)
243
244assert response.is_closed is True
245assert response.http_request.headers.get("X-Stainless-Lang") == "python"
246permission = response.parse()
0673da62stainless-app[bot]1 years ago247assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
8da9f46bstainless-app[bot]1 years ago248
249@parametrize
250async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
251async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.retrieve(
252fine_tuned_model_checkpoint="ft-AF1WoRqd3aJAHsqc9NY7iL8F",
253) as response:
254assert not response.is_closed
255assert response.http_request.headers.get("X-Stainless-Lang") == "python"
256
257permission = await response.parse()
0673da62stainless-app[bot]1 years ago258assert_matches_type(PermissionRetrieveResponse, permission, path=["response"])
8da9f46bstainless-app[bot]1 years ago259
260assert cast(Any, response.is_closed) is True
261
262@parametrize
263async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
264with pytest.raises(
265ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
266):
267await async_client.fine_tuning.checkpoints.permissions.with_raw_response.retrieve(
268fine_tuned_model_checkpoint="",
269)
270
271@parametrize
272async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
273permission = await async_client.fine_tuning.checkpoints.permissions.delete(
6321004astainless-app[bot]1 years ago274permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
275fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
8da9f46bstainless-app[bot]1 years ago276)
277assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
278
279@parametrize
280async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
281response = await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
6321004astainless-app[bot]1 years ago282permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
283fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
8da9f46bstainless-app[bot]1 years ago284)
285
286assert response.is_closed is True
287assert response.http_request.headers.get("X-Stainless-Lang") == "python"
288permission = response.parse()
289assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
290
291@parametrize
292async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
293async with async_client.fine_tuning.checkpoints.permissions.with_streaming_response.delete(
6321004astainless-app[bot]1 years ago294permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
295fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
8da9f46bstainless-app[bot]1 years ago296) as response:
297assert not response.is_closed
298assert response.http_request.headers.get("X-Stainless-Lang") == "python"
299
300permission = await response.parse()
301assert_matches_type(PermissionDeleteResponse, permission, path=["response"])
302
303assert cast(Any, response.is_closed) is True
304
305@parametrize
306async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
307with pytest.raises(
308ValueError, match=r"Expected a non-empty value for `fine_tuned_model_checkpoint` but received ''"
309):
310await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
6321004astainless-app[bot]1 years ago311permission_id="cp_zc4Q7MP6XxulcVzj4MZdwsAB",
312fine_tuned_model_checkpoint="",
313)
314
315with pytest.raises(ValueError, match=r"Expected a non-empty value for `permission_id` but received ''"):
316await async_client.fine_tuning.checkpoints.permissions.with_raw_response.delete(
317permission_id="",
318fine_tuned_model_checkpoint="ft:gpt-4o-mini-2024-07-18:org:weather:B7R9VjQd",
8da9f46bstainless-app[bot]1 years ago319)