Debian Codegraph @

tests/api_resources/beta/test_user_profiles.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._utils import parse_datetime
11 from anthropic.pagination import SyncPageCursor, AsyncPageCursor
12 from anthropic.types.beta import (
13 BetaUserProfile,
14 BetaUserProfileEnrollmentURL,
15 )
16
17 base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
18
19
20 class TestUserProfiles:
21 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
22
23 @parametrize
24 def test_method_create(self, client: Anthropic) -> None:
25 user_profile = client.beta.user_profiles.create()
26 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
27
28 @parametrize
29 def test_method_create_with_all_params(self, client: Anthropic) -> None:
30 user_profile = client.beta.user_profiles.create(
31 access_type="application",
32 external_id="user_12345",
33 external_user_details={
34 "account_status": "active",
35 "country": "country",
36 "email_hash": "x",
37 "entity_type": "individual",
38 "name_hash": "x",
39 "onboarded_at": parse_datetime("2019-12-27T18:11:19.117Z"),
40 "reference_id": "x",
41 },
42 external_user_onboarded_at=parse_datetime("2024-11-02T08:15:00Z"),
43 metadata={},
44 name="x",
45 betas=["message-batches-2024-09-24"],
46 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
47 )
48 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
49
50 @parametrize
51 def test_raw_response_create(self, client: Anthropic) -> None:
52 response = client.beta.user_profiles.with_raw_response.create()
53
54 assert response.is_closed is True
55 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
56 user_profile = response.parse()
57 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
58
59 @parametrize
60 def test_streaming_response_create(self, client: Anthropic) -> None:
61 with client.beta.user_profiles.with_streaming_response.create() as response:
62 assert not response.is_closed
63 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
64
65 user_profile = response.parse()
66 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
67
68 assert cast(Any, response.is_closed) is True
69
70 @parametrize
71 def test_method_retrieve(self, client: Anthropic) -> None:
72 user_profile = client.beta.user_profiles.retrieve(
73 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
74 )
75 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
76
77 @parametrize
78 def test_method_retrieve_with_all_params(self, client: Anthropic) -> None:
79 user_profile = client.beta.user_profiles.retrieve(
80 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
81 betas=["message-batches-2024-09-24"],
82 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
83 )
84 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
85
86 @parametrize
87 def test_raw_response_retrieve(self, client: Anthropic) -> None:
88 response = client.beta.user_profiles.with_raw_response.retrieve(
89 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
90 )
91
92 assert response.is_closed is True
93 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
94 user_profile = response.parse()
95 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
96
97 @parametrize
98 def test_streaming_response_retrieve(self, client: Anthropic) -> None:
99 with client.beta.user_profiles.with_streaming_response.retrieve(
100 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
101 ) as response:
102 assert not response.is_closed
103 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
104
105 user_profile = response.parse()
106 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
107
108 assert cast(Any, response.is_closed) is True
109
110 @parametrize
111 def test_path_params_retrieve(self, client: Anthropic) -> None:
112 with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_profile_id` but received ''"):
113 client.beta.user_profiles.with_raw_response.retrieve(
114 user_profile_id="",
115 )
116
117 @parametrize
118 def test_method_update(self, client: Anthropic) -> None:
119 user_profile = client.beta.user_profiles.update(
120 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
121 )
122 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
123
124 @parametrize
125 def test_method_update_with_all_params(self, client: Anthropic) -> None:
126 user_profile = client.beta.user_profiles.update(
127 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
128 access_type="application",
129 external_id="user_12345",
130 external_user_details={
131 "account_status": "active",
132 "country": "country",
133 "email_hash": "x",
134 "entity_type": "individual",
135 "name_hash": "x",
136 "onboarded_at": parse_datetime("2019-12-27T18:11:19.117Z"),
137 "reference_id": "x",
138 },
139 external_user_onboarded_at=parse_datetime("2019-12-27T18:11:19.117Z"),
140 metadata={"foo": "string"},
141 name="x",
142 betas=["message-batches-2024-09-24"],
143 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
144 )
145 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
146
147 @parametrize
148 def test_raw_response_update(self, client: Anthropic) -> None:
149 response = client.beta.user_profiles.with_raw_response.update(
150 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
151 )
152
153 assert response.is_closed is True
154 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
155 user_profile = response.parse()
156 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
157
158 @parametrize
159 def test_streaming_response_update(self, client: Anthropic) -> None:
160 with client.beta.user_profiles.with_streaming_response.update(
161 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
162 ) as response:
163 assert not response.is_closed
164 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
165
166 user_profile = response.parse()
167 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
168
169 assert cast(Any, response.is_closed) is True
170
171 @parametrize
172 def test_path_params_update(self, client: Anthropic) -> None:
173 with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_profile_id` but received ''"):
174 client.beta.user_profiles.with_raw_response.update(
175 user_profile_id="",
176 )
177
178 @parametrize
179 def test_method_list(self, client: Anthropic) -> None:
180 user_profile = client.beta.user_profiles.list()
181 assert_matches_type(SyncPageCursor[BetaUserProfile], user_profile, path=["response"])
182
183 @parametrize
184 def test_method_list_with_all_params(self, client: Anthropic) -> None:
185 user_profile = client.beta.user_profiles.list(
186 limit=0,
187 order="asc",
188 order_by="created_at",
189 page="page",
190 betas=["message-batches-2024-09-24"],
191 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
192 )
193 assert_matches_type(SyncPageCursor[BetaUserProfile], user_profile, path=["response"])
194
195 @parametrize
196 def test_raw_response_list(self, client: Anthropic) -> None:
197 response = client.beta.user_profiles.with_raw_response.list()
198
199 assert response.is_closed is True
200 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
201 user_profile = response.parse()
202 assert_matches_type(SyncPageCursor[BetaUserProfile], user_profile, path=["response"])
203
204 @parametrize
205 def test_streaming_response_list(self, client: Anthropic) -> None:
206 with client.beta.user_profiles.with_streaming_response.list() as response:
207 assert not response.is_closed
208 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
209
210 user_profile = response.parse()
211 assert_matches_type(SyncPageCursor[BetaUserProfile], user_profile, path=["response"])
212
213 assert cast(Any, response.is_closed) is True
214
215 @parametrize
216 def test_method_create_enrollment_url(self, client: Anthropic) -> None:
217 user_profile = client.beta.user_profiles.create_enrollment_url(
218 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
219 )
220 assert_matches_type(BetaUserProfileEnrollmentURL, user_profile, path=["response"])
221
222 @parametrize
223 def test_method_create_enrollment_url_with_all_params(self, client: Anthropic) -> None:
224 user_profile = client.beta.user_profiles.create_enrollment_url(
225 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
226 betas=["message-batches-2024-09-24"],
227 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
228 )
229 assert_matches_type(BetaUserProfileEnrollmentURL, user_profile, path=["response"])
230
231 @parametrize
232 def test_raw_response_create_enrollment_url(self, client: Anthropic) -> None:
233 response = client.beta.user_profiles.with_raw_response.create_enrollment_url(
234 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
235 )
236
237 assert response.is_closed is True
238 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
239 user_profile = response.parse()
240 assert_matches_type(BetaUserProfileEnrollmentURL, user_profile, path=["response"])
241
242 @parametrize
243 def test_streaming_response_create_enrollment_url(self, client: Anthropic) -> None:
244 with client.beta.user_profiles.with_streaming_response.create_enrollment_url(
245 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
246 ) as response:
247 assert not response.is_closed
248 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
249
250 user_profile = response.parse()
251 assert_matches_type(BetaUserProfileEnrollmentURL, user_profile, path=["response"])
252
253 assert cast(Any, response.is_closed) is True
254
255 @parametrize
256 def test_path_params_create_enrollment_url(self, client: Anthropic) -> None:
257 with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_profile_id` but received ''"):
258 client.beta.user_profiles.with_raw_response.create_enrollment_url(
259 user_profile_id="",
260 )
261
262
263 class TestAsyncUserProfiles:
264 parametrize = pytest.mark.parametrize(
265 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
266 )
267
268 @parametrize
269 async def test_method_create(self, async_client: AsyncAnthropic) -> None:
270 user_profile = await async_client.beta.user_profiles.create()
271 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
272
273 @parametrize
274 async def test_method_create_with_all_params(self, async_client: AsyncAnthropic) -> None:
275 user_profile = await async_client.beta.user_profiles.create(
276 access_type="application",
277 external_id="user_12345",
278 external_user_details={
279 "account_status": "active",
280 "country": "country",
281 "email_hash": "x",
282 "entity_type": "individual",
283 "name_hash": "x",
284 "onboarded_at": parse_datetime("2019-12-27T18:11:19.117Z"),
285 "reference_id": "x",
286 },
287 external_user_onboarded_at=parse_datetime("2024-11-02T08:15:00Z"),
288 metadata={},
289 name="x",
290 betas=["message-batches-2024-09-24"],
291 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
292 )
293 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
294
295 @parametrize
296 async def test_raw_response_create(self, async_client: AsyncAnthropic) -> None:
297 response = await async_client.beta.user_profiles.with_raw_response.create()
298
299 assert response.is_closed is True
300 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
301 user_profile = await response.parse()
302 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
303
304 @parametrize
305 async def test_streaming_response_create(self, async_client: AsyncAnthropic) -> None:
306 async with async_client.beta.user_profiles.with_streaming_response.create() as response:
307 assert not response.is_closed
308 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
309
310 user_profile = await response.parse()
311 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
312
313 assert cast(Any, response.is_closed) is True
314
315 @parametrize
316 async def test_method_retrieve(self, async_client: AsyncAnthropic) -> None:
317 user_profile = await async_client.beta.user_profiles.retrieve(
318 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
319 )
320 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
321
322 @parametrize
323 async def test_method_retrieve_with_all_params(self, async_client: AsyncAnthropic) -> None:
324 user_profile = await async_client.beta.user_profiles.retrieve(
325 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
326 betas=["message-batches-2024-09-24"],
327 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
328 )
329 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
330
331 @parametrize
332 async def test_raw_response_retrieve(self, async_client: AsyncAnthropic) -> None:
333 response = await async_client.beta.user_profiles.with_raw_response.retrieve(
334 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
335 )
336
337 assert response.is_closed is True
338 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
339 user_profile = await response.parse()
340 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
341
342 @parametrize
343 async def test_streaming_response_retrieve(self, async_client: AsyncAnthropic) -> None:
344 async with async_client.beta.user_profiles.with_streaming_response.retrieve(
345 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
346 ) as response:
347 assert not response.is_closed
348 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
349
350 user_profile = await response.parse()
351 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
352
353 assert cast(Any, response.is_closed) is True
354
355 @parametrize
356 async def test_path_params_retrieve(self, async_client: AsyncAnthropic) -> None:
357 with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_profile_id` but received ''"):
358 await async_client.beta.user_profiles.with_raw_response.retrieve(
359 user_profile_id="",
360 )
361
362 @parametrize
363 async def test_method_update(self, async_client: AsyncAnthropic) -> None:
364 user_profile = await async_client.beta.user_profiles.update(
365 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
366 )
367 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
368
369 @parametrize
370 async def test_method_update_with_all_params(self, async_client: AsyncAnthropic) -> None:
371 user_profile = await async_client.beta.user_profiles.update(
372 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
373 access_type="application",
374 external_id="user_12345",
375 external_user_details={
376 "account_status": "active",
377 "country": "country",
378 "email_hash": "x",
379 "entity_type": "individual",
380 "name_hash": "x",
381 "onboarded_at": parse_datetime("2019-12-27T18:11:19.117Z"),
382 "reference_id": "x",
383 },
384 external_user_onboarded_at=parse_datetime("2019-12-27T18:11:19.117Z"),
385 metadata={"foo": "string"},
386 name="x",
387 betas=["message-batches-2024-09-24"],
388 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
389 )
390 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
391
392 @parametrize
393 async def test_raw_response_update(self, async_client: AsyncAnthropic) -> None:
394 response = await async_client.beta.user_profiles.with_raw_response.update(
395 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
396 )
397
398 assert response.is_closed is True
399 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
400 user_profile = await response.parse()
401 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
402
403 @parametrize
404 async def test_streaming_response_update(self, async_client: AsyncAnthropic) -> None:
405 async with async_client.beta.user_profiles.with_streaming_response.update(
406 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
407 ) as response:
408 assert not response.is_closed
409 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
410
411 user_profile = await response.parse()
412 assert_matches_type(BetaUserProfile, user_profile, path=["response"])
413
414 assert cast(Any, response.is_closed) is True
415
416 @parametrize
417 async def test_path_params_update(self, async_client: AsyncAnthropic) -> None:
418 with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_profile_id` but received ''"):
419 await async_client.beta.user_profiles.with_raw_response.update(
420 user_profile_id="",
421 )
422
423 @parametrize
424 async def test_method_list(self, async_client: AsyncAnthropic) -> None:
425 user_profile = await async_client.beta.user_profiles.list()
426 assert_matches_type(AsyncPageCursor[BetaUserProfile], user_profile, path=["response"])
427
428 @parametrize
429 async def test_method_list_with_all_params(self, async_client: AsyncAnthropic) -> None:
430 user_profile = await async_client.beta.user_profiles.list(
431 limit=0,
432 order="asc",
433 order_by="created_at",
434 page="page",
435 betas=["message-batches-2024-09-24"],
436 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
437 )
438 assert_matches_type(AsyncPageCursor[BetaUserProfile], user_profile, path=["response"])
439
440 @parametrize
441 async def test_raw_response_list(self, async_client: AsyncAnthropic) -> None:
442 response = await async_client.beta.user_profiles.with_raw_response.list()
443
444 assert response.is_closed is True
445 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
446 user_profile = await response.parse()
447 assert_matches_type(AsyncPageCursor[BetaUserProfile], user_profile, path=["response"])
448
449 @parametrize
450 async def test_streaming_response_list(self, async_client: AsyncAnthropic) -> None:
451 async with async_client.beta.user_profiles.with_streaming_response.list() as response:
452 assert not response.is_closed
453 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
454
455 user_profile = await response.parse()
456 assert_matches_type(AsyncPageCursor[BetaUserProfile], user_profile, path=["response"])
457
458 assert cast(Any, response.is_closed) is True
459
460 @parametrize
461 async def test_method_create_enrollment_url(self, async_client: AsyncAnthropic) -> None:
462 user_profile = await async_client.beta.user_profiles.create_enrollment_url(
463 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
464 )
465 assert_matches_type(BetaUserProfileEnrollmentURL, user_profile, path=["response"])
466
467 @parametrize
468 async def test_method_create_enrollment_url_with_all_params(self, async_client: AsyncAnthropic) -> None:
469 user_profile = await async_client.beta.user_profiles.create_enrollment_url(
470 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
471 betas=["message-batches-2024-09-24"],
472 workspace_id="wrkspc_011CZkZaBF1tNoB5wlCeusgy",
473 )
474 assert_matches_type(BetaUserProfileEnrollmentURL, user_profile, path=["response"])
475
476 @parametrize
477 async def test_raw_response_create_enrollment_url(self, async_client: AsyncAnthropic) -> None:
478 response = await async_client.beta.user_profiles.with_raw_response.create_enrollment_url(
479 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
480 )
481
482 assert response.is_closed is True
483 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
484 user_profile = await response.parse()
485 assert_matches_type(BetaUserProfileEnrollmentURL, user_profile, path=["response"])
486
487 @parametrize
488 async def test_streaming_response_create_enrollment_url(self, async_client: AsyncAnthropic) -> None:
489 async with async_client.beta.user_profiles.with_streaming_response.create_enrollment_url(
490 user_profile_id="uprof_011CZkZCu8hGbp5mYRQgUmz9",
491 ) as response:
492 assert not response.is_closed
493 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
494
495 user_profile = await response.parse()
496 assert_matches_type(BetaUserProfileEnrollmentURL, user_profile, path=["response"])
497
498 assert cast(Any, response.is_closed) is True
499
500 @parametrize
501 async def test_path_params_create_enrollment_url(self, async_client: AsyncAnthropic) -> None:
502 with pytest.raises(ValueError, match=r"Expected a non-empty value for `user_profile_id` but received ''"):
503 await async_client.beta.user_profiles.with_raw_response.create_enrollment_url(
504 user_profile_id="",
505 )