Debian Codegraph @

tests/api_resources/beta/organization/test_service_accounts.py

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