Debian Codegraph @

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