Debian Codegraph @

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