| 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.types.beta import BetaOrganization |
| 11 |
|
| 12 |
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 13 |
|
| 14 |
|
| 15 |
class TestOrganization: |
| 16 |
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 17 |
|
| 18 |
@parametrize |
| 19 |
def test_method_retrieve(self, client: Anthropic) -> None: |
| 20 |
organization = client.beta.organization.retrieve() |
| 21 |
assert_matches_type(BetaOrganization, organization, path=["response"]) |
| 22 |
|
| 23 |
@parametrize |
| 24 |
def test_raw_response_retrieve(self, client: Anthropic) -> None: |
| 25 |
response = client.beta.organization.with_raw_response.retrieve() |
| 26 |
|
| 27 |
assert response.is_closed is True |
| 28 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 29 |
organization = response.parse() |
| 30 |
assert_matches_type(BetaOrganization, organization, path=["response"]) |
| 31 |
|
| 32 |
@parametrize |
| 33 |
def test_streaming_response_retrieve(self, client: Anthropic) -> None: |
| 34 |
with client.beta.organization.with_streaming_response.retrieve() as response: |
| 35 |
assert not response.is_closed |
| 36 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 37 |
|
| 38 |
organization = response.parse() |
| 39 |
assert_matches_type(BetaOrganization, organization, path=["response"]) |
| 40 |
|
| 41 |
assert cast(Any, response.is_closed) is True |
| 42 |
|
| 43 |
|
| 44 |
class TestAsyncOrganization: |
| 45 |
parametrize = pytest.mark.parametrize( |
| 46 |
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 47 |
) |
| 48 |
|
| 49 |
@parametrize |
| 50 |
async def test_method_retrieve(self, async_client: AsyncAnthropic) -> None: |
| 51 |
organization = await async_client.beta.organization.retrieve() |
| 52 |
assert_matches_type(BetaOrganization, organization, path=["response"]) |
| 53 |
|
| 54 |
@parametrize |
| 55 |
async def test_raw_response_retrieve(self, async_client: AsyncAnthropic) -> None: |
| 56 |
response = await async_client.beta.organization.with_raw_response.retrieve() |
| 57 |
|
| 58 |
assert response.is_closed is True |
| 59 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 60 |
organization = await response.parse() |
| 61 |
assert_matches_type(BetaOrganization, organization, path=["response"]) |
| 62 |
|
| 63 |
@parametrize |
| 64 |
async def test_streaming_response_retrieve(self, async_client: AsyncAnthropic) -> None: |
| 65 |
async with async_client.beta.organization.with_streaming_response.retrieve() as response: |
| 66 |
assert not response.is_closed |
| 67 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 68 |
|
| 69 |
organization = await response.parse() |
| 70 |
assert_matches_type(BetaOrganization, organization, path=["response"]) |
| 71 |
|
| 72 |
assert cast(Any, response.is_closed) is True |