Debian Codegraph @

tests/api_resources/beta/test_sessions.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._utils import parse_datetime
11 from anthropic.pagination import SyncBidirectionalPageCursor, AsyncBidirectionalPageCursor
12 from anthropic.types.beta import (
13 BetaManagedAgentsSession,
14 BetaManagedAgentsDeletedSession,
15 )
16
17 base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20 class TestSessions:
21 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
22
23 @parametrize
24 def test_method_create(self, client: Anthropic) -> None:
25 session = client.beta.sessions.create(
26 agent="agent_011CZkYpogX7uDKUyvBTophP",
27 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
28 )
29 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
30
31 @parametrize
32 def test_method_create_with_all_params(self, client: Anthropic) -> None:
33 session = client.beta.sessions.create(
34 agent="agent_011CZkYpogX7uDKUyvBTophP",
35 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
36 budget={
37 "max_list_cost": {
38 "amount": "2500",
39 "currency": "USD",
40 },
41 "type": "limit",
42 },
43 initial_events=[
44 {
45 "content": [
46 {
47 "text": "Where is my order #1234?",
48 "type": "text",
49 }
50 ],
51 "type": "user.message",
52 }
53 ],
54 metadata={"foo": "string"},
55 resources=[
56 {
57 "file_id": "file_011CNha8iCJcU1wXNR6q4V8w",
58 "type": "file",
59 "mount_path": "/uploads/receipt.pdf",
60 }
61 ],
62 title="Order #1234 inquiry",
63 vault_ids=["string"],
64 betas=["message-batches-2024-09-24"],
65 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
66 )
67 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
68
69 @parametrize
70 def test_raw_response_create(self, client: Anthropic) -> None:
71 response = client.beta.sessions.with_raw_response.create(
72 agent="agent_011CZkYpogX7uDKUyvBTophP",
73 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
74 )
75
76 assert response.is_closed is True
77 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
78 session = response.parse()
79 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
80
81 @parametrize
82 def test_streaming_response_create(self, client: Anthropic) -> None:
83 with client.beta.sessions.with_streaming_response.create(
84 agent="agent_011CZkYpogX7uDKUyvBTophP",
85 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
86 ) as response:
87 assert not response.is_closed
88 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
89
90 session = response.parse()
91 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
92
93 assert cast(Any, response.is_closed) is True
94
95 @parametrize
96 def test_method_retrieve(self, client: Anthropic) -> None:
97 session = client.beta.sessions.retrieve(
98 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
99 )
100 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
101
102 @parametrize
103 def test_method_retrieve_with_all_params(self, client: Anthropic) -> None:
104 session = client.beta.sessions.retrieve(
105 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
106 betas=["message-batches-2024-09-24"],
107 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
108 )
109 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
110
111 @parametrize
112 def test_raw_response_retrieve(self, client: Anthropic) -> None:
113 response = client.beta.sessions.with_raw_response.retrieve(
114 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
115 )
116
117 assert response.is_closed is True
118 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
119 session = response.parse()
120 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
121
122 @parametrize
123 def test_streaming_response_retrieve(self, client: Anthropic) -> None:
124 with client.beta.sessions.with_streaming_response.retrieve(
125 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
126 ) as response:
127 assert not response.is_closed
128 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
129
130 session = response.parse()
131 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
132
133 assert cast(Any, response.is_closed) is True
134
135 @parametrize
136 def test_path_params_retrieve(self, client: Anthropic) -> None:
137 with pytest.raises(ValueError, match=r"Expected a non-empty value for `session_id` but received ''"):
138 client.beta.sessions.with_raw_response.retrieve(
139 session_id="",
140 )
141
142 @parametrize
143 def test_method_update(self, client: Anthropic) -> None:
144 session = client.beta.sessions.update(
145 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
146 )
147 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
148
149 @parametrize
150 def test_method_update_with_all_params(self, client: Anthropic) -> None:
151 session = client.beta.sessions.update(
152 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
153 agent={
154 "mcp_servers": [
155 {
156 "name": "example-mcp",
157 "type": "url",
158 "url": "https://example-server.modelcontextprotocol.io/sse",
159 }
160 ],
161 "tools": [
162 {
163 "type": "agent_toolset_20260401",
164 "configs": [
165 {
166 "name": "bash",
167 "enabled": True,
168 "permission_policy": {"type": "always_allow"},
169 "type": "bash",
170 }
171 ],
172 "default_config": {
173 "enabled": True,
174 "permission_policy": {"type": "always_allow"},
175 },
176 }
177 ],
178 },
179 budget={
180 "max_list_cost": {
181 "amount": "2500",
182 "currency": "USD",
183 },
184 "type": "limit",
185 },
186 metadata={"foo": "string"},
187 title="Order #1234 inquiry",
188 vault_ids=["string"],
189 betas=["message-batches-2024-09-24"],
190 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
191 )
192 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
193
194 @parametrize
195 def test_raw_response_update(self, client: Anthropic) -> None:
196 response = client.beta.sessions.with_raw_response.update(
197 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
198 )
199
200 assert response.is_closed is True
201 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
202 session = response.parse()
203 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
204
205 @parametrize
206 def test_streaming_response_update(self, client: Anthropic) -> None:
207 with client.beta.sessions.with_streaming_response.update(
208 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
209 ) as response:
210 assert not response.is_closed
211 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
212
213 session = response.parse()
214 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
215
216 assert cast(Any, response.is_closed) is True
217
218 @parametrize
219 def test_path_params_update(self, client: Anthropic) -> None:
220 with pytest.raises(ValueError, match=r"Expected a non-empty value for `session_id` but received ''"):
221 client.beta.sessions.with_raw_response.update(
222 session_id="",
223 )
224
225 @pytest.mark.skip(reason="buildURL drops path-level query params")
226 @parametrize
227 def test_method_list(self, client: Anthropic) -> None:
228 session = client.beta.sessions.list()
229 assert_matches_type(SyncBidirectionalPageCursor[BetaManagedAgentsSession], session, path=["response"])
230
231 @pytest.mark.skip(reason="buildURL drops path-level query params")
232 @parametrize
233 def test_method_list_with_all_params(self, client: Anthropic) -> None:
234 session = client.beta.sessions.list(
235 agent_id="agent_id",
236 agent_version=0,
237 created_at_gt=parse_datetime("2019-12-27T18:11:19.117Z"),
238 created_at_gte=parse_datetime("2019-12-27T18:11:19.117Z"),
239 created_at_lt=parse_datetime("2019-12-27T18:11:19.117Z"),
240 created_at_lte=parse_datetime("2019-12-27T18:11:19.117Z"),
241 deployment_id="deployment_id",
242 include_archived=True,
243 limit=0,
244 memory_store_id="memory_store_id",
245 order="asc",
246 page="page",
247 statuses=["rescheduling"],
248 betas=["message-batches-2024-09-24"],
249 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
250 )
251 assert_matches_type(SyncBidirectionalPageCursor[BetaManagedAgentsSession], session, path=["response"])
252
253 @pytest.mark.skip(reason="buildURL drops path-level query params")
254 @parametrize
255 def test_raw_response_list(self, client: Anthropic) -> None:
256 response = client.beta.sessions.with_raw_response.list()
257
258 assert response.is_closed is True
259 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
260 session = response.parse()
261 assert_matches_type(SyncBidirectionalPageCursor[BetaManagedAgentsSession], session, path=["response"])
262
263 @pytest.mark.skip(reason="buildURL drops path-level query params")
264 @parametrize
265 def test_streaming_response_list(self, client: Anthropic) -> None:
266 with client.beta.sessions.with_streaming_response.list() as response:
267 assert not response.is_closed
268 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
269
270 session = response.parse()
271 assert_matches_type(SyncBidirectionalPageCursor[BetaManagedAgentsSession], session, path=["response"])
272
273 assert cast(Any, response.is_closed) is True
274
275 @parametrize
276 def test_method_delete(self, client: Anthropic) -> None:
277 session = client.beta.sessions.delete(
278 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
279 )
280 assert_matches_type(BetaManagedAgentsDeletedSession, session, path=["response"])
281
282 @parametrize
283 def test_method_delete_with_all_params(self, client: Anthropic) -> None:
284 session = client.beta.sessions.delete(
285 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
286 betas=["message-batches-2024-09-24"],
287 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
288 )
289 assert_matches_type(BetaManagedAgentsDeletedSession, session, path=["response"])
290
291 @parametrize
292 def test_raw_response_delete(self, client: Anthropic) -> None:
293 response = client.beta.sessions.with_raw_response.delete(
294 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
295 )
296
297 assert response.is_closed is True
298 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
299 session = response.parse()
300 assert_matches_type(BetaManagedAgentsDeletedSession, session, path=["response"])
301
302 @parametrize
303 def test_streaming_response_delete(self, client: Anthropic) -> None:
304 with client.beta.sessions.with_streaming_response.delete(
305 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
306 ) as response:
307 assert not response.is_closed
308 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
309
310 session = response.parse()
311 assert_matches_type(BetaManagedAgentsDeletedSession, session, path=["response"])
312
313 assert cast(Any, response.is_closed) is True
314
315 @parametrize
316 def test_path_params_delete(self, client: Anthropic) -> None:
317 with pytest.raises(ValueError, match=r"Expected a non-empty value for `session_id` but received ''"):
318 client.beta.sessions.with_raw_response.delete(
319 session_id="",
320 )
321
322 @parametrize
323 def test_method_archive(self, client: Anthropic) -> None:
324 session = client.beta.sessions.archive(
325 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
326 )
327 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
328
329 @parametrize
330 def test_method_archive_with_all_params(self, client: Anthropic) -> None:
331 session = client.beta.sessions.archive(
332 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
333 betas=["message-batches-2024-09-24"],
334 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
335 )
336 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
337
338 @parametrize
339 def test_raw_response_archive(self, client: Anthropic) -> None:
340 response = client.beta.sessions.with_raw_response.archive(
341 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
342 )
343
344 assert response.is_closed is True
345 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
346 session = response.parse()
347 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
348
349 @parametrize
350 def test_streaming_response_archive(self, client: Anthropic) -> None:
351 with client.beta.sessions.with_streaming_response.archive(
352 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
353 ) as response:
354 assert not response.is_closed
355 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
356
357 session = response.parse()
358 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
359
360 assert cast(Any, response.is_closed) is True
361
362 @parametrize
363 def test_path_params_archive(self, client: Anthropic) -> None:
364 with pytest.raises(ValueError, match=r"Expected a non-empty value for `session_id` but received ''"):
365 client.beta.sessions.with_raw_response.archive(
366 session_id="",
367 )
368
369
370 class TestAsyncSessions:
371 parametrize = pytest.mark.parametrize(
372 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
373 )
374
375 @parametrize
376 async def test_method_create(self, async_client: AsyncAnthropic) -> None:
377 session = await async_client.beta.sessions.create(
378 agent="agent_011CZkYpogX7uDKUyvBTophP",
379 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
380 )
381 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
382
383 @parametrize
384 async def test_method_create_with_all_params(self, async_client: AsyncAnthropic) -> None:
385 session = await async_client.beta.sessions.create(
386 agent="agent_011CZkYpogX7uDKUyvBTophP",
387 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
388 budget={
389 "max_list_cost": {
390 "amount": "2500",
391 "currency": "USD",
392 },
393 "type": "limit",
394 },
395 initial_events=[
396 {
397 "content": [
398 {
399 "text": "Where is my order #1234?",
400 "type": "text",
401 }
402 ],
403 "type": "user.message",
404 }
405 ],
406 metadata={"foo": "string"},
407 resources=[
408 {
409 "file_id": "file_011CNha8iCJcU1wXNR6q4V8w",
410 "type": "file",
411 "mount_path": "/uploads/receipt.pdf",
412 }
413 ],
414 title="Order #1234 inquiry",
415 vault_ids=["string"],
416 betas=["message-batches-2024-09-24"],
417 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
418 )
419 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
420
421 @parametrize
422 async def test_raw_response_create(self, async_client: AsyncAnthropic) -> None:
423 response = await async_client.beta.sessions.with_raw_response.create(
424 agent="agent_011CZkYpogX7uDKUyvBTophP",
425 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
426 )
427
428 assert response.is_closed is True
429 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
430 session = await response.parse()
431 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
432
433 @parametrize
434 async def test_streaming_response_create(self, async_client: AsyncAnthropic) -> None:
435 async with async_client.beta.sessions.with_streaming_response.create(
436 agent="agent_011CZkYpogX7uDKUyvBTophP",
437 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
438 ) as response:
439 assert not response.is_closed
440 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
441
442 session = await response.parse()
443 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
444
445 assert cast(Any, response.is_closed) is True
446
447 @parametrize
448 async def test_method_retrieve(self, async_client: AsyncAnthropic) -> None:
449 session = await async_client.beta.sessions.retrieve(
450 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
451 )
452 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
453
454 @parametrize
455 async def test_method_retrieve_with_all_params(self, async_client: AsyncAnthropic) -> None:
456 session = await async_client.beta.sessions.retrieve(
457 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
458 betas=["message-batches-2024-09-24"],
459 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
460 )
461 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
462
463 @parametrize
464 async def test_raw_response_retrieve(self, async_client: AsyncAnthropic) -> None:
465 response = await async_client.beta.sessions.with_raw_response.retrieve(
466 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
467 )
468
469 assert response.is_closed is True
470 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
471 session = await response.parse()
472 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
473
474 @parametrize
475 async def test_streaming_response_retrieve(self, async_client: AsyncAnthropic) -> None:
476 async with async_client.beta.sessions.with_streaming_response.retrieve(
477 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
478 ) as response:
479 assert not response.is_closed
480 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
481
482 session = await response.parse()
483 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
484
485 assert cast(Any, response.is_closed) is True
486
487 @parametrize
488 async def test_path_params_retrieve(self, async_client: AsyncAnthropic) -> None:
489 with pytest.raises(ValueError, match=r"Expected a non-empty value for `session_id` but received ''"):
490 await async_client.beta.sessions.with_raw_response.retrieve(
491 session_id="",
492 )
493
494 @parametrize
495 async def test_method_update(self, async_client: AsyncAnthropic) -> None:
496 session = await async_client.beta.sessions.update(
497 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
498 )
499 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
500
501 @parametrize
502 async def test_method_update_with_all_params(self, async_client: AsyncAnthropic) -> None:
503 session = await async_client.beta.sessions.update(
504 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
505 agent={
506 "mcp_servers": [
507 {
508 "name": "example-mcp",
509 "type": "url",
510 "url": "https://example-server.modelcontextprotocol.io/sse",
511 }
512 ],
513 "tools": [
514 {
515 "type": "agent_toolset_20260401",
516 "configs": [
517 {
518 "name": "bash",
519 "enabled": True,
520 "permission_policy": {"type": "always_allow"},
521 "type": "bash",
522 }
523 ],
524 "default_config": {
525 "enabled": True,
526 "permission_policy": {"type": "always_allow"},
527 },
528 }
529 ],
530 },
531 budget={
532 "max_list_cost": {
533 "amount": "2500",
534 "currency": "USD",
535 },
536 "type": "limit",
537 },
538 metadata={"foo": "string"},
539 title="Order #1234 inquiry",
540 vault_ids=["string"],
541 betas=["message-batches-2024-09-24"],
542 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
543 )
544 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
545
546 @parametrize
547 async def test_raw_response_update(self, async_client: AsyncAnthropic) -> None:
548 response = await async_client.beta.sessions.with_raw_response.update(
549 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
550 )
551
552 assert response.is_closed is True
553 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
554 session = await response.parse()
555 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
556
557 @parametrize
558 async def test_streaming_response_update(self, async_client: AsyncAnthropic) -> None:
559 async with async_client.beta.sessions.with_streaming_response.update(
560 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
561 ) as response:
562 assert not response.is_closed
563 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
564
565 session = await response.parse()
566 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
567
568 assert cast(Any, response.is_closed) is True
569
570 @parametrize
571 async def test_path_params_update(self, async_client: AsyncAnthropic) -> None:
572 with pytest.raises(ValueError, match=r"Expected a non-empty value for `session_id` but received ''"):
573 await async_client.beta.sessions.with_raw_response.update(
574 session_id="",
575 )
576
577 @pytest.mark.skip(reason="buildURL drops path-level query params")
578 @parametrize
579 async def test_method_list(self, async_client: AsyncAnthropic) -> None:
580 session = await async_client.beta.sessions.list()
581 assert_matches_type(AsyncBidirectionalPageCursor[BetaManagedAgentsSession], session, path=["response"])
582
583 @pytest.mark.skip(reason="buildURL drops path-level query params")
584 @parametrize
585 async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None:
586 session = await async_client.beta.sessions.list(
587 agent_id="agent_id",
588 agent_version=0,
589 created_at_gt=parse_datetime("2019-12-27T18:11:19.117Z"),
590 created_at_gte=parse_datetime("2019-12-27T18:11:19.117Z"),
591 created_at_lt=parse_datetime("2019-12-27T18:11:19.117Z"),
592 created_at_lte=parse_datetime("2019-12-27T18:11:19.117Z"),
593 deployment_id="deployment_id",
594 include_archived=True,
595 limit=0,
596 memory_store_id="memory_store_id",
597 order="asc",
598 page="page",
599 statuses=["rescheduling"],
600 betas=["message-batches-2024-09-24"],
601 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
602 )
603 assert_matches_type(AsyncBidirectionalPageCursor[BetaManagedAgentsSession], session, path=["response"])
604
605 @pytest.mark.skip(reason="buildURL drops path-level query params")
606 @parametrize
607 async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None:
608 response = await async_client.beta.sessions.with_raw_response.list()
609
610 assert response.is_closed is True
611 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
612 session = await response.parse()
613 assert_matches_type(AsyncBidirectionalPageCursor[BetaManagedAgentsSession], session, path=["response"])
614
615 @pytest.mark.skip(reason="buildURL drops path-level query params")
616 @parametrize
617 async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None:
618 async with async_client.beta.sessions.with_streaming_response.list() as response:
619 assert not response.is_closed
620 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
621
622 session = await response.parse()
623 assert_matches_type(AsyncBidirectionalPageCursor[BetaManagedAgentsSession], session, path=["response"])
624
625 assert cast(Any, response.is_closed) is True
626
627 @parametrize
628 async def test_method_delete(self, async_client: AsyncAnthropic) -> None:
629 session = await async_client.beta.sessions.delete(
630 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
631 )
632 assert_matches_type(BetaManagedAgentsDeletedSession, session, path=["response"])
633
634 @parametrize
635 async def test_method_delete_with_all_params(self, async_client: AsyncAnthropic) -> None:
636 session = await async_client.beta.sessions.delete(
637 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
638 betas=["message-batches-2024-09-24"],
639 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
640 )
641 assert_matches_type(BetaManagedAgentsDeletedSession, session, path=["response"])
642
643 @parametrize
644 async def test_raw_response_delete(self, async_client: AsyncAnthropic) -> None:
645 response = await async_client.beta.sessions.with_raw_response.delete(
646 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
647 )
648
649 assert response.is_closed is True
650 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
651 session = await response.parse()
652 assert_matches_type(BetaManagedAgentsDeletedSession, session, path=["response"])
653
654 @parametrize
655 async def test_streaming_response_delete(self, async_client: AsyncAnthropic) -> None:
656 async with async_client.beta.sessions.with_streaming_response.delete(
657 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
658 ) as response:
659 assert not response.is_closed
660 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
661
662 session = await response.parse()
663 assert_matches_type(BetaManagedAgentsDeletedSession, session, path=["response"])
664
665 assert cast(Any, response.is_closed) is True
666
667 @parametrize
668 async def test_path_params_delete(self, async_client: AsyncAnthropic) -> None:
669 with pytest.raises(ValueError, match=r"Expected a non-empty value for `session_id` but received ''"):
670 await async_client.beta.sessions.with_raw_response.delete(
671 session_id="",
672 )
673
674 @parametrize
675 async def test_method_archive(self, async_client: AsyncAnthropic) -> None:
676 session = await async_client.beta.sessions.archive(
677 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
678 )
679 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
680
681 @parametrize
682 async def test_method_archive_with_all_params(self, async_client: AsyncAnthropic) -> None:
683 session = await async_client.beta.sessions.archive(
684 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
685 betas=["message-batches-2024-09-24"],
686 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
687 )
688 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
689
690 @parametrize
691 async def test_raw_response_archive(self, async_client: AsyncAnthropic) -> None:
692 response = await async_client.beta.sessions.with_raw_response.archive(
693 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
694 )
695
696 assert response.is_closed is True
697 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
698 session = await response.parse()
699 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
700
701 @parametrize
702 async def test_streaming_response_archive(self, async_client: AsyncAnthropic) -> None:
703 async with async_client.beta.sessions.with_streaming_response.archive(
704 session_id="sesn_011CZkZAtmR3yMPDzynEDxu7",
705 ) as response:
706 assert not response.is_closed
707 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
708
709 session = await response.parse()
710 assert_matches_type(BetaManagedAgentsSession, session, path=["response"])
711
712 assert cast(Any, response.is_closed) is True
713
714 @parametrize
715 async def test_path_params_archive(self, async_client: AsyncAnthropic) -> None:
716 with pytest.raises(ValueError, match=r"Expected a non-empty value for `session_id` but received ''"):
717 await async_client.beta.sessions.with_raw_response.archive(
718 session_id="",
719 )