Debian Codegraph @

tests/api_resources/beta/organization/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 SyncPage, AsyncPage
11 from anthropic.types.beta.organization import (
12 BetaWorkspace,
13 )
14
15 base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16
17
18 class TestWorkspaces:
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 workspace = client.beta.organization.workspaces.create(
24 name="x",
25 )
26 assert_matches_type(BetaWorkspace, workspace, path=["response"])
27
28 @parametrize
29 def test_method_create_with_all_params(self, client: Anthropic) -> None:
30 workspace = client.beta.organization.workspaces.create(
31 name="x",
32 data_residency={
33 "allowed_inference_geos": "unrestricted",
34 "default_inference_geo": "global",
35 "workspace_geo": "us",
36 },
37 display_color="#6C5BB9",
38 external_key_id="ekey_01SDCCSbTxrXDpWc1phhtcfK",
39 tags={
40 "env": "prod",
41 "team": "platform",
42 },
43 betas=["message-batches-2024-09-24"],
44 )
45 assert_matches_type(BetaWorkspace, workspace, path=["response"])
46
47 @parametrize
48 def test_raw_response_create(self, client: Anthropic) -> None:
49 response = client.beta.organization.workspaces.with_raw_response.create(
50 name="x",
51 )
52
53 assert response.is_closed is True
54 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
55 workspace = response.parse()
56 assert_matches_type(BetaWorkspace, workspace, path=["response"])
57
58 @parametrize
59 def test_streaming_response_create(self, client: Anthropic) -> None:
60 with client.beta.organization.workspaces.with_streaming_response.create(
61 name="x",
62 ) as response:
63 assert not response.is_closed
64 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
65
66 workspace = response.parse()
67 assert_matches_type(BetaWorkspace, workspace, path=["response"])
68
69 assert cast(Any, response.is_closed) is True
70
71 @parametrize
72 def test_method_retrieve(self, client: Anthropic) -> None:
73 workspace = client.beta.organization.workspaces.retrieve(
74 "workspace_id",
75 )
76 assert_matches_type(BetaWorkspace, workspace, path=["response"])
77
78 @parametrize
79 def test_raw_response_retrieve(self, client: Anthropic) -> None:
80 response = client.beta.organization.workspaces.with_raw_response.retrieve(
81 "workspace_id",
82 )
83
84 assert response.is_closed is True
85 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
86 workspace = response.parse()
87 assert_matches_type(BetaWorkspace, workspace, path=["response"])
88
89 @parametrize
90 def test_streaming_response_retrieve(self, client: Anthropic) -> None:
91 with client.beta.organization.workspaces.with_streaming_response.retrieve(
92 "workspace_id",
93 ) as response:
94 assert not response.is_closed
95 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
96
97 workspace = response.parse()
98 assert_matches_type(BetaWorkspace, workspace, path=["response"])
99
100 assert cast(Any, response.is_closed) is True
101
102 @parametrize
103 def test_path_params_retrieve(self, client: Anthropic) -> None:
104 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
105 client.beta.organization.workspaces.with_raw_response.retrieve(
106 "",
107 )
108
109 @parametrize
110 def test_method_update(self, client: Anthropic) -> None:
111 workspace = client.beta.organization.workspaces.update(
112 workspace_id="workspace_id",
113 )
114 assert_matches_type(BetaWorkspace, workspace, path=["response"])
115
116 @parametrize
117 def test_method_update_with_all_params(self, client: Anthropic) -> None:
118 workspace = client.beta.organization.workspaces.update(
119 workspace_id="workspace_id",
120 data_residency={
121 "allowed_inference_geos": "unrestricted",
122 "default_inference_geo": "global",
123 },
124 display_color="#6C5BB9",
125 external_key_id="ekey_01SDCCSbTxrXDpWc1phhtcfK",
126 name="x",
127 tags={
128 "env": "prod",
129 "team": "platform",
130 },
131 )
132 assert_matches_type(BetaWorkspace, workspace, path=["response"])
133
134 @parametrize
135 def test_raw_response_update(self, client: Anthropic) -> None:
136 response = client.beta.organization.workspaces.with_raw_response.update(
137 workspace_id="workspace_id",
138 )
139
140 assert response.is_closed is True
141 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
142 workspace = response.parse()
143 assert_matches_type(BetaWorkspace, workspace, path=["response"])
144
145 @parametrize
146 def test_streaming_response_update(self, client: Anthropic) -> None:
147 with client.beta.organization.workspaces.with_streaming_response.update(
148 workspace_id="workspace_id",
149 ) as response:
150 assert not response.is_closed
151 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
152
153 workspace = response.parse()
154 assert_matches_type(BetaWorkspace, workspace, path=["response"])
155
156 assert cast(Any, response.is_closed) is True
157
158 @parametrize
159 def test_path_params_update(self, client: Anthropic) -> None:
160 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
161 client.beta.organization.workspaces.with_raw_response.update(
162 workspace_id="",
163 )
164
165 @parametrize
166 def test_method_list(self, client: Anthropic) -> None:
167 workspace = client.beta.organization.workspaces.list()
168 assert_matches_type(SyncPage[BetaWorkspace], workspace, path=["response"])
169
170 @parametrize
171 def test_method_list_with_all_params(self, client: Anthropic) -> None:
172 workspace = client.beta.organization.workspaces.list(
173 after_id="after_id",
174 before_id="before_id",
175 include_archived=True,
176 limit=1,
177 )
178 assert_matches_type(SyncPage[BetaWorkspace], workspace, path=["response"])
179
180 @parametrize
181 def test_raw_response_list(self, client: Anthropic) -> None:
182 response = client.beta.organization.workspaces.with_raw_response.list()
183
184 assert response.is_closed is True
185 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
186 workspace = response.parse()
187 assert_matches_type(SyncPage[BetaWorkspace], workspace, path=["response"])
188
189 @parametrize
190 def test_streaming_response_list(self, client: Anthropic) -> None:
191 with client.beta.organization.workspaces.with_streaming_response.list() as response:
192 assert not response.is_closed
193 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
194
195 workspace = response.parse()
196 assert_matches_type(SyncPage[BetaWorkspace], workspace, path=["response"])
197
198 assert cast(Any, response.is_closed) is True
199
200 @parametrize
201 def test_method_archive(self, client: Anthropic) -> None:
202 workspace = client.beta.organization.workspaces.archive(
203 "workspace_id",
204 )
205 assert_matches_type(BetaWorkspace, workspace, path=["response"])
206
207 @parametrize
208 def test_raw_response_archive(self, client: Anthropic) -> None:
209 response = client.beta.organization.workspaces.with_raw_response.archive(
210 "workspace_id",
211 )
212
213 assert response.is_closed is True
214 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
215 workspace = response.parse()
216 assert_matches_type(BetaWorkspace, workspace, path=["response"])
217
218 @parametrize
219 def test_streaming_response_archive(self, client: Anthropic) -> None:
220 with client.beta.organization.workspaces.with_streaming_response.archive(
221 "workspace_id",
222 ) as response:
223 assert not response.is_closed
224 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
225
226 workspace = response.parse()
227 assert_matches_type(BetaWorkspace, workspace, path=["response"])
228
229 assert cast(Any, response.is_closed) is True
230
231 @parametrize
232 def test_path_params_archive(self, client: Anthropic) -> None:
233 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
234 client.beta.organization.workspaces.with_raw_response.archive(
235 "",
236 )
237
238
239 class TestAsyncWorkspaces:
240 parametrize = pytest.mark.parametrize(
241 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
242 )
243
244 @parametrize
245 async def test_method_create(self, async_client: AsyncAnthropic) -> None:
246 workspace = await async_client.beta.organization.workspaces.create(
247 name="x",
248 )
249 assert_matches_type(BetaWorkspace, workspace, path=["response"])
250
251 @parametrize
252 async def test_method_create_with_all_params(self, async_client: AsyncAnthropic) -> None:
253 workspace = await async_client.beta.organization.workspaces.create(
254 name="x",
255 data_residency={
256 "allowed_inference_geos": "unrestricted",
257 "default_inference_geo": "global",
258 "workspace_geo": "us",
259 },
260 display_color="#6C5BB9",
261 external_key_id="ekey_01SDCCSbTxrXDpWc1phhtcfK",
262 tags={
263 "env": "prod",
264 "team": "platform",
265 },
266 betas=["message-batches-2024-09-24"],
267 )
268 assert_matches_type(BetaWorkspace, workspace, path=["response"])
269
270 @parametrize
271 async def test_raw_response_create(self, async_client: AsyncAnthropic) -> None:
272 response = await async_client.beta.organization.workspaces.with_raw_response.create(
273 name="x",
274 )
275
276 assert response.is_closed is True
277 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
278 workspace = await response.parse()
279 assert_matches_type(BetaWorkspace, workspace, path=["response"])
280
281 @parametrize
282 async def test_streaming_response_create(self, async_client: AsyncAnthropic) -> None:
283 async with async_client.beta.organization.workspaces.with_streaming_response.create(
284 name="x",
285 ) as response:
286 assert not response.is_closed
287 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
288
289 workspace = await response.parse()
290 assert_matches_type(BetaWorkspace, workspace, path=["response"])
291
292 assert cast(Any, response.is_closed) is True
293
294 @parametrize
295 async def test_method_retrieve(self, async_client: AsyncAnthropic) -> None:
296 workspace = await async_client.beta.organization.workspaces.retrieve(
297 "workspace_id",
298 )
299 assert_matches_type(BetaWorkspace, workspace, path=["response"])
300
301 @parametrize
302 async def test_raw_response_retrieve(self, async_client: AsyncAnthropic) -> None:
303 response = await async_client.beta.organization.workspaces.with_raw_response.retrieve(
304 "workspace_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(BetaWorkspace, workspace, path=["response"])
311
312 @parametrize
313 async def test_streaming_response_retrieve(self, async_client: AsyncAnthropic) -> None:
314 async with async_client.beta.organization.workspaces.with_streaming_response.retrieve(
315 "workspace_id",
316 ) as response:
317 assert not response.is_closed
318 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
319
320 workspace = await response.parse()
321 assert_matches_type(BetaWorkspace, workspace, path=["response"])
322
323 assert cast(Any, response.is_closed) is True
324
325 @parametrize
326 async def test_path_params_retrieve(self, async_client: AsyncAnthropic) -> None:
327 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
328 await async_client.beta.organization.workspaces.with_raw_response.retrieve(
329 "",
330 )
331
332 @parametrize
333 async def test_method_update(self, async_client: AsyncAnthropic) -> None:
334 workspace = await async_client.beta.organization.workspaces.update(
335 workspace_id="workspace_id",
336 )
337 assert_matches_type(BetaWorkspace, workspace, path=["response"])
338
339 @parametrize
340 async def test_method_update_with_all_params(self, async_client: AsyncAnthropic) -> None:
341 workspace = await async_client.beta.organization.workspaces.update(
342 workspace_id="workspace_id",
343 data_residency={
344 "allowed_inference_geos": "unrestricted",
345 "default_inference_geo": "global",
346 },
347 display_color="#6C5BB9",
348 external_key_id="ekey_01SDCCSbTxrXDpWc1phhtcfK",
349 name="x",
350 tags={
351 "env": "prod",
352 "team": "platform",
353 },
354 )
355 assert_matches_type(BetaWorkspace, workspace, path=["response"])
356
357 @parametrize
358 async def test_raw_response_update(self, async_client: AsyncAnthropic) -> None:
359 response = await async_client.beta.organization.workspaces.with_raw_response.update(
360 workspace_id="workspace_id",
361 )
362
363 assert response.is_closed is True
364 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
365 workspace = await response.parse()
366 assert_matches_type(BetaWorkspace, workspace, path=["response"])
367
368 @parametrize
369 async def test_streaming_response_update(self, async_client: AsyncAnthropic) -> None:
370 async with async_client.beta.organization.workspaces.with_streaming_response.update(
371 workspace_id="workspace_id",
372 ) as response:
373 assert not response.is_closed
374 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
375
376 workspace = await response.parse()
377 assert_matches_type(BetaWorkspace, workspace, path=["response"])
378
379 assert cast(Any, response.is_closed) is True
380
381 @parametrize
382 async def test_path_params_update(self, async_client: AsyncAnthropic) -> None:
383 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
384 await async_client.beta.organization.workspaces.with_raw_response.update(
385 workspace_id="",
386 )
387
388 @parametrize
389 async def test_method_list(self, async_client: AsyncAnthropic) -> None:
390 workspace = await async_client.beta.organization.workspaces.list()
391 assert_matches_type(AsyncPage[BetaWorkspace], workspace, path=["response"])
392
393 @parametrize
394 async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None:
395 workspace = await async_client.beta.organization.workspaces.list(
396 after_id="after_id",
397 before_id="before_id",
398 include_archived=True,
399 limit=1,
400 )
401 assert_matches_type(AsyncPage[BetaWorkspace], workspace, path=["response"])
402
403 @parametrize
404 async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None:
405 response = await async_client.beta.organization.workspaces.with_raw_response.list()
406
407 assert response.is_closed is True
408 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
409 workspace = await response.parse()
410 assert_matches_type(AsyncPage[BetaWorkspace], workspace, path=["response"])
411
412 @parametrize
413 async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None:
414 async with async_client.beta.organization.workspaces.with_streaming_response.list() as response:
415 assert not response.is_closed
416 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
417
418 workspace = await response.parse()
419 assert_matches_type(AsyncPage[BetaWorkspace], workspace, path=["response"])
420
421 assert cast(Any, response.is_closed) is True
422
423 @parametrize
424 async def test_method_archive(self, async_client: AsyncAnthropic) -> None:
425 workspace = await async_client.beta.organization.workspaces.archive(
426 "workspace_id",
427 )
428 assert_matches_type(BetaWorkspace, workspace, path=["response"])
429
430 @parametrize
431 async def test_raw_response_archive(self, async_client: AsyncAnthropic) -> None:
432 response = await async_client.beta.organization.workspaces.with_raw_response.archive(
433 "workspace_id",
434 )
435
436 assert response.is_closed is True
437 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
438 workspace = await response.parse()
439 assert_matches_type(BetaWorkspace, workspace, path=["response"])
440
441 @parametrize
442 async def test_streaming_response_archive(self, async_client: AsyncAnthropic) -> None:
443 async with async_client.beta.organization.workspaces.with_streaming_response.archive(
444 "workspace_id",
445 ) as response:
446 assert not response.is_closed
447 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
448
449 workspace = await response.parse()
450 assert_matches_type(BetaWorkspace, workspace, path=["response"])
451
452 assert cast(Any, response.is_closed) is True
453
454 @parametrize
455 async def test_path_params_archive(self, async_client: AsyncAnthropic) -> None:
456 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
457 await async_client.beta.organization.workspaces.with_raw_response.archive(
458 "",
459 )