| 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 BetaOrganizationRateLimit |
| 12 |
|
| 13 |
base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 14 |
|
| 15 |
|
| 16 |
class TestRateLimits: |
| 17 |
parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 18 |
|
| 19 |
@parametrize |
| 20 |
def test_method_list(self, client: Anthropic) -> None: |
| 21 |
rate_limit = client.beta.organization.rate_limits.list() |
| 22 |
assert_matches_type(SyncPageCursor[BetaOrganizationRateLimit], rate_limit, path=["response"]) |
| 23 |
|
| 24 |
@parametrize |
| 25 |
def test_method_list_with_all_params(self, client: Anthropic) -> None: |
| 26 |
rate_limit = client.beta.organization.rate_limits.list( |
| 27 |
group_type="batch", |
| 28 |
limit=1, |
| 29 |
model="model", |
| 30 |
page="page", |
| 31 |
) |
| 32 |
assert_matches_type(SyncPageCursor[BetaOrganizationRateLimit], rate_limit, path=["response"]) |
| 33 |
|
| 34 |
@parametrize |
| 35 |
def test_raw_response_list(self, client: Anthropic) -> None: |
| 36 |
response = client.beta.organization.rate_limits.with_raw_response.list() |
| 37 |
|
| 38 |
assert response.is_closed is True |
| 39 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 40 |
rate_limit = response.parse() |
| 41 |
assert_matches_type(SyncPageCursor[BetaOrganizationRateLimit], rate_limit, path=["response"]) |
| 42 |
|
| 43 |
@parametrize |
| 44 |
def test_streaming_response_list(self, client: Anthropic) -> None: |
| 45 |
with client.beta.organization.rate_limits.with_streaming_response.list() as response: |
| 46 |
assert not response.is_closed |
| 47 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 48 |
|
| 49 |
rate_limit = response.parse() |
| 50 |
assert_matches_type(SyncPageCursor[BetaOrganizationRateLimit], rate_limit, path=["response"]) |
| 51 |
|
| 52 |
assert cast(Any, response.is_closed) is True |
| 53 |
|
| 54 |
|
| 55 |
class TestAsyncRateLimits: |
| 56 |
parametrize = pytest.mark.parametrize( |
| 57 |
"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 58 |
) |
| 59 |
|
| 60 |
@parametrize |
| 61 |
async def test_method_list(self, async_client: AsyncAnthropic) -> None: |
| 62 |
rate_limit = await async_client.beta.organization.rate_limits.list() |
| 63 |
assert_matches_type(AsyncPageCursor[BetaOrganizationRateLimit], rate_limit, path=["response"]) |
| 64 |
|
| 65 |
@parametrize |
| 66 |
async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None: |
| 67 |
rate_limit = await async_client.beta.organization.rate_limits.list( |
| 68 |
group_type="batch", |
| 69 |
limit=1, |
| 70 |
model="model", |
| 71 |
page="page", |
| 72 |
) |
| 73 |
assert_matches_type(AsyncPageCursor[BetaOrganizationRateLimit], rate_limit, path=["response"]) |
| 74 |
|
| 75 |
@parametrize |
| 76 |
async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None: |
| 77 |
response = await async_client.beta.organization.rate_limits.with_raw_response.list() |
| 78 |
|
| 79 |
assert response.is_closed is True |
| 80 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 81 |
rate_limit = await response.parse() |
| 82 |
assert_matches_type(AsyncPageCursor[BetaOrganizationRateLimit], rate_limit, path=["response"]) |
| 83 |
|
| 84 |
@parametrize |
| 85 |
async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None: |
| 86 |
async with async_client.beta.organization.rate_limits.with_streaming_response.list() as response: |
| 87 |
assert not response.is_closed |
| 88 |
assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 89 |
|
| 90 |
rate_limit = await response.parse() |
| 91 |
assert_matches_type(AsyncPageCursor[BetaOrganizationRateLimit], rate_limit, path=["response"]) |
| 92 |
|
| 93 |
assert cast(Any, response.is_closed) is True |