openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/hayden/bedrock-aws-auth

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/projects/test_groups.py

426lines · 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 SyncNextCursorPage, AsyncNextCursorPage
13from openai.types.admin.organization.projects import (
14 ProjectGroup,
15 GroupDeleteResponse,
16)
17
18base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
19
20
21class TestGroups:
22 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 group = client.admin.organization.projects.groups.create(
27 project_id="project_id",
28 group_id="group_id",
29 role="role",
30 )
31 assert_matches_type(ProjectGroup, group, path=["response"])
32
33 @parametrize
34 def test_raw_response_create(self, client: OpenAI) -> None:
35 response = client.admin.organization.projects.groups.with_raw_response.create(
36 project_id="project_id",
37 group_id="group_id",
38 role="role",
39 )
40
41 assert response.is_closed is True
42 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
43 group = response.parse()
44 assert_matches_type(ProjectGroup, group, path=["response"])
45
46 @parametrize
47 def test_streaming_response_create(self, client: OpenAI) -> None:
48 with client.admin.organization.projects.groups.with_streaming_response.create(
49 project_id="project_id",
50 group_id="group_id",
51 role="role",
52 ) as response:
53 assert not response.is_closed
54 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
55
56 group = response.parse()
57 assert_matches_type(ProjectGroup, group, path=["response"])
58
59 assert cast(Any, response.is_closed) is True
60
61 @parametrize
62 def test_path_params_create(self, client: OpenAI) -> None:
63 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
64 client.admin.organization.projects.groups.with_raw_response.create(
65 project_id="",
66 group_id="group_id",
67 role="role",
68 )
69
70 @parametrize
71 def test_method_retrieve(self, client: OpenAI) -> None:
72 group = client.admin.organization.projects.groups.retrieve(
73 group_id="group_id",
74 project_id="project_id",
75 )
76 assert_matches_type(ProjectGroup, group, path=["response"])
77
78 @parametrize
79 def test_method_retrieve_with_all_params(self, client: OpenAI) -> None:
80 group = client.admin.organization.projects.groups.retrieve(
81 group_id="group_id",
82 project_id="project_id",
83 group_type="group",
84 )
85 assert_matches_type(ProjectGroup, group, path=["response"])
86
87 @parametrize
88 def test_raw_response_retrieve(self, client: OpenAI) -> None:
89 response = client.admin.organization.projects.groups.with_raw_response.retrieve(
90 group_id="group_id",
91 project_id="project_id",
92 )
93
94 assert response.is_closed is True
95 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
96 group = response.parse()
97 assert_matches_type(ProjectGroup, group, path=["response"])
98
99 @parametrize
100 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
101 with client.admin.organization.projects.groups.with_streaming_response.retrieve(
102 group_id="group_id",
103 project_id="project_id",
104 ) as response:
105 assert not response.is_closed
106 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
107
108 group = response.parse()
109 assert_matches_type(ProjectGroup, group, path=["response"])
110
111 assert cast(Any, response.is_closed) is True
112
113 @parametrize
114 def test_path_params_retrieve(self, client: OpenAI) -> None:
115 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
116 client.admin.organization.projects.groups.with_raw_response.retrieve(
117 group_id="group_id",
118 project_id="",
119 )
120
121 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
122 client.admin.organization.projects.groups.with_raw_response.retrieve(
123 group_id="",
124 project_id="project_id",
125 )
126
127 @parametrize
128 def test_method_list(self, client: OpenAI) -> None:
129 group = client.admin.organization.projects.groups.list(
130 project_id="project_id",
131 )
132 assert_matches_type(SyncNextCursorPage[ProjectGroup], group, path=["response"])
133
134 @parametrize
135 def test_method_list_with_all_params(self, client: OpenAI) -> None:
136 group = client.admin.organization.projects.groups.list(
137 project_id="project_id",
138 after="after",
139 limit=0,
140 order="asc",
141 )
142 assert_matches_type(SyncNextCursorPage[ProjectGroup], group, path=["response"])
143
144 @parametrize
145 def test_raw_response_list(self, client: OpenAI) -> None:
146 response = client.admin.organization.projects.groups.with_raw_response.list(
147 project_id="project_id",
148 )
149
150 assert response.is_closed is True
151 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
152 group = response.parse()
153 assert_matches_type(SyncNextCursorPage[ProjectGroup], group, path=["response"])
154
155 @parametrize
156 def test_streaming_response_list(self, client: OpenAI) -> None:
157 with client.admin.organization.projects.groups.with_streaming_response.list(
158 project_id="project_id",
159 ) as response:
160 assert not response.is_closed
161 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
162
163 group = response.parse()
164 assert_matches_type(SyncNextCursorPage[ProjectGroup], group, path=["response"])
165
166 assert cast(Any, response.is_closed) is True
167
168 @parametrize
169 def test_path_params_list(self, client: OpenAI) -> None:
170 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
171 client.admin.organization.projects.groups.with_raw_response.list(
172 project_id="",
173 )
174
175 @parametrize
176 def test_method_delete(self, client: OpenAI) -> None:
177 group = client.admin.organization.projects.groups.delete(
178 group_id="group_id",
179 project_id="project_id",
180 )
181 assert_matches_type(GroupDeleteResponse, group, path=["response"])
182
183 @parametrize
184 def test_raw_response_delete(self, client: OpenAI) -> None:
185 response = client.admin.organization.projects.groups.with_raw_response.delete(
186 group_id="group_id",
187 project_id="project_id",
188 )
189
190 assert response.is_closed is True
191 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
192 group = response.parse()
193 assert_matches_type(GroupDeleteResponse, group, path=["response"])
194
195 @parametrize
196 def test_streaming_response_delete(self, client: OpenAI) -> None:
197 with client.admin.organization.projects.groups.with_streaming_response.delete(
198 group_id="group_id",
199 project_id="project_id",
200 ) as response:
201 assert not response.is_closed
202 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
203
204 group = response.parse()
205 assert_matches_type(GroupDeleteResponse, group, path=["response"])
206
207 assert cast(Any, response.is_closed) is True
208
209 @parametrize
210 def test_path_params_delete(self, client: OpenAI) -> None:
211 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
212 client.admin.organization.projects.groups.with_raw_response.delete(
213 group_id="group_id",
214 project_id="",
215 )
216
217 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
218 client.admin.organization.projects.groups.with_raw_response.delete(
219 group_id="",
220 project_id="project_id",
221 )
222
223
224class TestAsyncGroups:
225 parametrize = pytest.mark.parametrize(
226 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
227 )
228
229 @parametrize
230 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
231 group = await async_client.admin.organization.projects.groups.create(
232 project_id="project_id",
233 group_id="group_id",
234 role="role",
235 )
236 assert_matches_type(ProjectGroup, group, path=["response"])
237
238 @parametrize
239 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
240 response = await async_client.admin.organization.projects.groups.with_raw_response.create(
241 project_id="project_id",
242 group_id="group_id",
243 role="role",
244 )
245
246 assert response.is_closed is True
247 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
248 group = response.parse()
249 assert_matches_type(ProjectGroup, group, path=["response"])
250
251 @parametrize
252 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
253 async with async_client.admin.organization.projects.groups.with_streaming_response.create(
254 project_id="project_id",
255 group_id="group_id",
256 role="role",
257 ) as response:
258 assert not response.is_closed
259 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
260
261 group = await response.parse()
262 assert_matches_type(ProjectGroup, group, path=["response"])
263
264 assert cast(Any, response.is_closed) is True
265
266 @parametrize
267 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
268 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
269 await async_client.admin.organization.projects.groups.with_raw_response.create(
270 project_id="",
271 group_id="group_id",
272 role="role",
273 )
274
275 @parametrize
276 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
277 group = await async_client.admin.organization.projects.groups.retrieve(
278 group_id="group_id",
279 project_id="project_id",
280 )
281 assert_matches_type(ProjectGroup, group, path=["response"])
282
283 @parametrize
284 async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
285 group = await async_client.admin.organization.projects.groups.retrieve(
286 group_id="group_id",
287 project_id="project_id",
288 group_type="group",
289 )
290 assert_matches_type(ProjectGroup, group, path=["response"])
291
292 @parametrize
293 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
294 response = await async_client.admin.organization.projects.groups.with_raw_response.retrieve(
295 group_id="group_id",
296 project_id="project_id",
297 )
298
299 assert response.is_closed is True
300 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
301 group = response.parse()
302 assert_matches_type(ProjectGroup, group, path=["response"])
303
304 @parametrize
305 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
306 async with async_client.admin.organization.projects.groups.with_streaming_response.retrieve(
307 group_id="group_id",
308 project_id="project_id",
309 ) as response:
310 assert not response.is_closed
311 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
312
313 group = await response.parse()
314 assert_matches_type(ProjectGroup, group, path=["response"])
315
316 assert cast(Any, response.is_closed) is True
317
318 @parametrize
319 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
320 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
321 await async_client.admin.organization.projects.groups.with_raw_response.retrieve(
322 group_id="group_id",
323 project_id="",
324 )
325
326 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
327 await async_client.admin.organization.projects.groups.with_raw_response.retrieve(
328 group_id="",
329 project_id="project_id",
330 )
331
332 @parametrize
333 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
334 group = await async_client.admin.organization.projects.groups.list(
335 project_id="project_id",
336 )
337 assert_matches_type(AsyncNextCursorPage[ProjectGroup], group, path=["response"])
338
339 @parametrize
340 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
341 group = await async_client.admin.organization.projects.groups.list(
342 project_id="project_id",
343 after="after",
344 limit=0,
345 order="asc",
346 )
347 assert_matches_type(AsyncNextCursorPage[ProjectGroup], group, path=["response"])
348
349 @parametrize
350 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
351 response = await async_client.admin.organization.projects.groups.with_raw_response.list(
352 project_id="project_id",
353 )
354
355 assert response.is_closed is True
356 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
357 group = response.parse()
358 assert_matches_type(AsyncNextCursorPage[ProjectGroup], group, path=["response"])
359
360 @parametrize
361 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
362 async with async_client.admin.organization.projects.groups.with_streaming_response.list(
363 project_id="project_id",
364 ) as response:
365 assert not response.is_closed
366 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
367
368 group = await response.parse()
369 assert_matches_type(AsyncNextCursorPage[ProjectGroup], group, path=["response"])
370
371 assert cast(Any, response.is_closed) is True
372
373 @parametrize
374 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
375 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
376 await async_client.admin.organization.projects.groups.with_raw_response.list(
377 project_id="",
378 )
379
380 @parametrize
381 async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
382 group = await async_client.admin.organization.projects.groups.delete(
383 group_id="group_id",
384 project_id="project_id",
385 )
386 assert_matches_type(GroupDeleteResponse, group, path=["response"])
387
388 @parametrize
389 async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
390 response = await async_client.admin.organization.projects.groups.with_raw_response.delete(
391 group_id="group_id",
392 project_id="project_id",
393 )
394
395 assert response.is_closed is True
396 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
397 group = response.parse()
398 assert_matches_type(GroupDeleteResponse, group, path=["response"])
399
400 @parametrize
401 async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
402 async with async_client.admin.organization.projects.groups.with_streaming_response.delete(
403 group_id="group_id",
404 project_id="project_id",
405 ) as response:
406 assert not response.is_closed
407 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
408
409 group = await response.parse()
410 assert_matches_type(GroupDeleteResponse, group, path=["response"])
411
412 assert cast(Any, response.is_closed) is True
413
414 @parametrize
415 async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
416 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
417 await async_client.admin.organization.projects.groups.with_raw_response.delete(
418 group_id="group_id",
419 project_id="",
420 )
421
422 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
423 await async_client.admin.organization.projects.groups.with_raw_response.delete(
424 group_id="",
425 project_id="project_id",
426 )
427