Debian Codegraph @

tests/api_resources/beta/organization/federation/rules/test_workspaces.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 BetaFederationRuleWorkspace
12 from anthropic.types.beta.organization.federation.rules import (
13 WorkspaceRemoveResponse,
14 )
15
16 base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
17
18
19 class TestWorkspaces:
20 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
21
22 @parametrize
23 def test_method_list(self, client: Anthropic) -> None:
24 workspace = client.beta.organization.federation.rules.workspaces.list(
25 federation_rule_id="federation_rule_id",
26 )
27 assert_matches_type(SyncPageCursor[BetaFederationRuleWorkspace], workspace, path=["response"])
28
29 @parametrize
30 def test_method_list_with_all_params(self, client: Anthropic) -> None:
31 workspace = client.beta.organization.federation.rules.workspaces.list(
32 federation_rule_id="federation_rule_id",
33 limit=1,
34 page="page",
35 betas=["message-batches-2024-09-24"],
36 )
37 assert_matches_type(SyncPageCursor[BetaFederationRuleWorkspace], workspace, path=["response"])
38
39 @parametrize
40 def test_raw_response_list(self, client: Anthropic) -> None:
41 response = client.beta.organization.federation.rules.workspaces.with_raw_response.list(
42 federation_rule_id="federation_rule_id",
43 )
44
45 assert response.is_closed is True
46 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
47 workspace = response.parse()
48 assert_matches_type(SyncPageCursor[BetaFederationRuleWorkspace], workspace, path=["response"])
49
50 @parametrize
51 def test_streaming_response_list(self, client: Anthropic) -> None:
52 with client.beta.organization.federation.rules.workspaces.with_streaming_response.list(
53 federation_rule_id="federation_rule_id",
54 ) as response:
55 assert not response.is_closed
56 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
57
58 workspace = response.parse()
59 assert_matches_type(SyncPageCursor[BetaFederationRuleWorkspace], workspace, path=["response"])
60
61 assert cast(Any, response.is_closed) is True
62
63 @parametrize
64 def test_path_params_list(self, client: Anthropic) -> None:
65 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
66 client.beta.organization.federation.rules.workspaces.with_raw_response.list(
67 federation_rule_id="",
68 )
69
70 @parametrize
71 def test_method_add(self, client: Anthropic) -> None:
72 workspace = client.beta.organization.federation.rules.workspaces.add(
73 federation_rule_id="federation_rule_id",
74 workspace_id="workspace_id",
75 )
76 assert_matches_type(BetaFederationRuleWorkspace, workspace, path=["response"])
77
78 @parametrize
79 def test_method_add_with_all_params(self, client: Anthropic) -> None:
80 workspace = client.beta.organization.federation.rules.workspaces.add(
81 federation_rule_id="federation_rule_id",
82 workspace_id="workspace_id",
83 betas=["message-batches-2024-09-24"],
84 )
85 assert_matches_type(BetaFederationRuleWorkspace, workspace, path=["response"])
86
87 @parametrize
88 def test_raw_response_add(self, client: Anthropic) -> None:
89 response = client.beta.organization.federation.rules.workspaces.with_raw_response.add(
90 federation_rule_id="federation_rule_id",
91 workspace_id="workspace_id",
92 )
93
94 assert response.is_closed is True
95 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
96 workspace = response.parse()
97 assert_matches_type(BetaFederationRuleWorkspace, workspace, path=["response"])
98
99 @parametrize
100 def test_streaming_response_add(self, client: Anthropic) -> None:
101 with client.beta.organization.federation.rules.workspaces.with_streaming_response.add(
102 federation_rule_id="federation_rule_id",
103 workspace_id="workspace_id",
104 ) as response:
105 assert not response.is_closed
106 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
107
108 workspace = response.parse()
109 assert_matches_type(BetaFederationRuleWorkspace, workspace, path=["response"])
110
111 assert cast(Any, response.is_closed) is True
112
113 @parametrize
114 def test_path_params_add(self, client: Anthropic) -> None:
115 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
116 client.beta.organization.federation.rules.workspaces.with_raw_response.add(
117 federation_rule_id="",
118 workspace_id="workspace_id",
119 )
120
121 @parametrize
122 def test_method_remove(self, client: Anthropic) -> None:
123 workspace = client.beta.organization.federation.rules.workspaces.remove(
124 workspace_id="workspace_id",
125 federation_rule_id="federation_rule_id",
126 )
127 assert_matches_type(WorkspaceRemoveResponse, workspace, path=["response"])
128
129 @parametrize
130 def test_method_remove_with_all_params(self, client: Anthropic) -> None:
131 workspace = client.beta.organization.federation.rules.workspaces.remove(
132 workspace_id="workspace_id",
133 federation_rule_id="federation_rule_id",
134 betas=["message-batches-2024-09-24"],
135 )
136 assert_matches_type(WorkspaceRemoveResponse, workspace, path=["response"])
137
138 @parametrize
139 def test_raw_response_remove(self, client: Anthropic) -> None:
140 response = client.beta.organization.federation.rules.workspaces.with_raw_response.remove(
141 workspace_id="workspace_id",
142 federation_rule_id="federation_rule_id",
143 )
144
145 assert response.is_closed is True
146 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
147 workspace = response.parse()
148 assert_matches_type(WorkspaceRemoveResponse, workspace, path=["response"])
149
150 @parametrize
151 def test_streaming_response_remove(self, client: Anthropic) -> None:
152 with client.beta.organization.federation.rules.workspaces.with_streaming_response.remove(
153 workspace_id="workspace_id",
154 federation_rule_id="federation_rule_id",
155 ) as response:
156 assert not response.is_closed
157 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
158
159 workspace = response.parse()
160 assert_matches_type(WorkspaceRemoveResponse, workspace, path=["response"])
161
162 assert cast(Any, response.is_closed) is True
163
164 @parametrize
165 def test_path_params_remove(self, client: Anthropic) -> None:
166 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
167 client.beta.organization.federation.rules.workspaces.with_raw_response.remove(
168 workspace_id="workspace_id",
169 federation_rule_id="",
170 )
171
172 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
173 client.beta.organization.federation.rules.workspaces.with_raw_response.remove(
174 workspace_id="",
175 federation_rule_id="federation_rule_id",
176 )
177
178
179 class TestAsyncWorkspaces:
180 parametrize = pytest.mark.parametrize(
181 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
182 )
183
184 @parametrize
185 async def test_method_list(self, async_client: AsyncAnthropic) -> None:
186 workspace = await async_client.beta.organization.federation.rules.workspaces.list(
187 federation_rule_id="federation_rule_id",
188 )
189 assert_matches_type(AsyncPageCursor[BetaFederationRuleWorkspace], workspace, path=["response"])
190
191 @parametrize
192 async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None:
193 workspace = await async_client.beta.organization.federation.rules.workspaces.list(
194 federation_rule_id="federation_rule_id",
195 limit=1,
196 page="page",
197 betas=["message-batches-2024-09-24"],
198 )
199 assert_matches_type(AsyncPageCursor[BetaFederationRuleWorkspace], workspace, path=["response"])
200
201 @parametrize
202 async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None:
203 response = await async_client.beta.organization.federation.rules.workspaces.with_raw_response.list(
204 federation_rule_id="federation_rule_id",
205 )
206
207 assert response.is_closed is True
208 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
209 workspace = await response.parse()
210 assert_matches_type(AsyncPageCursor[BetaFederationRuleWorkspace], workspace, path=["response"])
211
212 @parametrize
213 async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None:
214 async with async_client.beta.organization.federation.rules.workspaces.with_streaming_response.list(
215 federation_rule_id="federation_rule_id",
216 ) as response:
217 assert not response.is_closed
218 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
219
220 workspace = await response.parse()
221 assert_matches_type(AsyncPageCursor[BetaFederationRuleWorkspace], workspace, path=["response"])
222
223 assert cast(Any, response.is_closed) is True
224
225 @parametrize
226 async def test_path_params_list(self, async_client: AsyncAnthropic) -> None:
227 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
228 await async_client.beta.organization.federation.rules.workspaces.with_raw_response.list(
229 federation_rule_id="",
230 )
231
232 @parametrize
233 async def test_method_add(self, async_client: AsyncAnthropic) -> None:
234 workspace = await async_client.beta.organization.federation.rules.workspaces.add(
235 federation_rule_id="federation_rule_id",
236 workspace_id="workspace_id",
237 )
238 assert_matches_type(BetaFederationRuleWorkspace, workspace, path=["response"])
239
240 @parametrize
241 async def test_method_add_with_all_params(self, async_client: AsyncAnthropic) -> None:
242 workspace = await async_client.beta.organization.federation.rules.workspaces.add(
243 federation_rule_id="federation_rule_id",
244 workspace_id="workspace_id",
245 betas=["message-batches-2024-09-24"],
246 )
247 assert_matches_type(BetaFederationRuleWorkspace, workspace, path=["response"])
248
249 @parametrize
250 async def test_raw_response_add(self, async_client: AsyncAnthropic) -> None:
251 response = await async_client.beta.organization.federation.rules.workspaces.with_raw_response.add(
252 federation_rule_id="federation_rule_id",
253 workspace_id="workspace_id",
254 )
255
256 assert response.is_closed is True
257 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
258 workspace = await response.parse()
259 assert_matches_type(BetaFederationRuleWorkspace, workspace, path=["response"])
260
261 @parametrize
262 async def test_streaming_response_add(self, async_client: AsyncAnthropic) -> None:
263 async with async_client.beta.organization.federation.rules.workspaces.with_streaming_response.add(
264 federation_rule_id="federation_rule_id",
265 workspace_id="workspace_id",
266 ) as response:
267 assert not response.is_closed
268 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
269
270 workspace = await response.parse()
271 assert_matches_type(BetaFederationRuleWorkspace, workspace, path=["response"])
272
273 assert cast(Any, response.is_closed) is True
274
275 @parametrize
276 async def test_path_params_add(self, async_client: AsyncAnthropic) -> None:
277 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
278 await async_client.beta.organization.federation.rules.workspaces.with_raw_response.add(
279 federation_rule_id="",
280 workspace_id="workspace_id",
281 )
282
283 @parametrize
284 async def test_method_remove(self, async_client: AsyncAnthropic) -> None:
285 workspace = await async_client.beta.organization.federation.rules.workspaces.remove(
286 workspace_id="workspace_id",
287 federation_rule_id="federation_rule_id",
288 )
289 assert_matches_type(WorkspaceRemoveResponse, workspace, path=["response"])
290
291 @parametrize
292 async def test_method_remove_with_all_params(self, async_client: AsyncAnthropic) -> None:
293 workspace = await async_client.beta.organization.federation.rules.workspaces.remove(
294 workspace_id="workspace_id",
295 federation_rule_id="federation_rule_id",
296 betas=["message-batches-2024-09-24"],
297 )
298 assert_matches_type(WorkspaceRemoveResponse, workspace, path=["response"])
299
300 @parametrize
301 async def test_raw_response_remove(self, async_client: AsyncAnthropic) -> None:
302 response = await async_client.beta.organization.federation.rules.workspaces.with_raw_response.remove(
303 workspace_id="workspace_id",
304 federation_rule_id="federation_rule_id",
305 )
306
307 assert response.is_closed is True
308 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
309 workspace = await response.parse()
310 assert_matches_type(WorkspaceRemoveResponse, workspace, path=["response"])
311
312 @parametrize
313 async def test_streaming_response_remove(self, async_client: AsyncAnthropic) -> None:
314 async with async_client.beta.organization.federation.rules.workspaces.with_streaming_response.remove(
315 workspace_id="workspace_id",
316 federation_rule_id="federation_rule_id",
317 ) as response:
318 assert not response.is_closed
319 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
320
321 workspace = await response.parse()
322 assert_matches_type(WorkspaceRemoveResponse, workspace, path=["response"])
323
324 assert cast(Any, response.is_closed) is True
325
326 @parametrize
327 async def test_path_params_remove(self, async_client: AsyncAnthropic) -> None:
328 with pytest.raises(ValueError, match=r"Expected a non-empty value for `federation_rule_id` but received ''"):
329 await async_client.beta.organization.federation.rules.workspaces.with_raw_response.remove(
330 workspace_id="workspace_id",
331 federation_rule_id="",
332 )
333
334 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
335 await async_client.beta.organization.federation.rules.workspaces.with_raw_response.remove(
336 workspace_id="",
337 federation_rule_id="federation_rule_id",
338 )