Debian Codegraph @

tests/api_resources/beta/test_deployment_runs.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 SyncPageCursor, AsyncPageCursor
12 from anthropic.types.beta import (
13 BetaManagedAgentsDeploymentRun,
14 )
15
16 base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
17
18
19 class TestDeploymentRuns:
20 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
21
22 @pytest.mark.skip(reason="buildURL drops path-level query params")
23 @parametrize
24 def test_method_retrieve(self, client: Anthropic) -> None:
25 deployment_run = client.beta.deployment_runs.retrieve(
26 deployment_run_id="deployment_run_id",
27 )
28 assert_matches_type(BetaManagedAgentsDeploymentRun, deployment_run, path=["response"])
29
30 @pytest.mark.skip(reason="buildURL drops path-level query params")
31 @parametrize
32 def test_method_retrieve_with_all_params(self, client: Anthropic) -> None:
33 deployment_run = client.beta.deployment_runs.retrieve(
34 deployment_run_id="deployment_run_id",
35 betas=["message-batches-2024-09-24"],
36 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
37 )
38 assert_matches_type(BetaManagedAgentsDeploymentRun, deployment_run, path=["response"])
39
40 @pytest.mark.skip(reason="buildURL drops path-level query params")
41 @parametrize
42 def test_raw_response_retrieve(self, client: Anthropic) -> None:
43 response = client.beta.deployment_runs.with_raw_response.retrieve(
44 deployment_run_id="deployment_run_id",
45 )
46
47 assert response.is_closed is True
48 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
49 deployment_run = response.parse()
50 assert_matches_type(BetaManagedAgentsDeploymentRun, deployment_run, path=["response"])
51
52 @pytest.mark.skip(reason="buildURL drops path-level query params")
53 @parametrize
54 def test_streaming_response_retrieve(self, client: Anthropic) -> None:
55 with client.beta.deployment_runs.with_streaming_response.retrieve(
56 deployment_run_id="deployment_run_id",
57 ) as response:
58 assert not response.is_closed
59 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
60
61 deployment_run = response.parse()
62 assert_matches_type(BetaManagedAgentsDeploymentRun, deployment_run, path=["response"])
63
64 assert cast(Any, response.is_closed) is True
65
66 @pytest.mark.skip(reason="buildURL drops path-level query params")
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 `deployment_run_id` but received ''"):
70 client.beta.deployment_runs.with_raw_response.retrieve(
71 deployment_run_id="",
72 )
73
74 @pytest.mark.skip(reason="buildURL drops path-level query params")
75 @parametrize
76 def test_method_list(self, client: Anthropic) -> None:
77 deployment_run = client.beta.deployment_runs.list()
78 assert_matches_type(SyncPageCursor[BetaManagedAgentsDeploymentRun], deployment_run, path=["response"])
79
80 @pytest.mark.skip(reason="buildURL drops path-level query params")
81 @parametrize
82 def test_method_list_with_all_params(self, client: Anthropic) -> None:
83 deployment_run = client.beta.deployment_runs.list(
84 created_at_gt=parse_datetime("2019-12-27T18:11:19.117Z"),
85 created_at_gte=parse_datetime("2019-12-27T18:11:19.117Z"),
86 created_at_lt=parse_datetime("2019-12-27T18:11:19.117Z"),
87 created_at_lte=parse_datetime("2019-12-27T18:11:19.117Z"),
88 deployment_id="deployment_id",
89 has_error=True,
90 limit=0,
91 page="page",
92 trigger_type="schedule",
93 betas=["message-batches-2024-09-24"],
94 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
95 )
96 assert_matches_type(SyncPageCursor[BetaManagedAgentsDeploymentRun], deployment_run, path=["response"])
97
98 @pytest.mark.skip(reason="buildURL drops path-level query params")
99 @parametrize
100 def test_raw_response_list(self, client: Anthropic) -> None:
101 response = client.beta.deployment_runs.with_raw_response.list()
102
103 assert response.is_closed is True
104 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
105 deployment_run = response.parse()
106 assert_matches_type(SyncPageCursor[BetaManagedAgentsDeploymentRun], deployment_run, path=["response"])
107
108 @pytest.mark.skip(reason="buildURL drops path-level query params")
109 @parametrize
110 def test_streaming_response_list(self, client: Anthropic) -> None:
111 with client.beta.deployment_runs.with_streaming_response.list() as response:
112 assert not response.is_closed
113 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
114
115 deployment_run = response.parse()
116 assert_matches_type(SyncPageCursor[BetaManagedAgentsDeploymentRun], deployment_run, path=["response"])
117
118 assert cast(Any, response.is_closed) is True
119
120
121 class TestAsyncDeploymentRuns:
122 parametrize = pytest.mark.parametrize(
123 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
124 )
125
126 @pytest.mark.skip(reason="buildURL drops path-level query params")
127 @parametrize
128 async def test_method_retrieve(self, async_client: AsyncAnthropic) -> None:
129 deployment_run = await async_client.beta.deployment_runs.retrieve(
130 deployment_run_id="deployment_run_id",
131 )
132 assert_matches_type(BetaManagedAgentsDeploymentRun, deployment_run, path=["response"])
133
134 @pytest.mark.skip(reason="buildURL drops path-level query params")
135 @parametrize
136 async def test_method_retrieve_with_all_params(self, async_client: AsyncAnthropic) -> None:
137 deployment_run = await async_client.beta.deployment_runs.retrieve(
138 deployment_run_id="deployment_run_id",
139 betas=["message-batches-2024-09-24"],
140 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
141 )
142 assert_matches_type(BetaManagedAgentsDeploymentRun, deployment_run, path=["response"])
143
144 @pytest.mark.skip(reason="buildURL drops path-level query params")
145 @parametrize
146 async def test_raw_response_retrieve(self, async_client: AsyncAnthropic) -> None:
147 response = await async_client.beta.deployment_runs.with_raw_response.retrieve(
148 deployment_run_id="deployment_run_id",
149 )
150
151 assert response.is_closed is True
152 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
153 deployment_run = await response.parse()
154 assert_matches_type(BetaManagedAgentsDeploymentRun, deployment_run, path=["response"])
155
156 @pytest.mark.skip(reason="buildURL drops path-level query params")
157 @parametrize
158 async def test_streaming_response_retrieve(self, async_client: AsyncAnthropic) -> None:
159 async with async_client.beta.deployment_runs.with_streaming_response.retrieve(
160 deployment_run_id="deployment_run_id",
161 ) as response:
162 assert not response.is_closed
163 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
164
165 deployment_run = await response.parse()
166 assert_matches_type(BetaManagedAgentsDeploymentRun, deployment_run, path=["response"])
167
168 assert cast(Any, response.is_closed) is True
169
170 @pytest.mark.skip(reason="buildURL drops path-level query params")
171 @parametrize
172 async def test_path_params_retrieve(self, async_client: AsyncAnthropic) -> None:
173 with pytest.raises(ValueError, match=r"Expected a non-empty value for `deployment_run_id` but received ''"):
174 await async_client.beta.deployment_runs.with_raw_response.retrieve(
175 deployment_run_id="",
176 )
177
178 @pytest.mark.skip(reason="buildURL drops path-level query params")
179 @parametrize
180 async def test_method_list(self, async_client: AsyncAnthropic) -> None:
181 deployment_run = await async_client.beta.deployment_runs.list()
182 assert_matches_type(AsyncPageCursor[BetaManagedAgentsDeploymentRun], deployment_run, path=["response"])
183
184 @pytest.mark.skip(reason="buildURL drops path-level query params")
185 @parametrize
186 async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None:
187 deployment_run = await async_client.beta.deployment_runs.list(
188 created_at_gt=parse_datetime("2019-12-27T18:11:19.117Z"),
189 created_at_gte=parse_datetime("2019-12-27T18:11:19.117Z"),
190 created_at_lt=parse_datetime("2019-12-27T18:11:19.117Z"),
191 created_at_lte=parse_datetime("2019-12-27T18:11:19.117Z"),
192 deployment_id="deployment_id",
193 has_error=True,
194 limit=0,
195 page="page",
196 trigger_type="schedule",
197 betas=["message-batches-2024-09-24"],
198 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
199 )
200 assert_matches_type(AsyncPageCursor[BetaManagedAgentsDeploymentRun], deployment_run, path=["response"])
201
202 @pytest.mark.skip(reason="buildURL drops path-level query params")
203 @parametrize
204 async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None:
205 response = await async_client.beta.deployment_runs.with_raw_response.list()
206
207 assert response.is_closed is True
208 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
209 deployment_run = await response.parse()
210 assert_matches_type(AsyncPageCursor[BetaManagedAgentsDeploymentRun], deployment_run, path=["response"])
211
212 @pytest.mark.skip(reason="buildURL drops path-level query params")
213 @parametrize
214 async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None:
215 async with async_client.beta.deployment_runs.with_streaming_response.list() as response:
216 assert not response.is_closed
217 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
218
219 deployment_run = await response.parse()
220 assert_matches_type(AsyncPageCursor[BetaManagedAgentsDeploymentRun], deployment_run, path=["response"])
221
222 assert cast(Any, response.is_closed) is True