openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
codex/bedrock-thin-provider-rewrite

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/users/test_roles.py

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