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