openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.41.1

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/test_invites.py

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