openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bab18af787cd5d962aedeb4b5b86df4f6cf28003

Branches

Tags

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

Clone

HTTPS

Download ZIP

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

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