Debian Codegraph @

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