openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/hayden/bedrock-aws-auth

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/test_data_retention.py

136lines · 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.types.admin.organization import OrganizationDataRetention
13
14base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
15
16
17class TestDataRetention:
18 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
19
20 @parametrize
21 def test_method_retrieve(self, client: OpenAI) -> None:
22 data_retention = client.admin.organization.data_retention.retrieve()
23 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
24
25 @parametrize
26 def test_raw_response_retrieve(self, client: OpenAI) -> None:
27 response = client.admin.organization.data_retention.with_raw_response.retrieve()
28
29 assert response.is_closed is True
30 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
31 data_retention = response.parse()
32 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
33
34 @parametrize
35 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
36 with client.admin.organization.data_retention.with_streaming_response.retrieve() as response:
37 assert not response.is_closed
38 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
39
40 data_retention = response.parse()
41 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
42
43 assert cast(Any, response.is_closed) is True
44
45 @parametrize
46 def test_method_update(self, client: OpenAI) -> None:
47 data_retention = client.admin.organization.data_retention.update(
48 retention_type="zero_data_retention",
49 )
50 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
51
52 @parametrize
53 def test_raw_response_update(self, client: OpenAI) -> None:
54 response = client.admin.organization.data_retention.with_raw_response.update(
55 retention_type="zero_data_retention",
56 )
57
58 assert response.is_closed is True
59 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
60 data_retention = response.parse()
61 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
62
63 @parametrize
64 def test_streaming_response_update(self, client: OpenAI) -> None:
65 with client.admin.organization.data_retention.with_streaming_response.update(
66 retention_type="zero_data_retention",
67 ) as response:
68 assert not response.is_closed
69 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
70
71 data_retention = response.parse()
72 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
73
74 assert cast(Any, response.is_closed) is True
75
76
77class TestAsyncDataRetention:
78 parametrize = pytest.mark.parametrize(
79 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
80 )
81
82 @parametrize
83 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
84 data_retention = await async_client.admin.organization.data_retention.retrieve()
85 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
86
87 @parametrize
88 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
89 response = await async_client.admin.organization.data_retention.with_raw_response.retrieve()
90
91 assert response.is_closed is True
92 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
93 data_retention = response.parse()
94 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
95
96 @parametrize
97 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
98 async with async_client.admin.organization.data_retention.with_streaming_response.retrieve() as response:
99 assert not response.is_closed
100 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
101
102 data_retention = await response.parse()
103 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
104
105 assert cast(Any, response.is_closed) is True
106
107 @parametrize
108 async def test_method_update(self, async_client: AsyncOpenAI) -> None:
109 data_retention = await async_client.admin.organization.data_retention.update(
110 retention_type="zero_data_retention",
111 )
112 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
113
114 @parametrize
115 async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
116 response = await async_client.admin.organization.data_retention.with_raw_response.update(
117 retention_type="zero_data_retention",
118 )
119
120 assert response.is_closed is True
121 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
122 data_retention = response.parse()
123 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
124
125 @parametrize
126 async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
127 async with async_client.admin.organization.data_retention.with_streaming_response.update(
128 retention_type="zero_data_retention",
129 ) as response:
130 assert not response.is_closed
131 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
132
133 data_retention = await response.parse()
134 assert_matches_type(OrganizationDataRetention, data_retention, path=["response"])
135
136 assert cast(Any, response.is_closed) is True
137