| 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 import BetaManagedAgentsAgent |
| 12 |
|
| 13 |
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 14 |
|
| 15 |
|
| 16 |
class TestVersions: |
| 17 |
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 18 |
|
| 19 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 20 |
@parametrize |
| 21 |
def test_method_list(self, client: Anthropic) -> None: |
| 22 |
version = client.beta.agents.versions.list( |
| 23 |
agent_id="agent_011CZkYpogX7uDKUyvBTophP", |
| 24 |
) |
| 25 |
assert_matches_type(SyncPageCursor[BetaManagedAgentsAgent], version, path=["response"]) |
| 26 |
|
| 27 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 28 |
@parametrize |
| 29 |
def test_method_list_with_all_params(self, client: Anthropic) -> None: |
| 30 |
version = client.beta.agents.versions.list( |
| 31 |
agent_id="agent_011CZkYpogX7uDKUyvBTophP", |
| 32 |
limit=0, |
| 33 |
page="page", |
| 34 |
betas=["message-batches-2024-09-24"], |
| 35 |
workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy", |
| 36 |
) |
| 37 |
assert_matches_type(SyncPageCursor[BetaManagedAgentsAgent], version, path=["response"]) |
| 38 |
|
| 39 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 40 |
@parametrize |
| 41 |
def test_raw_response_list(self, client: Anthropic) -> None: |
| 42 |
response = client.beta.agents.versions.with_raw_response.list( |
| 43 |
agent_id="agent_011CZkYpogX7uDKUyvBTophP", |
| 44 |
) |
| 45 |
|
| 46 |
assert response.is_closed is True |
| 47 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 48 |
version = response.parse() |
| 49 |
assert_matches_type(SyncPageCursor[BetaManagedAgentsAgent], version, path=["response"]) |
| 50 |
|
| 51 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 52 |
@parametrize |
| 53 |
def test_streaming_response_list(self, client: Anthropic) -> None: |
| 54 |
with client.beta.agents.versions.with_streaming_response.list( |
| 55 |
agent_id="agent_011CZkYpogX7uDKUyvBTophP", |
| 56 |
) as response: |
| 57 |
assert not response.is_closed |
| 58 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 59 |
|
| 60 |
version = response.parse() |
| 61 |
assert_matches_type(SyncPageCursor[BetaManagedAgentsAgent], version, path=["response"]) |
| 62 |
|
| 63 |
assert cast(Any, response.is_closed) is True |
| 64 |
|
| 65 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 66 |
@parametrize |
| 67 |
def test_path_params_list(self, client: Anthropic) -> None: |
| 68 |
with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_id` but received ''"): |
| 69 |
client.beta.agents.versions.with_raw_response.list( |
| 70 |
agent_id="", |
| 71 |
) |
| 72 |
|
| 73 |
|
| 74 |
class TestAsyncVersions: |
| 75 |
parametrize = pytest.mark.parametrize( |
| 76 |
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 77 |
) |
| 78 |
|
| 79 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 80 |
@parametrize |
| 81 |
async def test_method_list(self, async_client: AsyncAnthropic) -> None: |
| 82 |
version = await async_client.beta.agents.versions.list( |
| 83 |
agent_id="agent_011CZkYpogX7uDKUyvBTophP", |
| 84 |
) |
| 85 |
assert_matches_type(AsyncPageCursor[BetaManagedAgentsAgent], version, path=["response"]) |
| 86 |
|
| 87 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 88 |
@parametrize |
| 89 |
async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None: |
| 90 |
version = await async_client.beta.agents.versions.list( |
| 91 |
agent_id="agent_011CZkYpogX7uDKUyvBTophP", |
| 92 |
limit=0, |
| 93 |
page="page", |
| 94 |
betas=["message-batches-2024-09-24"], |
| 95 |
workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy", |
| 96 |
) |
| 97 |
assert_matches_type(AsyncPageCursor[BetaManagedAgentsAgent], version, path=["response"]) |
| 98 |
|
| 99 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 100 |
@parametrize |
| 101 |
async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None: |
| 102 |
response = await async_client.beta.agents.versions.with_raw_response.list( |
| 103 |
agent_id="agent_011CZkYpogX7uDKUyvBTophP", |
| 104 |
) |
| 105 |
|
| 106 |
assert response.is_closed is True |
| 107 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 108 |
version = await response.parse() |
| 109 |
assert_matches_type(AsyncPageCursor[BetaManagedAgentsAgent], version, path=["response"]) |
| 110 |
|
| 111 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 112 |
@parametrize |
| 113 |
async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None: |
| 114 |
async with async_client.beta.agents.versions.with_streaming_response.list( |
| 115 |
agent_id="agent_011CZkYpogX7uDKUyvBTophP", |
| 116 |
) as response: |
| 117 |
assert not response.is_closed |
| 118 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 119 |
|
| 120 |
version = await response.parse() |
| 121 |
assert_matches_type(AsyncPageCursor[BetaManagedAgentsAgent], version, path=["response"]) |
| 122 |
|
| 123 |
assert cast(Any, response.is_closed) is True |
| 124 |
|
| 125 |
@pytest.mark.skip(reason="buildURL drops path-level query params") |
| 126 |
@parametrize |
| 127 |
async def test_path_params_list(self, async_client: AsyncAnthropic) -> None: |
| 128 |
with pytest.raises(ValueError, match=r"Expected a non-empty value for `agent_id` but received ''"): |
| 129 |
await async_client.beta.agents.versions.with_raw_response.list( |
| 130 |
agent_id="", |
| 131 |
) |