openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v2.42.0

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/test_certificates.py

561lines · 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 SyncPage, AsyncPage, SyncConversationCursorPage, AsyncConversationCursorPage
13from openai.types.admin.organization import (
14Certificate,
b1417cc7stainless-app[bot]2 months ago15CertificateListResponse,
d05f3a87stainless-app[bot]2 months ago16CertificateDeleteResponse,
b1417cc7stainless-app[bot]2 months ago17CertificateActivateResponse,
18CertificateDeactivateResponse,
d05f3a87stainless-app[bot]2 months ago19)
20
21base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
22
23
24class TestCertificates:
25parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
26
27@parametrize
28def test_method_create(self, client: OpenAI) -> None:
29certificate = client.admin.organization.certificates.create(
b1417cc7stainless-app[bot]2 months ago30certificate="certificate",
d05f3a87stainless-app[bot]2 months ago31)
32assert_matches_type(Certificate, certificate, path=["response"])
33
34@parametrize
35def test_method_create_with_all_params(self, client: OpenAI) -> None:
36certificate = client.admin.organization.certificates.create(
b1417cc7stainless-app[bot]2 months ago37certificate="certificate",
d05f3a87stainless-app[bot]2 months ago38name="name",
39)
40assert_matches_type(Certificate, certificate, path=["response"])
41
42@parametrize
43def test_raw_response_create(self, client: OpenAI) -> None:
44response = client.admin.organization.certificates.with_raw_response.create(
b1417cc7stainless-app[bot]2 months ago45certificate="certificate",
d05f3a87stainless-app[bot]2 months ago46)
47
48assert response.is_closed is True
49assert response.http_request.headers.get("X-Stainless-Lang") == "python"
50certificate = response.parse()
51assert_matches_type(Certificate, certificate, path=["response"])
52
53@parametrize
54def test_streaming_response_create(self, client: OpenAI) -> None:
55with client.admin.organization.certificates.with_streaming_response.create(
b1417cc7stainless-app[bot]2 months ago56certificate="certificate",
d05f3a87stainless-app[bot]2 months ago57) as response:
58assert not response.is_closed
59assert response.http_request.headers.get("X-Stainless-Lang") == "python"
60
61certificate = response.parse()
62assert_matches_type(Certificate, certificate, path=["response"])
63
64assert cast(Any, response.is_closed) is True
65
66@parametrize
67def test_method_retrieve(self, client: OpenAI) -> None:
68certificate = client.admin.organization.certificates.retrieve(
69certificate_id="certificate_id",
70)
71assert_matches_type(Certificate, certificate, path=["response"])
72
73@parametrize
74def test_method_retrieve_with_all_params(self, client: OpenAI) -> None:
75certificate = client.admin.organization.certificates.retrieve(
76certificate_id="certificate_id",
77include=["content"],
78)
79assert_matches_type(Certificate, certificate, path=["response"])
80
81@parametrize
82def test_raw_response_retrieve(self, client: OpenAI) -> None:
83response = client.admin.organization.certificates.with_raw_response.retrieve(
84certificate_id="certificate_id",
85)
86
87assert response.is_closed is True
88assert response.http_request.headers.get("X-Stainless-Lang") == "python"
89certificate = response.parse()
90assert_matches_type(Certificate, certificate, path=["response"])
91
92@parametrize
93def test_streaming_response_retrieve(self, client: OpenAI) -> None:
94with client.admin.organization.certificates.with_streaming_response.retrieve(
95certificate_id="certificate_id",
96) as response:
97assert not response.is_closed
98assert response.http_request.headers.get("X-Stainless-Lang") == "python"
99
100certificate = response.parse()
101assert_matches_type(Certificate, certificate, path=["response"])
102
103assert cast(Any, response.is_closed) is True
104
105@parametrize
106def test_path_params_retrieve(self, client: OpenAI) -> None:
107with pytest.raises(ValueError, match=r"Expected a non-empty value for `certificate_id` but received ''"):
108client.admin.organization.certificates.with_raw_response.retrieve(
109certificate_id="",
110)
111
112@parametrize
113def test_method_update(self, client: OpenAI) -> None:
b1417cc7stainless-app[bot]2 months ago114certificate = client.admin.organization.certificates.update(
115certificate_id="certificate_id",
116)
117assert_matches_type(Certificate, certificate, path=["response"])
118
119@parametrize
120def test_method_update_with_all_params(self, client: OpenAI) -> None:
d05f3a87stainless-app[bot]2 months ago121certificate = client.admin.organization.certificates.update(
122certificate_id="certificate_id",
123name="name",
124)
125assert_matches_type(Certificate, certificate, path=["response"])
126
127@parametrize
128def test_raw_response_update(self, client: OpenAI) -> None:
129response = client.admin.organization.certificates.with_raw_response.update(
130certificate_id="certificate_id",
131)
132
133assert response.is_closed is True
134assert response.http_request.headers.get("X-Stainless-Lang") == "python"
135certificate = response.parse()
136assert_matches_type(Certificate, certificate, path=["response"])
137
138@parametrize
139def test_streaming_response_update(self, client: OpenAI) -> None:
140with client.admin.organization.certificates.with_streaming_response.update(
141certificate_id="certificate_id",
142) as response:
143assert not response.is_closed
144assert response.http_request.headers.get("X-Stainless-Lang") == "python"
145
146certificate = response.parse()
147assert_matches_type(Certificate, certificate, path=["response"])
148
149assert cast(Any, response.is_closed) is True
150
151@parametrize
152def test_path_params_update(self, client: OpenAI) -> None:
153with pytest.raises(ValueError, match=r"Expected a non-empty value for `certificate_id` but received ''"):
154client.admin.organization.certificates.with_raw_response.update(
155certificate_id="",
156)
157
158@parametrize
159def test_method_list(self, client: OpenAI) -> None:
160certificate = client.admin.organization.certificates.list()
b1417cc7stainless-app[bot]2 months ago161assert_matches_type(SyncConversationCursorPage[CertificateListResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago162
163@parametrize
164def test_method_list_with_all_params(self, client: OpenAI) -> None:
165certificate = client.admin.organization.certificates.list(
166after="after",
167limit=0,
168order="asc",
169)
b1417cc7stainless-app[bot]2 months ago170assert_matches_type(SyncConversationCursorPage[CertificateListResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago171
172@parametrize
173def test_raw_response_list(self, client: OpenAI) -> None:
174response = client.admin.organization.certificates.with_raw_response.list()
175
176assert response.is_closed is True
177assert response.http_request.headers.get("X-Stainless-Lang") == "python"
178certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago179assert_matches_type(SyncConversationCursorPage[CertificateListResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago180
181@parametrize
182def test_streaming_response_list(self, client: OpenAI) -> None:
183with client.admin.organization.certificates.with_streaming_response.list() as response:
184assert not response.is_closed
185assert response.http_request.headers.get("X-Stainless-Lang") == "python"
186
187certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago188assert_matches_type(SyncConversationCursorPage[CertificateListResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago189
190assert cast(Any, response.is_closed) is True
191
192@parametrize
193def test_method_delete(self, client: OpenAI) -> None:
194certificate = client.admin.organization.certificates.delete(
195"certificate_id",
196)
197assert_matches_type(CertificateDeleteResponse, certificate, path=["response"])
198
199@parametrize
200def test_raw_response_delete(self, client: OpenAI) -> None:
201response = client.admin.organization.certificates.with_raw_response.delete(
202"certificate_id",
203)
204
205assert response.is_closed is True
206assert response.http_request.headers.get("X-Stainless-Lang") == "python"
207certificate = response.parse()
208assert_matches_type(CertificateDeleteResponse, certificate, path=["response"])
209
210@parametrize
211def test_streaming_response_delete(self, client: OpenAI) -> None:
212with client.admin.organization.certificates.with_streaming_response.delete(
213"certificate_id",
214) as response:
215assert not response.is_closed
216assert response.http_request.headers.get("X-Stainless-Lang") == "python"
217
218certificate = response.parse()
219assert_matches_type(CertificateDeleteResponse, certificate, path=["response"])
220
221assert cast(Any, response.is_closed) is True
222
223@parametrize
224def test_path_params_delete(self, client: OpenAI) -> None:
225with pytest.raises(ValueError, match=r"Expected a non-empty value for `certificate_id` but received ''"):
226client.admin.organization.certificates.with_raw_response.delete(
227"",
228)
229
230@parametrize
231def test_method_activate(self, client: OpenAI) -> None:
232certificate = client.admin.organization.certificates.activate(
233certificate_ids=["cert_abc"],
234)
b1417cc7stainless-app[bot]2 months ago235assert_matches_type(SyncPage[CertificateActivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago236
237@parametrize
238def test_raw_response_activate(self, client: OpenAI) -> None:
239response = client.admin.organization.certificates.with_raw_response.activate(
240certificate_ids=["cert_abc"],
241)
242
243assert response.is_closed is True
244assert response.http_request.headers.get("X-Stainless-Lang") == "python"
245certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago246assert_matches_type(SyncPage[CertificateActivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago247
248@parametrize
249def test_streaming_response_activate(self, client: OpenAI) -> None:
250with client.admin.organization.certificates.with_streaming_response.activate(
251certificate_ids=["cert_abc"],
252) as response:
253assert not response.is_closed
254assert response.http_request.headers.get("X-Stainless-Lang") == "python"
255
256certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago257assert_matches_type(SyncPage[CertificateActivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago258
259assert cast(Any, response.is_closed) is True
260
261@parametrize
262def test_method_deactivate(self, client: OpenAI) -> None:
263certificate = client.admin.organization.certificates.deactivate(
264certificate_ids=["cert_abc"],
265)
b1417cc7stainless-app[bot]2 months ago266assert_matches_type(SyncPage[CertificateDeactivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago267
268@parametrize
269def test_raw_response_deactivate(self, client: OpenAI) -> None:
270response = client.admin.organization.certificates.with_raw_response.deactivate(
271certificate_ids=["cert_abc"],
272)
273
274assert response.is_closed is True
275assert response.http_request.headers.get("X-Stainless-Lang") == "python"
276certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago277assert_matches_type(SyncPage[CertificateDeactivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago278
279@parametrize
280def test_streaming_response_deactivate(self, client: OpenAI) -> None:
281with client.admin.organization.certificates.with_streaming_response.deactivate(
282certificate_ids=["cert_abc"],
283) as response:
284assert not response.is_closed
285assert response.http_request.headers.get("X-Stainless-Lang") == "python"
286
287certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago288assert_matches_type(SyncPage[CertificateDeactivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago289
290assert cast(Any, response.is_closed) is True
291
292
293class TestAsyncCertificates:
294parametrize = pytest.mark.parametrize(
295"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
296)
297
298@parametrize
299async def test_method_create(self, async_client: AsyncOpenAI) -> None:
300certificate = await async_client.admin.organization.certificates.create(
b1417cc7stainless-app[bot]2 months ago301certificate="certificate",
d05f3a87stainless-app[bot]2 months ago302)
303assert_matches_type(Certificate, certificate, path=["response"])
304
305@parametrize
306async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
307certificate = await async_client.admin.organization.certificates.create(
b1417cc7stainless-app[bot]2 months ago308certificate="certificate",
d05f3a87stainless-app[bot]2 months ago309name="name",
310)
311assert_matches_type(Certificate, certificate, path=["response"])
312
313@parametrize
314async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
315response = await async_client.admin.organization.certificates.with_raw_response.create(
b1417cc7stainless-app[bot]2 months ago316certificate="certificate",
d05f3a87stainless-app[bot]2 months ago317)
318
319assert response.is_closed is True
320assert response.http_request.headers.get("X-Stainless-Lang") == "python"
321certificate = response.parse()
322assert_matches_type(Certificate, certificate, path=["response"])
323
324@parametrize
325async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
326async with async_client.admin.organization.certificates.with_streaming_response.create(
b1417cc7stainless-app[bot]2 months ago327certificate="certificate",
d05f3a87stainless-app[bot]2 months ago328) as response:
329assert not response.is_closed
330assert response.http_request.headers.get("X-Stainless-Lang") == "python"
331
332certificate = await response.parse()
333assert_matches_type(Certificate, certificate, path=["response"])
334
335assert cast(Any, response.is_closed) is True
336
337@parametrize
338async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
339certificate = await async_client.admin.organization.certificates.retrieve(
340certificate_id="certificate_id",
341)
342assert_matches_type(Certificate, certificate, path=["response"])
343
344@parametrize
345async def test_method_retrieve_with_all_params(self, async_client: AsyncOpenAI) -> None:
346certificate = await async_client.admin.organization.certificates.retrieve(
347certificate_id="certificate_id",
348include=["content"],
349)
350assert_matches_type(Certificate, certificate, path=["response"])
351
352@parametrize
353async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
354response = await async_client.admin.organization.certificates.with_raw_response.retrieve(
355certificate_id="certificate_id",
356)
357
358assert response.is_closed is True
359assert response.http_request.headers.get("X-Stainless-Lang") == "python"
360certificate = response.parse()
361assert_matches_type(Certificate, certificate, path=["response"])
362
363@parametrize
364async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
365async with async_client.admin.organization.certificates.with_streaming_response.retrieve(
366certificate_id="certificate_id",
367) as response:
368assert not response.is_closed
369assert response.http_request.headers.get("X-Stainless-Lang") == "python"
370
371certificate = await response.parse()
372assert_matches_type(Certificate, certificate, path=["response"])
373
374assert cast(Any, response.is_closed) is True
375
376@parametrize
377async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
378with pytest.raises(ValueError, match=r"Expected a non-empty value for `certificate_id` but received ''"):
379await async_client.admin.organization.certificates.with_raw_response.retrieve(
380certificate_id="",
381)
382
383@parametrize
384async def test_method_update(self, async_client: AsyncOpenAI) -> None:
b1417cc7stainless-app[bot]2 months ago385certificate = await async_client.admin.organization.certificates.update(
386certificate_id="certificate_id",
387)
388assert_matches_type(Certificate, certificate, path=["response"])
389
390@parametrize
391async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None:
d05f3a87stainless-app[bot]2 months ago392certificate = await async_client.admin.organization.certificates.update(
393certificate_id="certificate_id",
394name="name",
395)
396assert_matches_type(Certificate, certificate, path=["response"])
397
398@parametrize
399async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
400response = await async_client.admin.organization.certificates.with_raw_response.update(
401certificate_id="certificate_id",
402)
403
404assert response.is_closed is True
405assert response.http_request.headers.get("X-Stainless-Lang") == "python"
406certificate = response.parse()
407assert_matches_type(Certificate, certificate, path=["response"])
408
409@parametrize
410async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
411async with async_client.admin.organization.certificates.with_streaming_response.update(
412certificate_id="certificate_id",
413) as response:
414assert not response.is_closed
415assert response.http_request.headers.get("X-Stainless-Lang") == "python"
416
417certificate = await response.parse()
418assert_matches_type(Certificate, certificate, path=["response"])
419
420assert cast(Any, response.is_closed) is True
421
422@parametrize
423async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
424with pytest.raises(ValueError, match=r"Expected a non-empty value for `certificate_id` but received ''"):
425await async_client.admin.organization.certificates.with_raw_response.update(
426certificate_id="",
427)
428
429@parametrize
430async def test_method_list(self, async_client: AsyncOpenAI) -> None:
431certificate = await async_client.admin.organization.certificates.list()
b1417cc7stainless-app[bot]2 months ago432assert_matches_type(AsyncConversationCursorPage[CertificateListResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago433
434@parametrize
435async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
436certificate = await async_client.admin.organization.certificates.list(
437after="after",
438limit=0,
439order="asc",
440)
b1417cc7stainless-app[bot]2 months ago441assert_matches_type(AsyncConversationCursorPage[CertificateListResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago442
443@parametrize
444async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
445response = await async_client.admin.organization.certificates.with_raw_response.list()
446
447assert response.is_closed is True
448assert response.http_request.headers.get("X-Stainless-Lang") == "python"
449certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago450assert_matches_type(AsyncConversationCursorPage[CertificateListResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago451
452@parametrize
453async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
454async with async_client.admin.organization.certificates.with_streaming_response.list() as response:
455assert not response.is_closed
456assert response.http_request.headers.get("X-Stainless-Lang") == "python"
457
458certificate = await response.parse()
b1417cc7stainless-app[bot]2 months ago459assert_matches_type(AsyncConversationCursorPage[CertificateListResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago460
461assert cast(Any, response.is_closed) is True
462
463@parametrize
464async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
465certificate = await async_client.admin.organization.certificates.delete(
466"certificate_id",
467)
468assert_matches_type(CertificateDeleteResponse, certificate, path=["response"])
469
470@parametrize
471async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
472response = await async_client.admin.organization.certificates.with_raw_response.delete(
473"certificate_id",
474)
475
476assert response.is_closed is True
477assert response.http_request.headers.get("X-Stainless-Lang") == "python"
478certificate = response.parse()
479assert_matches_type(CertificateDeleteResponse, certificate, path=["response"])
480
481@parametrize
482async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
483async with async_client.admin.organization.certificates.with_streaming_response.delete(
484"certificate_id",
485) as response:
486assert not response.is_closed
487assert response.http_request.headers.get("X-Stainless-Lang") == "python"
488
489certificate = await response.parse()
490assert_matches_type(CertificateDeleteResponse, certificate, path=["response"])
491
492assert cast(Any, response.is_closed) is True
493
494@parametrize
495async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
496with pytest.raises(ValueError, match=r"Expected a non-empty value for `certificate_id` but received ''"):
497await async_client.admin.organization.certificates.with_raw_response.delete(
498"",
499)
500
501@parametrize
502async def test_method_activate(self, async_client: AsyncOpenAI) -> None:
503certificate = await async_client.admin.organization.certificates.activate(
504certificate_ids=["cert_abc"],
505)
b1417cc7stainless-app[bot]2 months ago506assert_matches_type(AsyncPage[CertificateActivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago507
508@parametrize
509async def test_raw_response_activate(self, async_client: AsyncOpenAI) -> None:
510response = await async_client.admin.organization.certificates.with_raw_response.activate(
511certificate_ids=["cert_abc"],
512)
513
514assert response.is_closed is True
515assert response.http_request.headers.get("X-Stainless-Lang") == "python"
516certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago517assert_matches_type(AsyncPage[CertificateActivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago518
519@parametrize
520async def test_streaming_response_activate(self, async_client: AsyncOpenAI) -> None:
521async with async_client.admin.organization.certificates.with_streaming_response.activate(
522certificate_ids=["cert_abc"],
523) as response:
524assert not response.is_closed
525assert response.http_request.headers.get("X-Stainless-Lang") == "python"
526
527certificate = await response.parse()
b1417cc7stainless-app[bot]2 months ago528assert_matches_type(AsyncPage[CertificateActivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago529
530assert cast(Any, response.is_closed) is True
531
532@parametrize
533async def test_method_deactivate(self, async_client: AsyncOpenAI) -> None:
534certificate = await async_client.admin.organization.certificates.deactivate(
535certificate_ids=["cert_abc"],
536)
b1417cc7stainless-app[bot]2 months ago537assert_matches_type(AsyncPage[CertificateDeactivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago538
539@parametrize
540async def test_raw_response_deactivate(self, async_client: AsyncOpenAI) -> None:
541response = await async_client.admin.organization.certificates.with_raw_response.deactivate(
542certificate_ids=["cert_abc"],
543)
544
545assert response.is_closed is True
546assert response.http_request.headers.get("X-Stainless-Lang") == "python"
547certificate = response.parse()
b1417cc7stainless-app[bot]2 months ago548assert_matches_type(AsyncPage[CertificateDeactivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago549
550@parametrize
551async def test_streaming_response_deactivate(self, async_client: AsyncOpenAI) -> None:
552async with async_client.admin.organization.certificates.with_streaming_response.deactivate(
553certificate_ids=["cert_abc"],
554) as response:
555assert not response.is_closed
556assert response.http_request.headers.get("X-Stainless-Lang") == "python"
557
558certificate = await response.parse()
b1417cc7stainless-app[bot]2 months ago559assert_matches_type(AsyncPage[CertificateDeactivateResponse], certificate, path=["response"])
d05f3a87stainless-app[bot]2 months ago560
561assert cast(Any, response.is_closed) is True