openai/openai-python

Public

mirrored fromhttps://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dev/dkundel/audio-helpers

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/vector_stores/test_files.py

625lines · 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("async_client", [False, True], indirect=True, ids=["loose", "strict"])
327
328 @parametrize
329 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
330 file = await async_client.vector_stores.files.create(
331 vector_store_id="vs_abc123",
332 file_id="file_id",
333 )
334 assert_matches_type(VectorStoreFile, file, path=["response"])
335
336 @parametrize
337 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
338 file = await async_client.vector_stores.files.create(
339 vector_store_id="vs_abc123",
340 file_id="file_id",
341 attributes={"foo": "string"},
342 chunking_strategy={"type": "auto"},
343 )
344 assert_matches_type(VectorStoreFile, file, path=["response"])
345
346 @parametrize
347 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
348 response = await async_client.vector_stores.files.with_raw_response.create(
349 vector_store_id="vs_abc123",
350 file_id="file_id",
351 )
352
353 assert response.is_closed is True
354 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
355 file = response.parse()
356 assert_matches_type(VectorStoreFile, file, path=["response"])
357
358 @parametrize
359 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
360 async with async_client.vector_stores.files.with_streaming_response.create(
361 vector_store_id="vs_abc123",
362 file_id="file_id",
363 ) as response:
364 assert not response.is_closed
365 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
366
367 file = await response.parse()
368 assert_matches_type(VectorStoreFile, file, path=["response"])
369
370 assert cast(Any, response.is_closed) is True
371
372 @parametrize
373 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
374 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
375 await async_client.vector_stores.files.with_raw_response.create(
376 vector_store_id="",
377 file_id="file_id",
378 )
379
380 @parametrize
381 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
382 file = await async_client.vector_stores.files.retrieve(
383 file_id="file-abc123",
384 vector_store_id="vs_abc123",
385 )
386 assert_matches_type(VectorStoreFile, file, path=["response"])
387
388 @parametrize
389 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
390 response = await async_client.vector_stores.files.with_raw_response.retrieve(
391 file_id="file-abc123",
392 vector_store_id="vs_abc123",
393 )
394
395 assert response.is_closed is True
396 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
397 file = response.parse()
398 assert_matches_type(VectorStoreFile, file, path=["response"])
399
400 @parametrize
401 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
402 async with async_client.vector_stores.files.with_streaming_response.retrieve(
403 file_id="file-abc123",
404 vector_store_id="vs_abc123",
405 ) as response:
406 assert not response.is_closed
407 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
408
409 file = await response.parse()
410 assert_matches_type(VectorStoreFile, file, path=["response"])
411
412 assert cast(Any, response.is_closed) is True
413
414 @parametrize
415 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
416 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
417 await async_client.vector_stores.files.with_raw_response.retrieve(
418 file_id="file-abc123",
419 vector_store_id="",
420 )
421
422 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
423 await async_client.vector_stores.files.with_raw_response.retrieve(
424 file_id="",
425 vector_store_id="vs_abc123",
426 )
427
428 @parametrize
429 async def test_method_update(self, async_client: AsyncOpenAI) -> None:
430 file = await async_client.vector_stores.files.update(
431 file_id="file-abc123",
432 vector_store_id="vs_abc123",
433 attributes={"foo": "string"},
434 )
435 assert_matches_type(VectorStoreFile, file, path=["response"])
436
437 @parametrize
438 async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None:
439 response = await async_client.vector_stores.files.with_raw_response.update(
440 file_id="file-abc123",
441 vector_store_id="vs_abc123",
442 attributes={"foo": "string"},
443 )
444
445 assert response.is_closed is True
446 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
447 file = response.parse()
448 assert_matches_type(VectorStoreFile, file, path=["response"])
449
450 @parametrize
451 async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None:
452 async with async_client.vector_stores.files.with_streaming_response.update(
453 file_id="file-abc123",
454 vector_store_id="vs_abc123",
455 attributes={"foo": "string"},
456 ) as response:
457 assert not response.is_closed
458 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
459
460 file = await response.parse()
461 assert_matches_type(VectorStoreFile, file, path=["response"])
462
463 assert cast(Any, response.is_closed) is True
464
465 @parametrize
466 async def test_path_params_update(self, async_client: AsyncOpenAI) -> None:
467 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
468 await async_client.vector_stores.files.with_raw_response.update(
469 file_id="file-abc123",
470 vector_store_id="",
471 attributes={"foo": "string"},
472 )
473
474 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
475 await async_client.vector_stores.files.with_raw_response.update(
476 file_id="",
477 vector_store_id="vs_abc123",
478 attributes={"foo": "string"},
479 )
480
481 @parametrize
482 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
483 file = await async_client.vector_stores.files.list(
484 vector_store_id="vector_store_id",
485 )
486 assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"])
487
488 @parametrize
489 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
490 file = await async_client.vector_stores.files.list(
491 vector_store_id="vector_store_id",
492 after="after",
493 before="before",
494 filter="in_progress",
495 limit=0,
496 order="asc",
497 )
498 assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"])
499
500 @parametrize
501 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
502 response = await async_client.vector_stores.files.with_raw_response.list(
503 vector_store_id="vector_store_id",
504 )
505
506 assert response.is_closed is True
507 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
508 file = response.parse()
509 assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"])
510
511 @parametrize
512 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
513 async with async_client.vector_stores.files.with_streaming_response.list(
514 vector_store_id="vector_store_id",
515 ) as response:
516 assert not response.is_closed
517 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
518
519 file = await response.parse()
520 assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"])
521
522 assert cast(Any, response.is_closed) is True
523
524 @parametrize
525 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
526 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
527 await async_client.vector_stores.files.with_raw_response.list(
528 vector_store_id="",
529 )
530
531 @parametrize
532 async def test_method_delete(self, async_client: AsyncOpenAI) -> None:
533 file = await async_client.vector_stores.files.delete(
534 file_id="file_id",
535 vector_store_id="vector_store_id",
536 )
537 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
538
539 @parametrize
540 async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None:
541 response = await async_client.vector_stores.files.with_raw_response.delete(
542 file_id="file_id",
543 vector_store_id="vector_store_id",
544 )
545
546 assert response.is_closed is True
547 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
548 file = response.parse()
549 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
550
551 @parametrize
552 async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None:
553 async with async_client.vector_stores.files.with_streaming_response.delete(
554 file_id="file_id",
555 vector_store_id="vector_store_id",
556 ) as response:
557 assert not response.is_closed
558 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
559
560 file = await response.parse()
561 assert_matches_type(VectorStoreFileDeleted, file, path=["response"])
562
563 assert cast(Any, response.is_closed) is True
564
565 @parametrize
566 async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None:
567 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
568 await async_client.vector_stores.files.with_raw_response.delete(
569 file_id="file_id",
570 vector_store_id="",
571 )
572
573 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
574 await async_client.vector_stores.files.with_raw_response.delete(
575 file_id="",
576 vector_store_id="vector_store_id",
577 )
578
579 @parametrize
580 async def test_method_content(self, async_client: AsyncOpenAI) -> None:
581 file = await async_client.vector_stores.files.content(
582 file_id="file-abc123",
583 vector_store_id="vs_abc123",
584 )
585 assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"])
586
587 @parametrize
588 async def test_raw_response_content(self, async_client: AsyncOpenAI) -> None:
589 response = await async_client.vector_stores.files.with_raw_response.content(
590 file_id="file-abc123",
591 vector_store_id="vs_abc123",
592 )
593
594 assert response.is_closed is True
595 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
596 file = response.parse()
597 assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"])
598
599 @parametrize
600 async def test_streaming_response_content(self, async_client: AsyncOpenAI) -> None:
601 async with async_client.vector_stores.files.with_streaming_response.content(
602 file_id="file-abc123",
603 vector_store_id="vs_abc123",
604 ) as response:
605 assert not response.is_closed
606 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
607
608 file = await response.parse()
609 assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"])
610
611 assert cast(Any, response.is_closed) is True
612
613 @parametrize
614 async def test_path_params_content(self, async_client: AsyncOpenAI) -> None:
615 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
616 await async_client.vector_stores.files.with_raw_response.content(
617 file_id="file-abc123",
618 vector_store_id="",
619 )
620
621 with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"):
622 await async_client.vector_stores.files.with_raw_response.content(
623 file_id="",
624 vector_store_id="vs_abc123",
625 )
626