Debian Codegraph @

tests/api_resources/beta/organization/workspaces/test_rate_limits.py

raw
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.workspaces import BetaWorkspaceRateLimit
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.workspaces.rate_limits.list(
22 workspace_id="workspace_id",
23 )
24 assert_matches_type(SyncPageCursor[BetaWorkspaceRateLimit], rate_limit, path=["response"])
25
26 @parametrize
27 def test_method_list_with_all_params(self, client: Anthropic) -> None:
28 rate_limit = client.beta.organization.workspaces.rate_limits.list(
29 workspace_id="workspace_id",
30 group_type="batch",
31 limit=1,
32 page="page",
33 )
34 assert_matches_type(SyncPageCursor[BetaWorkspaceRateLimit], rate_limit, path=["response"])
35
36 @parametrize
37 def test_raw_response_list(self, client: Anthropic) -> None:
38 response = client.beta.organization.workspaces.rate_limits.with_raw_response.list(
39 workspace_id="workspace_id",
40 )
41
42 assert response.is_closed is True
43 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
44 rate_limit = response.parse()
45 assert_matches_type(SyncPageCursor[BetaWorkspaceRateLimit], rate_limit, path=["response"])
46
47 @parametrize
48 def test_streaming_response_list(self, client: Anthropic) -> None:
49 with client.beta.organization.workspaces.rate_limits.with_streaming_response.list(
50 workspace_id="workspace_id",
51 ) as response:
52 assert not response.is_closed
53 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
54
55 rate_limit = response.parse()
56 assert_matches_type(SyncPageCursor[BetaWorkspaceRateLimit], rate_limit, path=["response"])
57
58 assert cast(Any, response.is_closed) is True
59
60 @parametrize
61 def test_path_params_list(self, client: Anthropic) -> None:
62 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
63 client.beta.organization.workspaces.rate_limits.with_raw_response.list(
64 workspace_id="",
65 )
66
67
68 class TestAsyncRateLimits:
69 parametrize = pytest.mark.parametrize(
70 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
71 )
72
73 @parametrize
74 async def test_method_list(self, async_client: AsyncAnthropic) -> None:
75 rate_limit = await async_client.beta.organization.workspaces.rate_limits.list(
76 workspace_id="workspace_id",
77 )
78 assert_matches_type(AsyncPageCursor[BetaWorkspaceRateLimit], rate_limit, path=["response"])
79
80 @parametrize
81 async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None:
82 rate_limit = await async_client.beta.organization.workspaces.rate_limits.list(
83 workspace_id="workspace_id",
84 group_type="batch",
85 limit=1,
86 page="page",
87 )
88 assert_matches_type(AsyncPageCursor[BetaWorkspaceRateLimit], rate_limit, path=["response"])
89
90 @parametrize
91 async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None:
92 response = await async_client.beta.organization.workspaces.rate_limits.with_raw_response.list(
93 workspace_id="workspace_id",
94 )
95
96 assert response.is_closed is True
97 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
98 rate_limit = await response.parse()
99 assert_matches_type(AsyncPageCursor[BetaWorkspaceRateLimit], rate_limit, path=["response"])
100
101 @parametrize
102 async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None:
103 async with async_client.beta.organization.workspaces.rate_limits.with_streaming_response.list(
104 workspace_id="workspace_id",
105 ) as response:
106 assert not response.is_closed
107 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
108
109 rate_limit = await response.parse()
110 assert_matches_type(AsyncPageCursor[BetaWorkspaceRateLimit], rate_limit, path=["response"])
111
112 assert cast(Any, response.is_closed) is True
113
114 @parametrize
115 async def test_path_params_list(self, async_client: AsyncAnthropic) -> None:
116 with pytest.raises(ValueError, match=r"Expected a non-empty value for `workspace_id` but received ''"):
117 await async_client.beta.organization.workspaces.rate_limits.with_raw_response.list(
118 workspace_id="",
119 )