openai/openai-python

Public

mirrored fromhttps://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_projects.py

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