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/groups/test_roles.py

305lines · 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.groups 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.groups.roles.create(
28 group_id="group_id",
29 role_id="role_id",
30 )
31 assert_matches_type(RoleCreateResponse, role, path=["response"])
32
33 @parametrize
34 def test_raw_response_create(self, client: OpenAI) -> None:
35 response = client.admin.organization.groups.roles.with_raw_response.create(
36 group_id="group_id",
37 role_id="role_id",
38 )
39
40 assert response.is_closed is True
41 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
42 role = response.parse()
43 assert_matches_type(RoleCreateResponse, role, path=["response"])
44
45 @parametrize
46 def test_streaming_response_create(self, client: OpenAI) -> None:
47 with client.admin.organization.groups.roles.with_streaming_response.create(
48 group_id="group_id",
49 role_id="role_id",
50 ) as response:
51 assert not response.is_closed
52 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
53
54 role = response.parse()
55 assert_matches_type(RoleCreateResponse, role, path=["response"])
56
57 assert cast(Any, response.is_closed) is True
58
59 @parametrize
60 def test_path_params_create(self, client: OpenAI) -> None:
61 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
62 client.admin.organization.groups.roles.with_raw_response.create(
63 group_id="",
64 role_id="role_id",
65 )
66
67 @parametrize
68 def test_method_list(self, client: OpenAI) -> None:
69 role = client.admin.organization.groups.roles.list(
70 group_id="group_id",
71 )
72 assert_matches_type(SyncNextCursorPage[RoleListResponse], role, path=["response"])
73
74 @parametrize
75 def test_method_list_with_all_params(self, client: OpenAI) -> None:
76 role = client.admin.organization.groups.roles.list(
77 group_id="group_id",
78 after="after",
79 limit=0,
80 order="asc",
81 )
82 assert_matches_type(SyncNextCursorPage[RoleListResponse], role, path=["response"])
83
84 @parametrize
85 def test_raw_response_list(self, client: OpenAI) -> None:
86 response = client.admin.organization.groups.roles.with_raw_response.list(
87 group_id="group_id",
88 )
89
90 assert response.is_closed is True
91 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
92 role = response.parse()
93 assert_matches_type(SyncNextCursorPage[RoleListResponse], role, path=["response"])
94
95 @parametrize
96 def test_streaming_response_list(self, client: OpenAI) -> None:
97 with client.admin.organization.groups.roles.with_streaming_response.list(
98 group_id="group_id",
99 ) as response:
100 assert not response.is_closed
101 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
102
103 role = response.parse()
104 assert_matches_type(SyncNextCursorPage[RoleListResponse], role, path=["response"])
105
106 assert cast(Any, response.is_closed) is True
107
108 @parametrize
109 def test_path_params_list(self, client: OpenAI) -> None:
110 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
111 client.admin.organization.groups.roles.with_raw_response.list(
112 group_id="",
113 )
114
115 @parametrize
116 def test_method_delete(self, client: OpenAI) -> None:
117 role = client.admin.organization.groups.roles.delete(
118 role_id="role_id",
119 group_id="group_id",
120 )
121 assert_matches_type(RoleDeleteResponse, role, path=["response"])
122
123 @parametrize
124 def test_raw_response_delete(self, client: OpenAI) -> None:
125 response = client.admin.organization.groups.roles.with_raw_response.delete(
126 role_id="role_id",
127 group_id="group_id",
128 )
129
130 assert response.is_closed is True
131 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
132 role = response.parse()
133 assert_matches_type(RoleDeleteResponse, role, path=["response"])
134
135 @parametrize
136 def test_streaming_response_delete(self, client: OpenAI) -> None:
137 with client.admin.organization.groups.roles.with_streaming_response.delete(
138 role_id="role_id",
139 group_id="group_id",
140 ) as response:
141 assert not response.is_closed
142 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
143
144 role = response.parse()
145 assert_matches_type(RoleDeleteResponse, role, path=["response"])
146
147 assert cast(Any, response.is_closed) is True
148
149 @parametrize
150 def test_path_params_delete(self, client: OpenAI) -> None:
151 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
152 client.admin.organization.groups.roles.with_raw_response.delete(
153 role_id="role_id",
154 group_id="",
155 )
156
157 with pytest.raises(ValueError, match=r"Expected a non-empty value for `role_id` but received ''"):
158 client.admin.organization.groups.roles.with_raw_response.delete(
159 role_id="",
160 group_id="group_id",
161 )
162
163
164class TestAsyncRoles:
165 parametrize = pytest.mark.parametrize(
166 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
167 )
168
169 @parametrize
170 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
171 role = await async_client.admin.organization.groups.roles.create(
172 group_id="group_id",
173 role_id="role_id",
174 )
175 assert_matches_type(RoleCreateResponse, role, path=["response"])
176
177 @parametrize
178 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
179 response = await async_client.admin.organization.groups.roles.with_raw_response.create(
180 group_id="group_id",
181 role_id="role_id",
182 )
183
184 assert response.is_closed is True
185 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
186 role = response.parse()
187 assert_matches_type(RoleCreateResponse, role, path=["response"])
188
189 @parametrize
190 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
191 async with async_client.admin.organization.groups.roles.with_streaming_response.create(
192 group_id="group_id",
193 role_id="role_id",
194 ) as response:
195 assert not response.is_closed
196 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
197
198 role = await response.parse()
199 assert_matches_type(RoleCreateResponse, role, path=["response"])
200
201 assert cast(Any, response.is_closed) is True
202
203 @parametrize
204 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
205 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
206 await async_client.admin.organization.groups.roles.with_raw_response.create(
207 group_id="",
208 role_id="role_id",
209 )
210
211 @parametrize
212 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
213 role = await async_client.admin.organization.groups.roles.list(
214 group_id="group_id",
215 )
216 assert_matches_type(AsyncNextCursorPage[RoleListResponse], role, path=["response"])
217
218 @parametrize
219 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
220 role = await async_client.admin.organization.groups.roles.list(
221 group_id="group_id",
222 after="after",
223 limit=0,
224 order="asc",
225 )
226 assert_matches_type(AsyncNextCursorPage[RoleListResponse], role, path=["response"])
227
228 @parametrize
229 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
230 response = await async_client.admin.organization.groups.roles.with_raw_response.list(
231 group_id="group_id",
232 )
233
234 assert response.is_closed is True
235 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
236 role = response.parse()
237 assert_matches_type(AsyncNextCursorPage[RoleListResponse], role, path=["response"])
238
239 @parametrize
240 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
241 async with async_client.admin.organization.groups.roles.with_streaming_response.list(
242 group_id="group_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(AsyncNextCursorPage[RoleListResponse], role, path=["response"])
249
250 assert cast(Any, response.is_closed) is True
251
252 @parametrize
253 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
254 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
255 await async_client.admin.organization.groups.roles.with_raw_response.list(
256 group_id="",
257 )
258
259 @parametrize
260 async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
261 role = await async_client.admin.organization.groups.roles.delete(
262 role_id="role_id",
263 group_id="group_id",
264 )
265 assert_matches_type(RoleDeleteResponse, role, path=["response"])
266
267 @parametrize
268 async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
269 response = await async_client.admin.organization.groups.roles.with_raw_response.delete(
270 role_id="role_id",
271 group_id="group_id",
272 )
273
274 assert response.is_closed is True
275 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
276 role = response.parse()
277 assert_matches_type(RoleDeleteResponse, role, path=["response"])
278
279 @parametrize
280 async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
281 async with async_client.admin.organization.groups.roles.with_streaming_response.delete(
282 role_id="role_id",
283 group_id="group_id",
284 ) as response:
285 assert not response.is_closed
286 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
287
288 role = await response.parse()
289 assert_matches_type(RoleDeleteResponse, role, path=["response"])
290
291 assert cast(Any, response.is_closed) is True
292
293 @parametrize
294 async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
295 with pytest.raises(ValueError, match=r"Expected a non-empty value for `group_id` but received ''"):
296 await async_client.admin.organization.groups.roles.with_raw_response.delete(
297 role_id="role_id",
298 group_id="",
299 )
300
301 with pytest.raises(ValueError, match=r"Expected a non-empty value for `role_id` but received ''"):
302 await async_client.admin.organization.groups.roles.with_raw_response.delete(
303 role_id="",
304 group_id="group_id",
305 )