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/projects/test_rate_limits.py

247lines · 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.projects import (
14 ProjectRateLimit,
15)
16
17base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20class TestRateLimits:
21 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
22
23 @parametrize
24 def test_method_list_rate_limits(self, client: OpenAI) -> None:
25 rate_limit = client.admin.organization.projects.rate_limits.list_rate_limits(
26 project_id="project_id",
27 )
28 assert_matches_type(SyncConversationCursorPage[ProjectRateLimit], rate_limit, path=["response"])
29
30 @parametrize
31 def test_method_list_rate_limits_with_all_params(self, client: OpenAI) -> None:
32 rate_limit = client.admin.organization.projects.rate_limits.list_rate_limits(
33 project_id="project_id",
34 after="after",
35 before="before",
36 limit=0,
37 )
38 assert_matches_type(SyncConversationCursorPage[ProjectRateLimit], rate_limit, path=["response"])
39
40 @parametrize
41 def test_raw_response_list_rate_limits(self, client: OpenAI) -> None:
42 response = client.admin.organization.projects.rate_limits.with_raw_response.list_rate_limits(
43 project_id="project_id",
44 )
45
46 assert response.is_closed is True
47 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
48 rate_limit = response.parse()
49 assert_matches_type(SyncConversationCursorPage[ProjectRateLimit], rate_limit, path=["response"])
50
51 @parametrize
52 def test_streaming_response_list_rate_limits(self, client: OpenAI) -> None:
53 with client.admin.organization.projects.rate_limits.with_streaming_response.list_rate_limits(
54 project_id="project_id",
55 ) as response:
56 assert not response.is_closed
57 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
58
59 rate_limit = response.parse()
60 assert_matches_type(SyncConversationCursorPage[ProjectRateLimit], rate_limit, path=["response"])
61
62 assert cast(Any, response.is_closed) is True
63
64 @parametrize
65 def test_path_params_list_rate_limits(self, client: OpenAI) -> None:
66 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
67 client.admin.organization.projects.rate_limits.with_raw_response.list_rate_limits(
68 project_id="",
69 )
70
71 @parametrize
72 def test_method_update_rate_limit(self, client: OpenAI) -> None:
73 rate_limit = client.admin.organization.projects.rate_limits.update_rate_limit(
74 rate_limit_id="rate_limit_id",
75 project_id="project_id",
76 )
77 assert_matches_type(ProjectRateLimit, rate_limit, path=["response"])
78
79 @parametrize
80 def test_method_update_rate_limit_with_all_params(self, client: OpenAI) -> None:
81 rate_limit = client.admin.organization.projects.rate_limits.update_rate_limit(
82 rate_limit_id="rate_limit_id",
83 project_id="project_id",
84 batch_1_day_max_input_tokens=0,
85 max_audio_megabytes_per_1_minute=0,
86 max_images_per_1_minute=0,
87 max_requests_per_1_day=0,
88 max_requests_per_1_minute=0,
89 max_tokens_per_1_minute=0,
90 )
91 assert_matches_type(ProjectRateLimit, rate_limit, path=["response"])
92
93 @parametrize
94 def test_raw_response_update_rate_limit(self, client: OpenAI) -> None:
95 response = client.admin.organization.projects.rate_limits.with_raw_response.update_rate_limit(
96 rate_limit_id="rate_limit_id",
97 project_id="project_id",
98 )
99
100 assert response.is_closed is True
101 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
102 rate_limit = response.parse()
103 assert_matches_type(ProjectRateLimit, rate_limit, path=["response"])
104
105 @parametrize
106 def test_streaming_response_update_rate_limit(self, client: OpenAI) -> None:
107 with client.admin.organization.projects.rate_limits.with_streaming_response.update_rate_limit(
108 rate_limit_id="rate_limit_id",
109 project_id="project_id",
110 ) as response:
111 assert not response.is_closed
112 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
113
114 rate_limit = response.parse()
115 assert_matches_type(ProjectRateLimit, rate_limit, path=["response"])
116
117 assert cast(Any, response.is_closed) is True
118
119 @parametrize
120 def test_path_params_update_rate_limit(self, client: OpenAI) -> None:
121 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
122 client.admin.organization.projects.rate_limits.with_raw_response.update_rate_limit(
123 rate_limit_id="rate_limit_id",
124 project_id="",
125 )
126
127 with pytest.raises(ValueError, match=r"Expected a non-empty value for `rate_limit_id` but received ''"):
128 client.admin.organization.projects.rate_limits.with_raw_response.update_rate_limit(
129 rate_limit_id="",
130 project_id="project_id",
131 )
132
133
134class TestAsyncRateLimits:
135 parametrize = pytest.mark.parametrize(
136 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
137 )
138
139 @parametrize
140 async def test_method_list_rate_limits(self, async_client: AsyncOpenAI) -> None:
141 rate_limit = await async_client.admin.organization.projects.rate_limits.list_rate_limits(
142 project_id="project_id",
143 )
144 assert_matches_type(AsyncConversationCursorPage[ProjectRateLimit], rate_limit, path=["response"])
145
146 @parametrize
147 async def test_method_list_rate_limits_with_all_params(self, async_client: AsyncOpenAI) -> None:
148 rate_limit = await async_client.admin.organization.projects.rate_limits.list_rate_limits(
149 project_id="project_id",
150 after="after",
151 before="before",
152 limit=0,
153 )
154 assert_matches_type(AsyncConversationCursorPage[ProjectRateLimit], rate_limit, path=["response"])
155
156 @parametrize
157 async def test_raw_response_list_rate_limits(self, async_client: AsyncOpenAI) -> None:
158 response = await async_client.admin.organization.projects.rate_limits.with_raw_response.list_rate_limits(
159 project_id="project_id",
160 )
161
162 assert response.is_closed is True
163 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
164 rate_limit = response.parse()
165 assert_matches_type(AsyncConversationCursorPage[ProjectRateLimit], rate_limit, path=["response"])
166
167 @parametrize
168 async def test_streaming_response_list_rate_limits(self, async_client: AsyncOpenAI) -> None:
169 async with async_client.admin.organization.projects.rate_limits.with_streaming_response.list_rate_limits(
170 project_id="project_id",
171 ) as response:
172 assert not response.is_closed
173 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
174
175 rate_limit = await response.parse()
176 assert_matches_type(AsyncConversationCursorPage[ProjectRateLimit], rate_limit, path=["response"])
177
178 assert cast(Any, response.is_closed) is True
179
180 @parametrize
181 async def test_path_params_list_rate_limits(self, async_client: AsyncOpenAI) -> None:
182 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
183 await async_client.admin.organization.projects.rate_limits.with_raw_response.list_rate_limits(
184 project_id="",
185 )
186
187 @parametrize
188 async def test_method_update_rate_limit(self, async_client: AsyncOpenAI) -> None:
189 rate_limit = await async_client.admin.organization.projects.rate_limits.update_rate_limit(
190 rate_limit_id="rate_limit_id",
191 project_id="project_id",
192 )
193 assert_matches_type(ProjectRateLimit, rate_limit, path=["response"])
194
195 @parametrize
196 async def test_method_update_rate_limit_with_all_params(self, async_client: AsyncOpenAI) -> None:
197 rate_limit = await async_client.admin.organization.projects.rate_limits.update_rate_limit(
198 rate_limit_id="rate_limit_id",
199 project_id="project_id",
200 batch_1_day_max_input_tokens=0,
201 max_audio_megabytes_per_1_minute=0,
202 max_images_per_1_minute=0,
203 max_requests_per_1_day=0,
204 max_requests_per_1_minute=0,
205 max_tokens_per_1_minute=0,
206 )
207 assert_matches_type(ProjectRateLimit, rate_limit, path=["response"])
208
209 @parametrize
210 async def test_raw_response_update_rate_limit(self, async_client: AsyncOpenAI) -> None:
211 response = await async_client.admin.organization.projects.rate_limits.with_raw_response.update_rate_limit(
212 rate_limit_id="rate_limit_id",
213 project_id="project_id",
214 )
215
216 assert response.is_closed is True
217 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
218 rate_limit = response.parse()
219 assert_matches_type(ProjectRateLimit, rate_limit, path=["response"])
220
221 @parametrize
222 async def test_streaming_response_update_rate_limit(self, async_client: AsyncOpenAI) -> None:
223 async with async_client.admin.organization.projects.rate_limits.with_streaming_response.update_rate_limit(
224 rate_limit_id="rate_limit_id",
225 project_id="project_id",
226 ) as response:
227 assert not response.is_closed
228 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
229
230 rate_limit = await response.parse()
231 assert_matches_type(ProjectRateLimit, rate_limit, path=["response"])
232
233 assert cast(Any, response.is_closed) is True
234
235 @parametrize
236 async def test_path_params_update_rate_limit(self, async_client: AsyncOpenAI) -> None:
237 with pytest.raises(ValueError, match=r"Expected a non-empty value for `project_id` but received ''"):
238 await async_client.admin.organization.projects.rate_limits.with_raw_response.update_rate_limit(
239 rate_limit_id="rate_limit_id",
240 project_id="",
241 )
242
243 with pytest.raises(ValueError, match=r"Expected a non-empty value for `rate_limit_id` but received ''"):
244 await async_client.admin.organization.projects.rate_limits.with_raw_response.update_rate_limit(
245 rate_limit_id="",
246 project_id="project_id",
247 )
248