openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.38.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/test_groups.py

395lines · modeblame

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