Debian Codegraph @

tests/api_resources/beta/organization/federation/test_rules.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.federation import (
12 BetaFederationRule,
13 )
14
15 base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16
17
18 class TestRules:
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 rule = client.beta.organization.federation.rules.create(
24 issuer_id="issuer_id",
25 match={},
26 name="x",
27 oauth_scope="x",
28 target={
29 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
30 "type": "service_account",
31 },
32 )
33 assert_matches_type(BetaFederationRule, rule, path=["response"])
34
35 @parametrize
36 def test_method_create_with_all_params(self, client: Anthropic) -> None:
37 rule = client.beta.organization.federation.rules.create(
38 issuer_id="issuer_id",
39 match={
40 "audience": "audience",
41 "claims": {"foo": "string"},
42 "condition": "condition",
43 "subject_prefix": "subject_prefix",
44 },
45 name="x",
46 oauth_scope="x",
47 target={
48 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
49 "type": "service_account",
50 "service_account_name": "service_account_name",
51 },
52 applies_to_all_workspaces=True,
53 attributes={"foo": "string"},
54 description="description",
55 token_lifetime_seconds=60,
56 workspace_id="workspace_id",
57 betas=["message-batches-2024-09-24"],
58 )
59 assert_matches_type(BetaFederationRule, rule, path=["response"])
60
61 @parametrize
62 def test_raw_response_create(self, client: Anthropic) -> None:
63 response = client.beta.organization.federation.rules.with_raw_response.create(
64 issuer_id="issuer_id",
65 match={},
66 name="x",
67 oauth_scope="x",
68 target={
69 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
70 "type": "service_account",
71 },
72 )
73
74 assert response.is_closed is True
75 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
76 rule = response.parse()
77 assert_matches_type(BetaFederationRule, rule, path=["response"])
78
79 @parametrize
80 def test_streaming_response_create(self, client: Anthropic) -> None:
81 with client.beta.organization.federation.rules.with_streaming_response.create(
82 issuer_id="issuer_id",
83 match={},
84 name="x",
85 oauth_scope="x",
86 target={
87 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
88 "type": "service_account",
89 },
90 ) as response:
91 assert not response.is_closed
92 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
93
94 rule = response.parse()
95 assert_matches_type(BetaFederationRule, rule, path=["response"])
96
97 assert cast(Any, response.is_closed) is True
98
99 @parametrize
100 def test_method_retrieve(self, client: Anthropic) -> None:
101 rule = client.beta.organization.federation.rules.retrieve(
102 federation_rule_id="federation_rule_id",
103 )
104 assert_matches_type(BetaFederationRule, rule, path=["response"])
105
106 @parametrize
107 def test_method_retrieve_with_all_params(self, client: Anthropic) -> None:
108 rule = client.beta.organization.federation.rules.retrieve(
109 federation_rule_id="federation_rule_id",
110 betas=["message-batches-2024-09-24"],
111 )
112 assert_matches_type(BetaFederationRule, rule, path=["response"])
113
114 @parametrize
115 def test_raw_response_retrieve(self, client: Anthropic) -> None:
116 response = client.beta.organization.federation.rules.with_raw_response.retrieve(
117 federation_rule_id="federation_rule_id",
118 )
119
120 assert response.is_closed is True
121 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
122 rule = response.parse()
123 assert_matches_type(BetaFederationRule, rule, path=["response"])
124
125 @parametrize
126 def test_streaming_response_retrieve(self, client: Anthropic) -> None:
127 with client.beta.organization.federation.rules.with_streaming_response.retrieve(
128 federation_rule_id="federation_rule_id",
129 ) as response:
130 assert not response.is_closed
131 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
132
133 rule = response.parse()
134 assert_matches_type(BetaFederationRule, rule, path=["response"])
135
136 assert cast(Any, response.is_closed) is True
137
138 @parametrize
139 def test_path_params_retrieve(self, client: Anthropic) -> None:
140 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
141 client.beta.organization.federation.rules.with_raw_response.retrieve(
142 federation_rule_id="",
143 )
144
145 @parametrize
146 def test_method_update(self, client: Anthropic) -> None:
147 rule = client.beta.organization.federation.rules.update(
148 federation_rule_id="federation_rule_id",
149 )
150 assert_matches_type(BetaFederationRule, rule, path=["response"])
151
152 @parametrize
153 def test_method_update_with_all_params(self, client: Anthropic) -> None:
154 rule = client.beta.organization.federation.rules.update(
155 federation_rule_id="federation_rule_id",
156 applies_to_all_workspaces=True,
157 attributes={"foo": "string"},
158 description="description",
159 match={
160 "audience": "audience",
161 "claims": {"foo": "string"},
162 "condition": "condition",
163 "subject_prefix": "subject_prefix",
164 },
165 name="x",
166 oauth_scope="x",
167 target={
168 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
169 "type": "service_account",
170 "service_account_name": "service_account_name",
171 },
172 token_lifetime_seconds=60,
173 workspace_id="workspace_id",
174 betas=["message-batches-2024-09-24"],
175 )
176 assert_matches_type(BetaFederationRule, rule, path=["response"])
177
178 @parametrize
179 def test_raw_response_update(self, client: Anthropic) -> None:
180 response = client.beta.organization.federation.rules.with_raw_response.update(
181 federation_rule_id="federation_rule_id",
182 )
183
184 assert response.is_closed is True
185 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
186 rule = response.parse()
187 assert_matches_type(BetaFederationRule, rule, path=["response"])
188
189 @parametrize
190 def test_streaming_response_update(self, client: Anthropic) -> None:
191 with client.beta.organization.federation.rules.with_streaming_response.update(
192 federation_rule_id="federation_rule_id",
193 ) as response:
194 assert not response.is_closed
195 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
196
197 rule = response.parse()
198 assert_matches_type(BetaFederationRule, rule, path=["response"])
199
200 assert cast(Any, response.is_closed) is True
201
202 @parametrize
203 def test_path_params_update(self, client: Anthropic) -> None:
204 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
205 client.beta.organization.federation.rules.with_raw_response.update(
206 federation_rule_id="",
207 )
208
209 @parametrize
210 def test_method_list(self, client: Anthropic) -> None:
211 rule = client.beta.organization.federation.rules.list()
212 assert_matches_type(SyncPageCursor[BetaFederationRule], rule, path=["response"])
213
214 @parametrize
215 def test_method_list_with_all_params(self, client: Anthropic) -> None:
216 rule = client.beta.organization.federation.rules.list(
217 include_archived=True,
218 issuer_id="issuer_id",
219 limit=1,
220 page="page",
221 betas=["message-batches-2024-09-24"],
222 )
223 assert_matches_type(SyncPageCursor[BetaFederationRule], rule, path=["response"])
224
225 @parametrize
226 def test_raw_response_list(self, client: Anthropic) -> None:
227 response = client.beta.organization.federation.rules.with_raw_response.list()
228
229 assert response.is_closed is True
230 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
231 rule = response.parse()
232 assert_matches_type(SyncPageCursor[BetaFederationRule], rule, path=["response"])
233
234 @parametrize
235 def test_streaming_response_list(self, client: Anthropic) -> None:
236 with client.beta.organization.federation.rules.with_streaming_response.list() as response:
237 assert not response.is_closed
238 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
239
240 rule = response.parse()
241 assert_matches_type(SyncPageCursor[BetaFederationRule], rule, path=["response"])
242
243 assert cast(Any, response.is_closed) is True
244
245 @parametrize
246 def test_method_archive(self, client: Anthropic) -> None:
247 rule = client.beta.organization.federation.rules.archive(
248 federation_rule_id="federation_rule_id",
249 )
250 assert_matches_type(BetaFederationRule, rule, path=["response"])
251
252 @parametrize
253 def test_method_archive_with_all_params(self, client: Anthropic) -> None:
254 rule = client.beta.organization.federation.rules.archive(
255 federation_rule_id="federation_rule_id",
256 betas=["message-batches-2024-09-24"],
257 )
258 assert_matches_type(BetaFederationRule, rule, path=["response"])
259
260 @parametrize
261 def test_raw_response_archive(self, client: Anthropic) -> None:
262 response = client.beta.organization.federation.rules.with_raw_response.archive(
263 federation_rule_id="federation_rule_id",
264 )
265
266 assert response.is_closed is True
267 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
268 rule = response.parse()
269 assert_matches_type(BetaFederationRule, rule, path=["response"])
270
271 @parametrize
272 def test_streaming_response_archive(self, client: Anthropic) -> None:
273 with client.beta.organization.federation.rules.with_streaming_response.archive(
274 federation_rule_id="federation_rule_id",
275 ) as response:
276 assert not response.is_closed
277 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
278
279 rule = response.parse()
280 assert_matches_type(BetaFederationRule, rule, path=["response"])
281
282 assert cast(Any, response.is_closed) is True
283
284 @parametrize
285 def test_path_params_archive(self, client: Anthropic) -> None:
286 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
287 client.beta.organization.federation.rules.with_raw_response.archive(
288 federation_rule_id="",
289 )
290
291
292 class TestAsyncRules:
293 parametrize = pytest.mark.parametrize(
294 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
295 )
296
297 @parametrize
298 async def test_method_create(self, async_client: AsyncAnthropic) -> None:
299 rule = await async_client.beta.organization.federation.rules.create(
300 issuer_id="issuer_id",
301 match={},
302 name="x",
303 oauth_scope="x",
304 target={
305 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
306 "type": "service_account",
307 },
308 )
309 assert_matches_type(BetaFederationRule, rule, path=["response"])
310
311 @parametrize
312 async def test_method_create_with_all_params(self, async_client: AsyncAnthropic) -> None:
313 rule = await async_client.beta.organization.federation.rules.create(
314 issuer_id="issuer_id",
315 match={
316 "audience": "audience",
317 "claims": {"foo": "string"},
318 "condition": "condition",
319 "subject_prefix": "subject_prefix",
320 },
321 name="x",
322 oauth_scope="x",
323 target={
324 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
325 "type": "service_account",
326 "service_account_name": "service_account_name",
327 },
328 applies_to_all_workspaces=True,
329 attributes={"foo": "string"},
330 description="description",
331 token_lifetime_seconds=60,
332 workspace_id="workspace_id",
333 betas=["message-batches-2024-09-24"],
334 )
335 assert_matches_type(BetaFederationRule, rule, path=["response"])
336
337 @parametrize
338 async def test_raw_response_create(self, async_client: AsyncAnthropic) -> None:
339 response = await async_client.beta.organization.federation.rules.with_raw_response.create(
340 issuer_id="issuer_id",
341 match={},
342 name="x",
343 oauth_scope="x",
344 target={
345 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
346 "type": "service_account",
347 },
348 )
349
350 assert response.is_closed is True
351 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
352 rule = await response.parse()
353 assert_matches_type(BetaFederationRule, rule, path=["response"])
354
355 @parametrize
356 async def test_streaming_response_create(self, async_client: AsyncAnthropic) -> None:
357 async with async_client.beta.organization.federation.rules.with_streaming_response.create(
358 issuer_id="issuer_id",
359 match={},
360 name="x",
361 oauth_scope="x",
362 target={
363 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
364 "type": "service_account",
365 },
366 ) as response:
367 assert not response.is_closed
368 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
369
370 rule = await response.parse()
371 assert_matches_type(BetaFederationRule, rule, path=["response"])
372
373 assert cast(Any, response.is_closed) is True
374
375 @parametrize
376 async def test_method_retrieve(self, async_client: AsyncAnthropic) -> None:
377 rule = await async_client.beta.organization.federation.rules.retrieve(
378 federation_rule_id="federation_rule_id",
379 )
380 assert_matches_type(BetaFederationRule, rule, path=["response"])
381
382 @parametrize
383 async def test_method_retrieve_with_all_params(self, async_client: AsyncAnthropic) -> None:
384 rule = await async_client.beta.organization.federation.rules.retrieve(
385 federation_rule_id="federation_rule_id",
386 betas=["message-batches-2024-09-24"],
387 )
388 assert_matches_type(BetaFederationRule, rule, path=["response"])
389
390 @parametrize
391 async def test_raw_response_retrieve(self, async_client: AsyncAnthropic) -> None:
392 response = await async_client.beta.organization.federation.rules.with_raw_response.retrieve(
393 federation_rule_id="federation_rule_id",
394 )
395
396 assert response.is_closed is True
397 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
398 rule = await response.parse()
399 assert_matches_type(BetaFederationRule, rule, path=["response"])
400
401 @parametrize
402 async def test_streaming_response_retrieve(self, async_client: AsyncAnthropic) -> None:
403 async with async_client.beta.organization.federation.rules.with_streaming_response.retrieve(
404 federation_rule_id="federation_rule_id",
405 ) as response:
406 assert not response.is_closed
407 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
408
409 rule = await response.parse()
410 assert_matches_type(BetaFederationRule, rule, path=["response"])
411
412 assert cast(Any, response.is_closed) is True
413
414 @parametrize
415 async def test_path_params_retrieve(self, async_client: AsyncAnthropic) -> None:
416 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
417 await async_client.beta.organization.federation.rules.with_raw_response.retrieve(
418 federation_rule_id="",
419 )
420
421 @parametrize
422 async def test_method_update(self, async_client: AsyncAnthropic) -> None:
423 rule = await async_client.beta.organization.federation.rules.update(
424 federation_rule_id="federation_rule_id",
425 )
426 assert_matches_type(BetaFederationRule, rule, path=["response"])
427
428 @parametrize
429 async def test_method_update_with_all_params(self, async_client: AsyncAnthropic) -> None:
430 rule = await async_client.beta.organization.federation.rules.update(
431 federation_rule_id="federation_rule_id",
432 applies_to_all_workspaces=True,
433 attributes={"foo": "string"},
434 description="description",
435 match={
436 "audience": "audience",
437 "claims": {"foo": "string"},
438 "condition": "condition",
439 "subject_prefix": "subject_prefix",
440 },
441 name="x",
442 oauth_scope="x",
443 target={
444 "service_account_id": "svac_01SDCCSbTxrXDpWc1phhtcfK",
445 "type": "service_account",
446 "service_account_name": "service_account_name",
447 },
448 token_lifetime_seconds=60,
449 workspace_id="workspace_id",
450 betas=["message-batches-2024-09-24"],
451 )
452 assert_matches_type(BetaFederationRule, rule, path=["response"])
453
454 @parametrize
455 async def test_raw_response_update(self, async_client: AsyncAnthropic) -> None:
456 response = await async_client.beta.organization.federation.rules.with_raw_response.update(
457 federation_rule_id="federation_rule_id",
458 )
459
460 assert response.is_closed is True
461 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
462 rule = await response.parse()
463 assert_matches_type(BetaFederationRule, rule, path=["response"])
464
465 @parametrize
466 async def test_streaming_response_update(self, async_client: AsyncAnthropic) -> None:
467 async with async_client.beta.organization.federation.rules.with_streaming_response.update(
468 federation_rule_id="federation_rule_id",
469 ) as response:
470 assert not response.is_closed
471 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
472
473 rule = await response.parse()
474 assert_matches_type(BetaFederationRule, rule, path=["response"])
475
476 assert cast(Any, response.is_closed) is True
477
478 @parametrize
479 async def test_path_params_update(self, async_client: AsyncAnthropic) -> None:
480 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
481 await async_client.beta.organization.federation.rules.with_raw_response.update(
482 federation_rule_id="",
483 )
484
485 @parametrize
486 async def test_method_list(self, async_client: AsyncAnthropic) -> None:
487 rule = await async_client.beta.organization.federation.rules.list()
488 assert_matches_type(AsyncPageCursor[BetaFederationRule], rule, path=["response"])
489
490 @parametrize
491 async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None:
492 rule = await async_client.beta.organization.federation.rules.list(
493 include_archived=True,
494 issuer_id="issuer_id",
495 limit=1,
496 page="page",
497 betas=["message-batches-2024-09-24"],
498 )
499 assert_matches_type(AsyncPageCursor[BetaFederationRule], rule, path=["response"])
500
501 @parametrize
502 async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None:
503 response = await async_client.beta.organization.federation.rules.with_raw_response.list()
504
505 assert response.is_closed is True
506 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
507 rule = await response.parse()
508 assert_matches_type(AsyncPageCursor[BetaFederationRule], rule, path=["response"])
509
510 @parametrize
511 async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None:
512 async with async_client.beta.organization.federation.rules.with_streaming_response.list() as response:
513 assert not response.is_closed
514 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
515
516 rule = await response.parse()
517 assert_matches_type(AsyncPageCursor[BetaFederationRule], rule, path=["response"])
518
519 assert cast(Any, response.is_closed) is True
520
521 @parametrize
522 async def test_method_archive(self, async_client: AsyncAnthropic) -> None:
523 rule = await async_client.beta.organization.federation.rules.archive(
524 federation_rule_id="federation_rule_id",
525 )
526 assert_matches_type(BetaFederationRule, rule, path=["response"])
527
528 @parametrize
529 async def test_method_archive_with_all_params(self, async_client: AsyncAnthropic) -> None:
530 rule = await async_client.beta.organization.federation.rules.archive(
531 federation_rule_id="federation_rule_id",
532 betas=["message-batches-2024-09-24"],
533 )
534 assert_matches_type(BetaFederationRule, rule, path=["response"])
535
536 @parametrize
537 async def test_raw_response_archive(self, async_client: AsyncAnthropic) -> None:
538 response = await async_client.beta.organization.federation.rules.with_raw_response.archive(
539 federation_rule_id="federation_rule_id",
540 )
541
542 assert response.is_closed is True
543 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
544 rule = await response.parse()
545 assert_matches_type(BetaFederationRule, rule, path=["response"])
546
547 @parametrize
548 async def test_streaming_response_archive(self, async_client: AsyncAnthropic) -> None:
549 async with async_client.beta.organization.federation.rules.with_streaming_response.archive(
550 federation_rule_id="federation_rule_id",
551 ) as response:
552 assert not response.is_closed
553 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
554
555 rule = await response.parse()
556 assert_matches_type(BetaFederationRule, rule, path=["response"])
557
558 assert cast(Any, response.is_closed) is True
559
560 @parametrize
561 async def test_path_params_archive(self, async_client: AsyncAnthropic) -> None:
562 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
563 await async_client.beta.organization.federation.rules.with_raw_response.archive(
564 federation_rule_id="",
565 )