openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.91.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/vector_stores/test_files.py

627lines · modecode

1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncPage, AsyncPage, SyncCursorPage, AsyncCursorPage
13from openai.types.vector_stores import (
14 VectorStoreFile,
15 FileContentResponse,
16 VectorStoreFileDeleted,
17)
18
19base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
20
21
22class TestFiles:
23 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
24
25 @parametrize
26 def test_method_create(self, client: OpenAI) -> None:
27 file = client.vector_stores.files.create(
28 vector_store_id="vs_abc123",
29 file_id="file_id",
30 )
31 assert_matches_type(VectorStoreFile, file, path=["response"])
32
33 @parametrize
34 def test_method_create_with_all_params(self, client: OpenAI) -> None:
35 file = client.vector_stores.files.create(
36 vector_store_id="vs_abc123",
37 file_id="file_id",
38 attributes={"foo": "string"},
39 chunking_strategy={"type": "auto"},
40 )
41 assert_matches_type(VectorStoreFile, file, path=["response"])
42
43 @parametrize
44 def test_raw_response_create(self, client: OpenAI) -> None:
45 response = client.vector_stores.files.with_raw_response.create(
46 vector_store_id="vs_abc123",
47 file_id="file_id",
48 )
49
50 assert response.is_closed is True
51 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
52 file = response.parse()
53 assert_matches_type(VectorStoreFile, file, path=["response"])
54
55 @parametrize
56 def test_streaming_response_create(self, client: OpenAI) -> None:
57 with client.vector_stores.files.with_streaming_response.create(
58 vector_store_id="vs_abc123",
59 file_id="file_id",
60 ) as response:
61 assert not response.is_closed
62 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
63
64 file = response.parse()
65 assert_matches_type(VectorStoreFile, file, path=["response"])
66
67 assert cast(Any, response.is_closed) is True
68
69 @parametrize
70 def test_path_params_create(self, client: OpenAI) -> None:
71 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
72 client.vector_stores.files.with_raw_response.create(
73 vector_store_id="",
74 file_id="file_id",
75 )
76
77 @parametrize
78 def test_method_retrieve(self, client: OpenAI) -> None:
79 file = client.vector_stores.files.retrieve(
80 file_id="file-abc123",
81 vector_store_id="vs_abc123",
82 )
83 assert_matches_type(VectorStoreFile, file, path=["response"])
84
85 @parametrize
86 def test_raw_response_retrieve(self, client: OpenAI) -> None:
87 response = client.vector_stores.files.with_raw_response.retrieve(
88 file_id="file-abc123",
89 vector_store_id="vs_abc123",
90 )
91
92 assert response.is_closed is True
93 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
94 file = response.parse()
95 assert_matches_type(VectorStoreFile, file, path=["response"])
96
97 @parametrize
98 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
99 with client.vector_stores.files.with_streaming_response.retrieve(
100 file_id="file-abc123",
101 vector_store_id="vs_abc123",
102 ) as response:
103 assert not response.is_closed
104 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
105
106 file = response.parse()
107 assert_matches_type(VectorStoreFile, file, path=["response"])
108
109 assert cast(Any, response.is_closed) is True
110
111 @parametrize
112 def test_path_params_retrieve(self, client: OpenAI) -> None:
113 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
114 client.vector_stores.files.with_raw_response.retrieve(
115 file_id="file-abc123",
116 vector_store_id="",
117 )
118
119 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
120 client.vector_stores.files.with_raw_response.retrieve(
121 file_id="",
122 vector_store_id="vs_abc123",
123 )
124
125 @parametrize
126 def test_method_update(self, client: OpenAI) -> None:
127 file = client.vector_stores.files.update(
128 file_id="file-abc123",
129 vector_store_id="vs_abc123",
130 attributes={"foo": "string"},
131 )
132 assert_matches_type(VectorStoreFile, file, path=["response"])
133
134 @parametrize
135 def test_raw_response_update(self, client: OpenAI) -> None:
136 response = client.vector_stores.files.with_raw_response.update(
137 file_id="file-abc123",
138 vector_store_id="vs_abc123",
139 attributes={"foo": "string"},
140 )
141
142 assert response.is_closed is True
143 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
144 file = response.parse()
145 assert_matches_type(VectorStoreFile, file, path=["response"])
146
147 @parametrize
148 def test_streaming_response_update(self, client: OpenAI) -> None:
149 with client.vector_stores.files.with_streaming_response.update(
150 file_id="file-abc123",
151 vector_store_id="vs_abc123",
152 attributes={"foo": "string"},
153 ) as response:
154 assert not response.is_closed
155 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
156
157 file = response.parse()
158 assert_matches_type(VectorStoreFile, file, path=["response"])
159
160 assert cast(Any, response.is_closed) is True
161
162 @parametrize
163 def test_path_params_update(self, client: OpenAI) -> None:
164 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
165 client.vector_stores.files.with_raw_response.update(
166 file_id="file-abc123",
167 vector_store_id="",
168 attributes={"foo": "string"},
169 )
170
171 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
172 client.vector_stores.files.with_raw_response.update(
173 file_id="",
174 vector_store_id="vs_abc123",
175 attributes={"foo": "string"},
176 )
177
178 @parametrize
179 def test_method_list(self, client: OpenAI) -> None:
180 file = client.vector_stores.files.list(
181 vector_store_id="vector_store_id",
182 )
183 assert_matches_type(SyncCursorPage[VectorStoreFile], file, path=["response"])
184
185 @parametrize
186 def test_method_list_with_all_params(self, client: OpenAI) -> None:
187 file = client.vector_stores.files.list(
188 vector_store_id="vector_store_id",
189 after="after",
190 before="before",
191 filter="in_progress",
192 limit=0,
193 order="asc",
194 )
195 assert_matches_type(SyncCursorPage[VectorStoreFile], file, path=["response"])
196
197 @parametrize
198 def test_raw_response_list(self, client: OpenAI) -> None:
199 response = client.vector_stores.files.with_raw_response.list(
200 vector_store_id="vector_store_id",
201 )
202
203 assert response.is_closed is True
204 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
205 file = response.parse()
206 assert_matches_type(SyncCursorPage[VectorStoreFile], file, path=["response"])
207
208 @parametrize
209 def test_streaming_response_list(self, client: OpenAI) -> None:
210 with client.vector_stores.files.with_streaming_response.list(
211 vector_store_id="vector_store_id",
212 ) as response:
213 assert not response.is_closed
214 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
215
216 file = response.parse()
217 assert_matches_type(SyncCursorPage[VectorStoreFile], file, path=["response"])
218
219 assert cast(Any, response.is_closed) is True
220
221 @parametrize
222 def test_path_params_list(self, client: OpenAI) -> None:
223 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
224 client.vector_stores.files.with_raw_response.list(
225 vector_store_id="",
226 )
227
228 @parametrize
229 def test_method_delete(self, client: OpenAI) -> None:
230 file = client.vector_stores.files.delete(
231 file_id="file_id",
232 vector_store_id="vector_store_id",
233 )
234 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
235
236 @parametrize
237 def test_raw_response_delete(self, client: OpenAI) -> None:
238 response = client.vector_stores.files.with_raw_response.delete(
239 file_id="file_id",
240 vector_store_id="vector_store_id",
241 )
242
243 assert response.is_closed is True
244 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
245 file = response.parse()
246 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
247
248 @parametrize
249 def test_streaming_response_delete(self, client: OpenAI) -> None:
250 with client.vector_stores.files.with_streaming_response.delete(
251 file_id="file_id",
252 vector_store_id="vector_store_id",
253 ) as response:
254 assert not response.is_closed
255 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
256
257 file = response.parse()
258 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
259
260 assert cast(Any, response.is_closed) is True
261
262 @parametrize
263 def test_path_params_delete(self, client: OpenAI) -> None:
264 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
265 client.vector_stores.files.with_raw_response.delete(
266 file_id="file_id",
267 vector_store_id="",
268 )
269
270 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
271 client.vector_stores.files.with_raw_response.delete(
272 file_id="",
273 vector_store_id="vector_store_id",
274 )
275
276 @parametrize
277 def test_method_content(self, client: OpenAI) -> None:
278 file = client.vector_stores.files.content(
279 file_id="file-abc123",
280 vector_store_id="vs_abc123",
281 )
282 assert_matches_type(SyncPage[FileContentResponse], file, path=["response"])
283
284 @parametrize
285 def test_raw_response_content(self, client: OpenAI) -> None:
286 response = client.vector_stores.files.with_raw_response.content(
287 file_id="file-abc123",
288 vector_store_id="vs_abc123",
289 )
290
291 assert response.is_closed is True
292 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
293 file = response.parse()
294 assert_matches_type(SyncPage[FileContentResponse], file, path=["response"])
295
296 @parametrize
297 def test_streaming_response_content(self, client: OpenAI) -> None:
298 with client.vector_stores.files.with_streaming_response.content(
299 file_id="file-abc123",
300 vector_store_id="vs_abc123",
301 ) as response:
302 assert not response.is_closed
303 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
304
305 file = response.parse()
306 assert_matches_type(SyncPage[FileContentResponse], file, path=["response"])
307
308 assert cast(Any, response.is_closed) is True
309
310 @parametrize
311 def test_path_params_content(self, client: OpenAI) -> None:
312 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
313 client.vector_stores.files.with_raw_response.content(
314 file_id="file-abc123",
315 vector_store_id="",
316 )
317
318 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
319 client.vector_stores.files.with_raw_response.content(
320 file_id="",
321 vector_store_id="vs_abc123",
322 )
323
324
325class TestAsyncFiles:
326 parametrize = pytest.mark.parametrize(
327 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
328 )
329
330 @parametrize
331 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
332 file = await async_client.vector_stores.files.create(
333 vector_store_id="vs_abc123",
334 file_id="file_id",
335 )
336 assert_matches_type(VectorStoreFile, file, path=["response"])
337
338 @parametrize
339 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
340 file = await async_client.vector_stores.files.create(
341 vector_store_id="vs_abc123",
342 file_id="file_id",
343 attributes={"foo": "string"},
344 chunking_strategy={"type": "auto"},
345 )
346 assert_matches_type(VectorStoreFile, file, path=["response"])
347
348 @parametrize
349 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
350 response = await async_client.vector_stores.files.with_raw_response.create(
351 vector_store_id="vs_abc123",
352 file_id="file_id",
353 )
354
355 assert response.is_closed is True
356 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
357 file = response.parse()
358 assert_matches_type(VectorStoreFile, file, path=["response"])
359
360 @parametrize
361 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
362 async with async_client.vector_stores.files.with_streaming_response.create(
363 vector_store_id="vs_abc123",
364 file_id="file_id",
365 ) as response:
366 assert not response.is_closed
367 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
368
369 file = await response.parse()
370 assert_matches_type(VectorStoreFile, file, path=["response"])
371
372 assert cast(Any, response.is_closed) is True
373
374 @parametrize
375 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
376 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
377 await async_client.vector_stores.files.with_raw_response.create(
378 vector_store_id="",
379 file_id="file_id",
380 )
381
382 @parametrize
383 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
384 file = await async_client.vector_stores.files.retrieve(
385 file_id="file-abc123",
386 vector_store_id="vs_abc123",
387 )
388 assert_matches_type(VectorStoreFile, file, path=["response"])
389
390 @parametrize
391 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
392 response = await async_client.vector_stores.files.with_raw_response.retrieve(
393 file_id="file-abc123",
394 vector_store_id="vs_abc123",
395 )
396
397 assert response.is_closed is True
398 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
399 file = response.parse()
400 assert_matches_type(VectorStoreFile, file, path=["response"])
401
402 @parametrize
403 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
404 async with async_client.vector_stores.files.with_streaming_response.retrieve(
405 file_id="file-abc123",
406 vector_store_id="vs_abc123",
407 ) as response:
408 assert not response.is_closed
409 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
410
411 file = await response.parse()
412 assert_matches_type(VectorStoreFile, file, path=["response"])
413
414 assert cast(Any, response.is_closed) is True
415
416 @parametrize
417 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
418 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
419 await async_client.vector_stores.files.with_raw_response.retrieve(
420 file_id="file-abc123",
421 vector_store_id="",
422 )
423
424 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
425 await async_client.vector_stores.files.with_raw_response.retrieve(
426 file_id="",
427 vector_store_id="vs_abc123",
428 )
429
430 @parametrize
431 async def test_method_update(self, async_client: AsyncOpenAI) -> None:
432 file = await async_client.vector_stores.files.update(
433 file_id="file-abc123",
434 vector_store_id="vs_abc123",
435 attributes={"foo": "string"},
436 )
437 assert_matches_type(VectorStoreFile, file, path=["response"])
438
439 @parametrize
440 async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
441 response = await async_client.vector_stores.files.with_raw_response.update(
442 file_id="file-abc123",
443 vector_store_id="vs_abc123",
444 attributes={"foo": "string"},
445 )
446
447 assert response.is_closed is True
448 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
449 file = response.parse()
450 assert_matches_type(VectorStoreFile, file, path=["response"])
451
452 @parametrize
453 async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
454 async with async_client.vector_stores.files.with_streaming_response.update(
455 file_id="file-abc123",
456 vector_store_id="vs_abc123",
457 attributes={"foo": "string"},
458 ) as response:
459 assert not response.is_closed
460 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
461
462 file = await response.parse()
463 assert_matches_type(VectorStoreFile, file, path=["response"])
464
465 assert cast(Any, response.is_closed) is True
466
467 @parametrize
468 async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
469 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
470 await async_client.vector_stores.files.with_raw_response.update(
471 file_id="file-abc123",
472 vector_store_id="",
473 attributes={"foo": "string"},
474 )
475
476 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
477 await async_client.vector_stores.files.with_raw_response.update(
478 file_id="",
479 vector_store_id="vs_abc123",
480 attributes={"foo": "string"},
481 )
482
483 @parametrize
484 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
485 file = await async_client.vector_stores.files.list(
486 vector_store_id="vector_store_id",
487 )
488 assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"])
489
490 @parametrize
491 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
492 file = await async_client.vector_stores.files.list(
493 vector_store_id="vector_store_id",
494 after="after",
495 before="before",
496 filter="in_progress",
497 limit=0,
498 order="asc",
499 )
500 assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"])
501
502 @parametrize
503 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
504 response = await async_client.vector_stores.files.with_raw_response.list(
505 vector_store_id="vector_store_id",
506 )
507
508 assert response.is_closed is True
509 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
510 file = response.parse()
511 assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"])
512
513 @parametrize
514 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
515 async with async_client.vector_stores.files.with_streaming_response.list(
516 vector_store_id="vector_store_id",
517 ) as response:
518 assert not response.is_closed
519 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
520
521 file = await response.parse()
522 assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"])
523
524 assert cast(Any, response.is_closed) is True
525
526 @parametrize
527 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
528 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
529 await async_client.vector_stores.files.with_raw_response.list(
530 vector_store_id="",
531 )
532
533 @parametrize
534 async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
535 file = await async_client.vector_stores.files.delete(
536 file_id="file_id",
537 vector_store_id="vector_store_id",
538 )
539 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
540
541 @parametrize
542 async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
543 response = await async_client.vector_stores.files.with_raw_response.delete(
544 file_id="file_id",
545 vector_store_id="vector_store_id",
546 )
547
548 assert response.is_closed is True
549 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
550 file = response.parse()
551 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
552
553 @parametrize
554 async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
555 async with async_client.vector_stores.files.with_streaming_response.delete(
556 file_id="file_id",
557 vector_store_id="vector_store_id",
558 ) as response:
559 assert not response.is_closed
560 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
561
562 file = await response.parse()
563 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
564
565 assert cast(Any, response.is_closed) is True
566
567 @parametrize
568 async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
569 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
570 await async_client.vector_stores.files.with_raw_response.delete(
571 file_id="file_id",
572 vector_store_id="",
573 )
574
575 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
576 await async_client.vector_stores.files.with_raw_response.delete(
577 file_id="",
578 vector_store_id="vector_store_id",
579 )
580
581 @parametrize
582 async def test_method_content(self, async_client: AsyncOpenAI) -> None:
583 file = await async_client.vector_stores.files.content(
584 file_id="file-abc123",
585 vector_store_id="vs_abc123",
586 )
587 assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"])
588
589 @parametrize
590 async def test_raw_response_content(self, async_client: AsyncOpenAI) -> None:
591 response = await async_client.vector_stores.files.with_raw_response.content(
592 file_id="file-abc123",
593 vector_store_id="vs_abc123",
594 )
595
596 assert response.is_closed is True
597 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
598 file = response.parse()
599 assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"])
600
601 @parametrize
602 async def test_streaming_response_content(self, async_client: AsyncOpenAI) -> None:
603 async with async_client.vector_stores.files.with_streaming_response.content(
604 file_id="file-abc123",
605 vector_store_id="vs_abc123",
606 ) as response:
607 assert not response.is_closed
608 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
609
610 file = await response.parse()
611 assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"])
612
613 assert cast(Any, response.is_closed) is True
614
615 @parametrize
616 async def test_path_params_content(self, async_client: AsyncOpenAI) -> None:
617 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
618 await async_client.vector_stores.files.with_raw_response.content(
619 file_id="file-abc123",
620 vector_store_id="",
621 )
622
623 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
624 await async_client.vector_stores.files.with_raw_response.content(
625 file_id="",
626 vector_store_id="vs_abc123",
627 )
628