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