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