Debian Codegraph @

tests/api_resources/beta/environments/test_work.py

raw
1 from __future__ import annotations
2
3 import os
4 from typing import Any, Optional, 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.environments import (
12 BetaSelfHostedWork,
13 BetaSelfHostedWorkQueueStats,
14 BetaSelfHostedWorkHeartbeatResponse,
15 )
16
17 base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20 class TestWork:
21 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
22
23 @parametrize
24 def test_method_retrieve(self, client: Anthropic) -> None:
25 work = client.beta.environments.work.retrieve(
26 work_id="work_id",
27 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
28 )
29 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
30
31 @parametrize
32 def test_method_retrieve_with_all_params(self, client: Anthropic) -> None:
33 work = client.beta.environments.work.retrieve(
34 work_id="work_id",
35 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
36 betas=["message-batches-2024-09-24"],
37 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
38 )
39 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
40
41 @parametrize
42 def test_raw_response_retrieve(self, client: Anthropic) -> None:
43 response = client.beta.environments.work.with_raw_response.retrieve(
44 work_id="work_id",
45 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
46 )
47
48 assert response.is_closed is True
49 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
50 work = response.parse()
51 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
52
53 @parametrize
54 def test_streaming_response_retrieve(self, client: Anthropic) -> None:
55 with client.beta.environments.work.with_streaming_response.retrieve(
56 work_id="work_id",
57 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
58 ) as response:
59 assert not response.is_closed
60 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
61
62 work = response.parse()
63 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
64
65 assert cast(Any, response.is_closed) is True
66
67 @parametrize
68 def test_path_params_retrieve(self, client: Anthropic) -> None:
69 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
70 client.beta.environments.work.with_raw_response.retrieve(
71 work_id="work_id",
72 environment_id="",
73 )
74
75 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
76 client.beta.environments.work.with_raw_response.retrieve(
77 work_id="",
78 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
79 )
80
81 @parametrize
82 def test_method_update(self, client: Anthropic) -> None:
83 work = client.beta.environments.work.update(
84 work_id="work_id",
85 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
86 metadata={"foo": "string"},
87 )
88 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
89
90 @parametrize
91 def test_method_update_with_all_params(self, client: Anthropic) -> None:
92 work = client.beta.environments.work.update(
93 work_id="work_id",
94 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
95 metadata={"foo": "string"},
96 betas=["message-batches-2024-09-24"],
97 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
98 )
99 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
100
101 @parametrize
102 def test_raw_response_update(self, client: Anthropic) -> None:
103 response = client.beta.environments.work.with_raw_response.update(
104 work_id="work_id",
105 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
106 metadata={"foo": "string"},
107 )
108
109 assert response.is_closed is True
110 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
111 work = response.parse()
112 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
113
114 @parametrize
115 def test_streaming_response_update(self, client: Anthropic) -> None:
116 with client.beta.environments.work.with_streaming_response.update(
117 work_id="work_id",
118 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
119 metadata={"foo": "string"},
120 ) as response:
121 assert not response.is_closed
122 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
123
124 work = response.parse()
125 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
126
127 assert cast(Any, response.is_closed) is True
128
129 @parametrize
130 def test_path_params_update(self, client: Anthropic) -> None:
131 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
132 client.beta.environments.work.with_raw_response.update(
133 work_id="work_id",
134 environment_id="",
135 metadata={"foo": "string"},
136 )
137
138 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
139 client.beta.environments.work.with_raw_response.update(
140 work_id="",
141 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
142 metadata={"foo": "string"},
143 )
144
145 @pytest.mark.skip(reason="buildURL drops path-level query params")
146 @parametrize
147 def test_method_list(self, client: Anthropic) -> None:
148 work = client.beta.environments.work.list(
149 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
150 )
151 assert_matches_type(SyncPageCursor[BetaSelfHostedWork], work, path=["response"])
152
153 @pytest.mark.skip(reason="buildURL drops path-level query params")
154 @parametrize
155 def test_method_list_with_all_params(self, client: Anthropic) -> None:
156 work = client.beta.environments.work.list(
157 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
158 limit=1,
159 page="page",
160 betas=["message-batches-2024-09-24"],
161 )
162 assert_matches_type(SyncPageCursor[BetaSelfHostedWork], work, path=["response"])
163
164 @pytest.mark.skip(reason="buildURL drops path-level query params")
165 @parametrize
166 def test_raw_response_list(self, client: Anthropic) -> None:
167 response = client.beta.environments.work.with_raw_response.list(
168 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
169 )
170
171 assert response.is_closed is True
172 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
173 work = response.parse()
174 assert_matches_type(SyncPageCursor[BetaSelfHostedWork], work, path=["response"])
175
176 @pytest.mark.skip(reason="buildURL drops path-level query params")
177 @parametrize
178 def test_streaming_response_list(self, client: Anthropic) -> None:
179 with client.beta.environments.work.with_streaming_response.list(
180 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
181 ) as response:
182 assert not response.is_closed
183 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
184
185 work = response.parse()
186 assert_matches_type(SyncPageCursor[BetaSelfHostedWork], work, path=["response"])
187
188 assert cast(Any, response.is_closed) is True
189
190 @pytest.mark.skip(reason="buildURL drops path-level query params")
191 @parametrize
192 def test_path_params_list(self, client: Anthropic) -> None:
193 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
194 client.beta.environments.work.with_raw_response.list(
195 environment_id="",
196 )
197
198 @parametrize
199 def test_method_ack(self, client: Anthropic) -> None:
200 work = client.beta.environments.work.ack(
201 work_id="work_id",
202 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
203 )
204 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
205
206 @parametrize
207 def test_method_ack_with_all_params(self, client: Anthropic) -> None:
208 work = client.beta.environments.work.ack(
209 work_id="work_id",
210 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
211 betas=["message-batches-2024-09-24"],
212 )
213 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
214
215 @parametrize
216 def test_raw_response_ack(self, client: Anthropic) -> None:
217 response = client.beta.environments.work.with_raw_response.ack(
218 work_id="work_id",
219 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
220 )
221
222 assert response.is_closed is True
223 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
224 work = response.parse()
225 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
226
227 @parametrize
228 def test_streaming_response_ack(self, client: Anthropic) -> None:
229 with client.beta.environments.work.with_streaming_response.ack(
230 work_id="work_id",
231 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
232 ) as response:
233 assert not response.is_closed
234 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
235
236 work = response.parse()
237 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
238
239 assert cast(Any, response.is_closed) is True
240
241 @parametrize
242 def test_path_params_ack(self, client: Anthropic) -> None:
243 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
244 client.beta.environments.work.with_raw_response.ack(
245 work_id="work_id",
246 environment_id="",
247 )
248
249 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
250 client.beta.environments.work.with_raw_response.ack(
251 work_id="",
252 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
253 )
254
255 @parametrize
256 def test_method_heartbeat(self, client: Anthropic) -> None:
257 work = client.beta.environments.work.heartbeat(
258 work_id="work_id",
259 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
260 )
261 assert_matches_type(BetaSelfHostedWorkHeartbeatResponse, work, path=["response"])
262
263 @parametrize
264 def test_method_heartbeat_with_all_params(self, client: Anthropic) -> None:
265 work = client.beta.environments.work.heartbeat(
266 work_id="work_id",
267 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
268 desired_ttl_seconds=0,
269 expected_last_heartbeat="expected_last_heartbeat",
270 betas=["message-batches-2024-09-24"],
271 )
272 assert_matches_type(BetaSelfHostedWorkHeartbeatResponse, work, path=["response"])
273
274 @parametrize
275 def test_raw_response_heartbeat(self, client: Anthropic) -> None:
276 response = client.beta.environments.work.with_raw_response.heartbeat(
277 work_id="work_id",
278 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
279 )
280
281 assert response.is_closed is True
282 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
283 work = response.parse()
284 assert_matches_type(BetaSelfHostedWorkHeartbeatResponse, work, path=["response"])
285
286 @parametrize
287 def test_streaming_response_heartbeat(self, client: Anthropic) -> None:
288 with client.beta.environments.work.with_streaming_response.heartbeat(
289 work_id="work_id",
290 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
291 ) as response:
292 assert not response.is_closed
293 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
294
295 work = response.parse()
296 assert_matches_type(BetaSelfHostedWorkHeartbeatResponse, work, path=["response"])
297
298 assert cast(Any, response.is_closed) is True
299
300 @parametrize
301 def test_path_params_heartbeat(self, client: Anthropic) -> None:
302 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
303 client.beta.environments.work.with_raw_response.heartbeat(
304 work_id="work_id",
305 environment_id="",
306 )
307
308 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
309 client.beta.environments.work.with_raw_response.heartbeat(
310 work_id="",
311 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
312 )
313
314 @parametrize
315 def test_method_poll(self, client: Anthropic) -> None:
316 work = client.beta.environments.work.poll(
317 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
318 )
319 assert_matches_type(Optional[BetaSelfHostedWork], work, path=["response"])
320
321 @parametrize
322 def test_method_poll_with_all_params(self, client: Anthropic) -> None:
323 work = client.beta.environments.work.poll(
324 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
325 block_ms=1,
326 reclaim_older_than_ms=1,
327 betas=["message-batches-2024-09-24"],
328 anthropic_worker_id="Anthropic-Worker-ID",
329 )
330 assert_matches_type(Optional[BetaSelfHostedWork], work, path=["response"])
331
332 @parametrize
333 def test_raw_response_poll(self, client: Anthropic) -> None:
334 response = client.beta.environments.work.with_raw_response.poll(
335 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
336 )
337
338 assert response.is_closed is True
339 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
340 work = response.parse()
341 assert_matches_type(Optional[BetaSelfHostedWork], work, path=["response"])
342
343 @parametrize
344 def test_streaming_response_poll(self, client: Anthropic) -> None:
345 with client.beta.environments.work.with_streaming_response.poll(
346 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
347 ) as response:
348 assert not response.is_closed
349 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
350
351 work = response.parse()
352 assert_matches_type(Optional[BetaSelfHostedWork], work, path=["response"])
353
354 assert cast(Any, response.is_closed) is True
355
356 @parametrize
357 def test_path_params_poll(self, client: Anthropic) -> None:
358 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
359 client.beta.environments.work.with_raw_response.poll(
360 environment_id="",
361 )
362
363 @pytest.mark.skip(reason="buildURL drops path-level query params")
364 @parametrize
365 def test_method_stats(self, client: Anthropic) -> None:
366 work = client.beta.environments.work.stats(
367 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
368 )
369 assert_matches_type(BetaSelfHostedWorkQueueStats, work, path=["response"])
370
371 @pytest.mark.skip(reason="buildURL drops path-level query params")
372 @parametrize
373 def test_method_stats_with_all_params(self, client: Anthropic) -> None:
374 work = client.beta.environments.work.stats(
375 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
376 betas=["message-batches-2024-09-24"],
377 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
378 )
379 assert_matches_type(BetaSelfHostedWorkQueueStats, work, path=["response"])
380
381 @pytest.mark.skip(reason="buildURL drops path-level query params")
382 @parametrize
383 def test_raw_response_stats(self, client: Anthropic) -> None:
384 response = client.beta.environments.work.with_raw_response.stats(
385 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
386 )
387
388 assert response.is_closed is True
389 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
390 work = response.parse()
391 assert_matches_type(BetaSelfHostedWorkQueueStats, work, path=["response"])
392
393 @pytest.mark.skip(reason="buildURL drops path-level query params")
394 @parametrize
395 def test_streaming_response_stats(self, client: Anthropic) -> None:
396 with client.beta.environments.work.with_streaming_response.stats(
397 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
398 ) as response:
399 assert not response.is_closed
400 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
401
402 work = response.parse()
403 assert_matches_type(BetaSelfHostedWorkQueueStats, work, path=["response"])
404
405 assert cast(Any, response.is_closed) is True
406
407 @pytest.mark.skip(reason="buildURL drops path-level query params")
408 @parametrize
409 def test_path_params_stats(self, client: Anthropic) -> None:
410 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
411 client.beta.environments.work.with_raw_response.stats(
412 environment_id="",
413 )
414
415 @parametrize
416 def test_method_stop(self, client: Anthropic) -> None:
417 work = client.beta.environments.work.stop(
418 work_id="work_id",
419 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
420 )
421 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
422
423 @parametrize
424 def test_method_stop_with_all_params(self, client: Anthropic) -> None:
425 work = client.beta.environments.work.stop(
426 work_id="work_id",
427 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
428 force=True,
429 betas=["message-batches-2024-09-24"],
430 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
431 )
432 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
433
434 @parametrize
435 def test_raw_response_stop(self, client: Anthropic) -> None:
436 response = client.beta.environments.work.with_raw_response.stop(
437 work_id="work_id",
438 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
439 )
440
441 assert response.is_closed is True
442 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
443 work = response.parse()
444 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
445
446 @parametrize
447 def test_streaming_response_stop(self, client: Anthropic) -> None:
448 with client.beta.environments.work.with_streaming_response.stop(
449 work_id="work_id",
450 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
451 ) as response:
452 assert not response.is_closed
453 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
454
455 work = response.parse()
456 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
457
458 assert cast(Any, response.is_closed) is True
459
460 @parametrize
461 def test_path_params_stop(self, client: Anthropic) -> None:
462 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
463 client.beta.environments.work.with_raw_response.stop(
464 work_id="work_id",
465 environment_id="",
466 )
467
468 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
469 client.beta.environments.work.with_raw_response.stop(
470 work_id="",
471 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
472 )
473
474
475 class TestAsyncWork:
476 parametrize = pytest.mark.parametrize(
477 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
478 )
479
480 @parametrize
481 async def test_method_retrieve(self, async_client: AsyncAnthropic) -> None:
482 work = await async_client.beta.environments.work.retrieve(
483 work_id="work_id",
484 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
485 )
486 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
487
488 @parametrize
489 async def test_method_retrieve_with_all_params(self, async_client: AsyncAnthropic) -> None:
490 work = await async_client.beta.environments.work.retrieve(
491 work_id="work_id",
492 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
493 betas=["message-batches-2024-09-24"],
494 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
495 )
496 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
497
498 @parametrize
499 async def test_raw_response_retrieve(self, async_client: AsyncAnthropic) -> None:
500 response = await async_client.beta.environments.work.with_raw_response.retrieve(
501 work_id="work_id",
502 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
503 )
504
505 assert response.is_closed is True
506 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
507 work = await response.parse()
508 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
509
510 @parametrize
511 async def test_streaming_response_retrieve(self, async_client: AsyncAnthropic) -> None:
512 async with async_client.beta.environments.work.with_streaming_response.retrieve(
513 work_id="work_id",
514 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
515 ) as response:
516 assert not response.is_closed
517 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
518
519 work = await response.parse()
520 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
521
522 assert cast(Any, response.is_closed) is True
523
524 @parametrize
525 async def test_path_params_retrieve(self, async_client: AsyncAnthropic) -> None:
526 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
527 await async_client.beta.environments.work.with_raw_response.retrieve(
528 work_id="work_id",
529 environment_id="",
530 )
531
532 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
533 await async_client.beta.environments.work.with_raw_response.retrieve(
534 work_id="",
535 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
536 )
537
538 @parametrize
539 async def test_method_update(self, async_client: AsyncAnthropic) -> None:
540 work = await async_client.beta.environments.work.update(
541 work_id="work_id",
542 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
543 metadata={"foo": "string"},
544 )
545 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
546
547 @parametrize
548 async def test_method_update_with_all_params(self, async_client: AsyncAnthropic) -> None:
549 work = await async_client.beta.environments.work.update(
550 work_id="work_id",
551 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
552 metadata={"foo": "string"},
553 betas=["message-batches-2024-09-24"],
554 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
555 )
556 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
557
558 @parametrize
559 async def test_raw_response_update(self, async_client: AsyncAnthropic) -> None:
560 response = await async_client.beta.environments.work.with_raw_response.update(
561 work_id="work_id",
562 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
563 metadata={"foo": "string"},
564 )
565
566 assert response.is_closed is True
567 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
568 work = await response.parse()
569 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
570
571 @parametrize
572 async def test_streaming_response_update(self, async_client: AsyncAnthropic) -> None:
573 async with async_client.beta.environments.work.with_streaming_response.update(
574 work_id="work_id",
575 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
576 metadata={"foo": "string"},
577 ) as response:
578 assert not response.is_closed
579 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
580
581 work = await response.parse()
582 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
583
584 assert cast(Any, response.is_closed) is True
585
586 @parametrize
587 async def test_path_params_update(self, async_client: AsyncAnthropic) -> None:
588 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
589 await async_client.beta.environments.work.with_raw_response.update(
590 work_id="work_id",
591 environment_id="",
592 metadata={"foo": "string"},
593 )
594
595 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
596 await async_client.beta.environments.work.with_raw_response.update(
597 work_id="",
598 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
599 metadata={"foo": "string"},
600 )
601
602 @pytest.mark.skip(reason="buildURL drops path-level query params")
603 @parametrize
604 async def test_method_list(self, async_client: AsyncAnthropic) -> None:
605 work = await async_client.beta.environments.work.list(
606 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
607 )
608 assert_matches_type(AsyncPageCursor[BetaSelfHostedWork], work, path=["response"])
609
610 @pytest.mark.skip(reason="buildURL drops path-level query params")
611 @parametrize
612 async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None:
613 work = await async_client.beta.environments.work.list(
614 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
615 limit=1,
616 page="page",
617 betas=["message-batches-2024-09-24"],
618 )
619 assert_matches_type(AsyncPageCursor[BetaSelfHostedWork], work, path=["response"])
620
621 @pytest.mark.skip(reason="buildURL drops path-level query params")
622 @parametrize
623 async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None:
624 response = await async_client.beta.environments.work.with_raw_response.list(
625 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
626 )
627
628 assert response.is_closed is True
629 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
630 work = await response.parse()
631 assert_matches_type(AsyncPageCursor[BetaSelfHostedWork], work, path=["response"])
632
633 @pytest.mark.skip(reason="buildURL drops path-level query params")
634 @parametrize
635 async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None:
636 async with async_client.beta.environments.work.with_streaming_response.list(
637 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
638 ) as response:
639 assert not response.is_closed
640 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
641
642 work = await response.parse()
643 assert_matches_type(AsyncPageCursor[BetaSelfHostedWork], work, path=["response"])
644
645 assert cast(Any, response.is_closed) is True
646
647 @pytest.mark.skip(reason="buildURL drops path-level query params")
648 @parametrize
649 async def test_path_params_list(self, async_client: AsyncAnthropic) -> None:
650 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
651 await async_client.beta.environments.work.with_raw_response.list(
652 environment_id="",
653 )
654
655 @parametrize
656 async def test_method_ack(self, async_client: AsyncAnthropic) -> None:
657 work = await async_client.beta.environments.work.ack(
658 work_id="work_id",
659 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
660 )
661 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
662
663 @parametrize
664 async def test_method_ack_with_all_params(self, async_client: AsyncAnthropic) -> None:
665 work = await async_client.beta.environments.work.ack(
666 work_id="work_id",
667 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
668 betas=["message-batches-2024-09-24"],
669 )
670 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
671
672 @parametrize
673 async def test_raw_response_ack(self, async_client: AsyncAnthropic) -> None:
674 response = await async_client.beta.environments.work.with_raw_response.ack(
675 work_id="work_id",
676 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
677 )
678
679 assert response.is_closed is True
680 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
681 work = await response.parse()
682 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
683
684 @parametrize
685 async def test_streaming_response_ack(self, async_client: AsyncAnthropic) -> None:
686 async with async_client.beta.environments.work.with_streaming_response.ack(
687 work_id="work_id",
688 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
689 ) as response:
690 assert not response.is_closed
691 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
692
693 work = await response.parse()
694 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
695
696 assert cast(Any, response.is_closed) is True
697
698 @parametrize
699 async def test_path_params_ack(self, async_client: AsyncAnthropic) -> None:
700 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
701 await async_client.beta.environments.work.with_raw_response.ack(
702 work_id="work_id",
703 environment_id="",
704 )
705
706 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
707 await async_client.beta.environments.work.with_raw_response.ack(
708 work_id="",
709 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
710 )
711
712 @parametrize
713 async def test_method_heartbeat(self, async_client: AsyncAnthropic) -> None:
714 work = await async_client.beta.environments.work.heartbeat(
715 work_id="work_id",
716 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
717 )
718 assert_matches_type(BetaSelfHostedWorkHeartbeatResponse, work, path=["response"])
719
720 @parametrize
721 async def test_method_heartbeat_with_all_params(self, async_client: AsyncAnthropic) -> None:
722 work = await async_client.beta.environments.work.heartbeat(
723 work_id="work_id",
724 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
725 desired_ttl_seconds=0,
726 expected_last_heartbeat="expected_last_heartbeat",
727 betas=["message-batches-2024-09-24"],
728 )
729 assert_matches_type(BetaSelfHostedWorkHeartbeatResponse, work, path=["response"])
730
731 @parametrize
732 async def test_raw_response_heartbeat(self, async_client: AsyncAnthropic) -> None:
733 response = await async_client.beta.environments.work.with_raw_response.heartbeat(
734 work_id="work_id",
735 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
736 )
737
738 assert response.is_closed is True
739 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
740 work = await response.parse()
741 assert_matches_type(BetaSelfHostedWorkHeartbeatResponse, work, path=["response"])
742
743 @parametrize
744 async def test_streaming_response_heartbeat(self, async_client: AsyncAnthropic) -> None:
745 async with async_client.beta.environments.work.with_streaming_response.heartbeat(
746 work_id="work_id",
747 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
748 ) as response:
749 assert not response.is_closed
750 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
751
752 work = await response.parse()
753 assert_matches_type(BetaSelfHostedWorkHeartbeatResponse, work, path=["response"])
754
755 assert cast(Any, response.is_closed) is True
756
757 @parametrize
758 async def test_path_params_heartbeat(self, async_client: AsyncAnthropic) -> None:
759 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
760 await async_client.beta.environments.work.with_raw_response.heartbeat(
761 work_id="work_id",
762 environment_id="",
763 )
764
765 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
766 await async_client.beta.environments.work.with_raw_response.heartbeat(
767 work_id="",
768 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
769 )
770
771 @parametrize
772 async def test_method_poll(self, async_client: AsyncAnthropic) -> None:
773 work = await async_client.beta.environments.work.poll(
774 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
775 )
776 assert_matches_type(Optional[BetaSelfHostedWork], work, path=["response"])
777
778 @parametrize
779 async def test_method_poll_with_all_params(self, async_client: AsyncAnthropic) -> None:
780 work = await async_client.beta.environments.work.poll(
781 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
782 block_ms=1,
783 reclaim_older_than_ms=1,
784 betas=["message-batches-2024-09-24"],
785 anthropic_worker_id="Anthropic-Worker-ID",
786 )
787 assert_matches_type(Optional[BetaSelfHostedWork], work, path=["response"])
788
789 @parametrize
790 async def test_raw_response_poll(self, async_client: AsyncAnthropic) -> None:
791 response = await async_client.beta.environments.work.with_raw_response.poll(
792 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
793 )
794
795 assert response.is_closed is True
796 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
797 work = await response.parse()
798 assert_matches_type(Optional[BetaSelfHostedWork], work, path=["response"])
799
800 @parametrize
801 async def test_streaming_response_poll(self, async_client: AsyncAnthropic) -> None:
802 async with async_client.beta.environments.work.with_streaming_response.poll(
803 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
804 ) as response:
805 assert not response.is_closed
806 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
807
808 work = await response.parse()
809 assert_matches_type(Optional[BetaSelfHostedWork], work, path=["response"])
810
811 assert cast(Any, response.is_closed) is True
812
813 @parametrize
814 async def test_path_params_poll(self, async_client: AsyncAnthropic) -> None:
815 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
816 await async_client.beta.environments.work.with_raw_response.poll(
817 environment_id="",
818 )
819
820 @pytest.mark.skip(reason="buildURL drops path-level query params")
821 @parametrize
822 async def test_method_stats(self, async_client: AsyncAnthropic) -> None:
823 work = await async_client.beta.environments.work.stats(
824 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
825 )
826 assert_matches_type(BetaSelfHostedWorkQueueStats, work, path=["response"])
827
828 @pytest.mark.skip(reason="buildURL drops path-level query params")
829 @parametrize
830 async def test_method_stats_with_all_params(self, async_client: AsyncAnthropic) -> None:
831 work = await async_client.beta.environments.work.stats(
832 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
833 betas=["message-batches-2024-09-24"],
834 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
835 )
836 assert_matches_type(BetaSelfHostedWorkQueueStats, work, path=["response"])
837
838 @pytest.mark.skip(reason="buildURL drops path-level query params")
839 @parametrize
840 async def test_raw_response_stats(self, async_client: AsyncAnthropic) -> None:
841 response = await async_client.beta.environments.work.with_raw_response.stats(
842 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
843 )
844
845 assert response.is_closed is True
846 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
847 work = await response.parse()
848 assert_matches_type(BetaSelfHostedWorkQueueStats, work, path=["response"])
849
850 @pytest.mark.skip(reason="buildURL drops path-level query params")
851 @parametrize
852 async def test_streaming_response_stats(self, async_client: AsyncAnthropic) -> None:
853 async with async_client.beta.environments.work.with_streaming_response.stats(
854 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
855 ) as response:
856 assert not response.is_closed
857 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
858
859 work = await response.parse()
860 assert_matches_type(BetaSelfHostedWorkQueueStats, work, path=["response"])
861
862 assert cast(Any, response.is_closed) is True
863
864 @pytest.mark.skip(reason="buildURL drops path-level query params")
865 @parametrize
866 async def test_path_params_stats(self, async_client: AsyncAnthropic) -> None:
867 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
868 await async_client.beta.environments.work.with_raw_response.stats(
869 environment_id="",
870 )
871
872 @parametrize
873 async def test_method_stop(self, async_client: AsyncAnthropic) -> None:
874 work = await async_client.beta.environments.work.stop(
875 work_id="work_id",
876 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
877 )
878 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
879
880 @parametrize
881 async def test_method_stop_with_all_params(self, async_client: AsyncAnthropic) -> None:
882 work = await async_client.beta.environments.work.stop(
883 work_id="work_id",
884 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
885 force=True,
886 betas=["message-batches-2024-09-24"],
887 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
888 )
889 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
890
891 @parametrize
892 async def test_raw_response_stop(self, async_client: AsyncAnthropic) -> None:
893 response = await async_client.beta.environments.work.with_raw_response.stop(
894 work_id="work_id",
895 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
896 )
897
898 assert response.is_closed is True
899 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
900 work = await response.parse()
901 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
902
903 @parametrize
904 async def test_streaming_response_stop(self, async_client: AsyncAnthropic) -> None:
905 async with async_client.beta.environments.work.with_streaming_response.stop(
906 work_id="work_id",
907 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
908 ) as response:
909 assert not response.is_closed
910 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
911
912 work = await response.parse()
913 assert_matches_type(BetaSelfHostedWork, work, path=["response"])
914
915 assert cast(Any, response.is_closed) is True
916
917 @parametrize
918 async def test_path_params_stop(self, async_client: AsyncAnthropic) -> None:
919 with pytest.raises(ValueError, match=r"Expected a non-empty value for `environment_id` but received ''"):
920 await async_client.beta.environments.work.with_raw_response.stop(
921 work_id="work_id",
922 environment_id="",
923 )
924
925 with pytest.raises(ValueError, match=r"Expected a non-empty value for `work_id` but received ''"):
926 await async_client.beta.environments.work.with_raw_response.stop(
927 work_id="",
928 environment_id="env_011CZkZ9X2dpNyB7HsEFoRfW",
929 )