openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
codex/bedrock-thin-provider-rewrite

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/admin/organization/projects/test_data_retention.py

184lines · 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.projects import ProjectDataRetention
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.projects.data_retention.retrieve(
23 "project_id",
24 )
25 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
26
27 @parametrize
28 def test_raw_response_retrieve(self, client: OpenAI) -> None:
29 response = client.admin.organization.projects.data_retention.with_raw_response.retrieve(
30 "project_id",
31 )
32
33 assert response.is_closed is True
34 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
35 data_retention = response.parse()
36 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
37
38 @parametrize
39 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
40 with client.admin.organization.projects.data_retention.with_streaming_response.retrieve(
41 "project_id",
42 ) as response:
43 assert not response.is_closed
44 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
45
46 data_retention = response.parse()
47 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
48
49 assert cast(Any, response.is_closed) is True
50
51 @parametrize
52 def test_path_params_retrieve(self, client: OpenAI) -> None:
53 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
54 client.admin.organization.projects.data_retention.with_raw_response.retrieve(
55 "",
56 )
57
58 @parametrize
59 def test_method_update(self, client: OpenAI) -> None:
60 data_retention = client.admin.organization.projects.data_retention.update(
61 project_id="project_id",
62 retention_type="organization_default",
63 )
64 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
65
66 @parametrize
67 def test_raw_response_update(self, client: OpenAI) -> None:
68 response = client.admin.organization.projects.data_retention.with_raw_response.update(
69 project_id="project_id",
70 retention_type="organization_default",
71 )
72
73 assert response.is_closed is True
74 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
75 data_retention = response.parse()
76 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
77
78 @parametrize
79 def test_streaming_response_update(self, client: OpenAI) -> None:
80 with client.admin.organization.projects.data_retention.with_streaming_response.update(
81 project_id="project_id",
82 retention_type="organization_default",
83 ) as response:
84 assert not response.is_closed
85 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86
87 data_retention = response.parse()
88 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
89
90 assert cast(Any, response.is_closed) is True
91
92 @parametrize
93 def test_path_params_update(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.data_retention.with_raw_response.update(
96 project_id="",
97 retention_type="organization_default",
98 )
99
100
101class TestAsyncDataRetention:
102 parametrize = pytest.mark.parametrize(
103 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
104 )
105
106 @parametrize
107 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
108 data_retention = await async_client.admin.organization.projects.data_retention.retrieve(
109 "project_id",
110 )
111 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
112
113 @parametrize
114 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
115 response = await async_client.admin.organization.projects.data_retention.with_raw_response.retrieve(
116 "project_id",
117 )
118
119 assert response.is_closed is True
120 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
121 data_retention = response.parse()
122 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
123
124 @parametrize
125 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
126 async with async_client.admin.organization.projects.data_retention.with_streaming_response.retrieve(
127 "project_id",
128 ) as response:
129 assert not response.is_closed
130 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
131
132 data_retention = await response.parse()
133 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
134
135 assert cast(Any, response.is_closed) is True
136
137 @parametrize
138 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
139 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
140 await async_client.admin.organization.projects.data_retention.with_raw_response.retrieve(
141 "",
142 )
143
144 @parametrize
145 async def test_method_update(self, async_client: AsyncOpenAI) -> None:
146 data_retention = await async_client.admin.organization.projects.data_retention.update(
147 project_id="project_id",
148 retention_type="organization_default",
149 )
150 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
151
152 @parametrize
153 async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
154 response = await async_client.admin.organization.projects.data_retention.with_raw_response.update(
155 project_id="project_id",
156 retention_type="organization_default",
157 )
158
159 assert response.is_closed is True
160 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
161 data_retention = response.parse()
162 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
163
164 @parametrize
165 async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
166 async with async_client.admin.organization.projects.data_retention.with_streaming_response.update(
167 project_id="project_id",
168 retention_type="organization_default",
169 ) as response:
170 assert not response.is_closed
171 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
172
173 data_retention = await response.parse()
174 assert_matches_type(ProjectDataRetention, data_retention, path=["response"])
175
176 assert cast(Any, response.is_closed) is True
177
178 @parametrize
179 async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
180 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
181 await async_client.admin.organization.projects.data_retention.with_raw_response.update(
182 project_id="",
183 retention_type="organization_default",
184 )
185