openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
d4a322816ad637330e40fdcdee9ca48bc92a2a4f

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/test_groups.py

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