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