openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.97.2

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/vector_stores/test_file_batches.py

446lines · 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 SyncCursorPage, AsyncCursorPage
13from openai.types.vector_stores import (
14 VectorStoreFile,
15 VectorStoreFileBatch,
16)
17
18base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
19
20
21class TestFileBatches:
22 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 file_batch = client.vector_stores.file_batches.create(
27 vector_store_id="vs_abc123",
28 file_ids=["string"],
29 )
30 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
31
32 @parametrize
33 def test_method_create_with_all_params(self, client: OpenAI) -> None:
34 file_batch = client.vector_stores.file_batches.create(
35 vector_store_id="vs_abc123",
36 file_ids=["string"],
37 attributes={"foo": "string"},
38 chunking_strategy={"type": "auto"},
39 )
40 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
41
42 @parametrize
43 def test_raw_response_create(self, client: OpenAI) -> None:
44 response = client.vector_stores.file_batches.with_raw_response.create(
45 vector_store_id="vs_abc123",
46 file_ids=["string"],
47 )
48
49 assert response.is_closed is True
50 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
51 file_batch = response.parse()
52 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
53
54 @parametrize
55 def test_streaming_response_create(self, client: OpenAI) -> None:
56 with client.vector_stores.file_batches.with_streaming_response.create(
57 vector_store_id="vs_abc123",
58 file_ids=["string"],
59 ) as response:
60 assert not response.is_closed
61 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
62
63 file_batch = response.parse()
64 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
65
66 assert cast(Any, response.is_closed) is True
67
68 @parametrize
69 def test_path_params_create(self, client: OpenAI) -> None:
70 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
71 client.vector_stores.file_batches.with_raw_response.create(
72 vector_store_id="",
73 file_ids=["string"],
74 )
75
76 @parametrize
77 def test_method_retrieve(self, client: OpenAI) -> None:
78 file_batch = client.vector_stores.file_batches.retrieve(
79 batch_id="vsfb_abc123",
80 vector_store_id="vs_abc123",
81 )
82 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
83
84 @parametrize
85 def test_raw_response_retrieve(self, client: OpenAI) -> None:
86 response = client.vector_stores.file_batches.with_raw_response.retrieve(
87 batch_id="vsfb_abc123",
88 vector_store_id="vs_abc123",
89 )
90
91 assert response.is_closed is True
92 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
93 file_batch = response.parse()
94 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
95
96 @parametrize
97 def test_streaming_response_retrieve(self, client: OpenAI) -> None:
98 with client.vector_stores.file_batches.with_streaming_response.retrieve(
99 batch_id="vsfb_abc123",
100 vector_store_id="vs_abc123",
101 ) as response:
102 assert not response.is_closed
103 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
104
105 file_batch = response.parse()
106 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
107
108 assert cast(Any, response.is_closed) is True
109
110 @parametrize
111 def test_path_params_retrieve(self, client: OpenAI) -> None:
112 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
113 client.vector_stores.file_batches.with_raw_response.retrieve(
114 batch_id="vsfb_abc123",
115 vector_store_id="",
116 )
117
118 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
119 client.vector_stores.file_batches.with_raw_response.retrieve(
120 batch_id="",
121 vector_store_id="vs_abc123",
122 )
123
124 @parametrize
125 def test_method_cancel(self, client: OpenAI) -> None:
126 file_batch = client.vector_stores.file_batches.cancel(
127 batch_id="batch_id",
128 vector_store_id="vector_store_id",
129 )
130 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
131
132 @parametrize
133 def test_raw_response_cancel(self, client: OpenAI) -> None:
134 response = client.vector_stores.file_batches.with_raw_response.cancel(
135 batch_id="batch_id",
136 vector_store_id="vector_store_id",
137 )
138
139 assert response.is_closed is True
140 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
141 file_batch = response.parse()
142 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
143
144 @parametrize
145 def test_streaming_response_cancel(self, client: OpenAI) -> None:
146 with client.vector_stores.file_batches.with_streaming_response.cancel(
147 batch_id="batch_id",
148 vector_store_id="vector_store_id",
149 ) as response:
150 assert not response.is_closed
151 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
152
153 file_batch = response.parse()
154 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
155
156 assert cast(Any, response.is_closed) is True
157
158 @parametrize
159 def test_path_params_cancel(self, client: OpenAI) -> None:
160 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
161 client.vector_stores.file_batches.with_raw_response.cancel(
162 batch_id="batch_id",
163 vector_store_id="",
164 )
165
166 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
167 client.vector_stores.file_batches.with_raw_response.cancel(
168 batch_id="",
169 vector_store_id="vector_store_id",
170 )
171
172 @parametrize
173 def test_method_list_files(self, client: OpenAI) -> None:
174 file_batch = client.vector_stores.file_batches.list_files(
175 batch_id="batch_id",
176 vector_store_id="vector_store_id",
177 )
178 assert_matches_type(SyncCursorPage[VectorStoreFile], file_batch, path=["response"])
179
180 @parametrize
181 def test_method_list_files_with_all_params(self, client: OpenAI) -> None:
182 file_batch = client.vector_stores.file_batches.list_files(
183 batch_id="batch_id",
184 vector_store_id="vector_store_id",
185 after="after",
186 before="before",
187 filter="in_progress",
188 limit=0,
189 order="asc",
190 )
191 assert_matches_type(SyncCursorPage[VectorStoreFile], file_batch, path=["response"])
192
193 @parametrize
194 def test_raw_response_list_files(self, client: OpenAI) -> None:
195 response = client.vector_stores.file_batches.with_raw_response.list_files(
196 batch_id="batch_id",
197 vector_store_id="vector_store_id",
198 )
199
200 assert response.is_closed is True
201 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
202 file_batch = response.parse()
203 assert_matches_type(SyncCursorPage[VectorStoreFile], file_batch, path=["response"])
204
205 @parametrize
206 def test_streaming_response_list_files(self, client: OpenAI) -> None:
207 with client.vector_stores.file_batches.with_streaming_response.list_files(
208 batch_id="batch_id",
209 vector_store_id="vector_store_id",
210 ) as response:
211 assert not response.is_closed
212 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
213
214 file_batch = response.parse()
215 assert_matches_type(SyncCursorPage[VectorStoreFile], file_batch, path=["response"])
216
217 assert cast(Any, response.is_closed) is True
218
219 @parametrize
220 def test_path_params_list_files(self, client: OpenAI) -> None:
221 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
222 client.vector_stores.file_batches.with_raw_response.list_files(
223 batch_id="batch_id",
224 vector_store_id="",
225 )
226
227 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
228 client.vector_stores.file_batches.with_raw_response.list_files(
229 batch_id="",
230 vector_store_id="vector_store_id",
231 )
232
233
234class TestAsyncFileBatches:
235 parametrize = pytest.mark.parametrize(
236 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
237 )
238
239 @parametrize
240 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
241 file_batch = await async_client.vector_stores.file_batches.create(
242 vector_store_id="vs_abc123",
243 file_ids=["string"],
244 )
245 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
246
247 @parametrize
248 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
249 file_batch = await async_client.vector_stores.file_batches.create(
250 vector_store_id="vs_abc123",
251 file_ids=["string"],
252 attributes={"foo": "string"},
253 chunking_strategy={"type": "auto"},
254 )
255 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
256
257 @parametrize
258 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
259 response = await async_client.vector_stores.file_batches.with_raw_response.create(
260 vector_store_id="vs_abc123",
261 file_ids=["string"],
262 )
263
264 assert response.is_closed is True
265 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
266 file_batch = response.parse()
267 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
268
269 @parametrize
270 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
271 async with async_client.vector_stores.file_batches.with_streaming_response.create(
272 vector_store_id="vs_abc123",
273 file_ids=["string"],
274 ) as response:
275 assert not response.is_closed
276 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
277
278 file_batch = await response.parse()
279 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
280
281 assert cast(Any, response.is_closed) is True
282
283 @parametrize
284 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
285 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
286 await async_client.vector_stores.file_batches.with_raw_response.create(
287 vector_store_id="",
288 file_ids=["string"],
289 )
290
291 @parametrize
292 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
293 file_batch = await async_client.vector_stores.file_batches.retrieve(
294 batch_id="vsfb_abc123",
295 vector_store_id="vs_abc123",
296 )
297 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
298
299 @parametrize
300 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
301 response = await async_client.vector_stores.file_batches.with_raw_response.retrieve(
302 batch_id="vsfb_abc123",
303 vector_store_id="vs_abc123",
304 )
305
306 assert response.is_closed is True
307 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
308 file_batch = response.parse()
309 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
310
311 @parametrize
312 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
313 async with async_client.vector_stores.file_batches.with_streaming_response.retrieve(
314 batch_id="vsfb_abc123",
315 vector_store_id="vs_abc123",
316 ) as response:
317 assert not response.is_closed
318 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
319
320 file_batch = await response.parse()
321 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
322
323 assert cast(Any, response.is_closed) is True
324
325 @parametrize
326 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
327 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
328 await async_client.vector_stores.file_batches.with_raw_response.retrieve(
329 batch_id="vsfb_abc123",
330 vector_store_id="",
331 )
332
333 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
334 await async_client.vector_stores.file_batches.with_raw_response.retrieve(
335 batch_id="",
336 vector_store_id="vs_abc123",
337 )
338
339 @parametrize
340 async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
341 file_batch = await async_client.vector_stores.file_batches.cancel(
342 batch_id="batch_id",
343 vector_store_id="vector_store_id",
344 )
345 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
346
347 @parametrize
348 async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
349 response = await async_client.vector_stores.file_batches.with_raw_response.cancel(
350 batch_id="batch_id",
351 vector_store_id="vector_store_id",
352 )
353
354 assert response.is_closed is True
355 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
356 file_batch = response.parse()
357 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
358
359 @parametrize
360 async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
361 async with async_client.vector_stores.file_batches.with_streaming_response.cancel(
362 batch_id="batch_id",
363 vector_store_id="vector_store_id",
364 ) as response:
365 assert not response.is_closed
366 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
367
368 file_batch = await response.parse()
369 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
370
371 assert cast(Any, response.is_closed) is True
372
373 @parametrize
374 async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
375 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
376 await async_client.vector_stores.file_batches.with_raw_response.cancel(
377 batch_id="batch_id",
378 vector_store_id="",
379 )
380
381 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
382 await async_client.vector_stores.file_batches.with_raw_response.cancel(
383 batch_id="",
384 vector_store_id="vector_store_id",
385 )
386
387 @parametrize
388 async def test_method_list_files(self, async_client: AsyncOpenAI) -> None:
389 file_batch = await async_client.vector_stores.file_batches.list_files(
390 batch_id="batch_id",
391 vector_store_id="vector_store_id",
392 )
393 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
394
395 @parametrize
396 async def test_method_list_files_with_all_params(self, async_client: AsyncOpenAI) -> None:
397 file_batch = await async_client.vector_stores.file_batches.list_files(
398 batch_id="batch_id",
399 vector_store_id="vector_store_id",
400 after="after",
401 before="before",
402 filter="in_progress",
403 limit=0,
404 order="asc",
405 )
406 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
407
408 @parametrize
409 async def test_raw_response_list_files(self, async_client: AsyncOpenAI) -> None:
410 response = await async_client.vector_stores.file_batches.with_raw_response.list_files(
411 batch_id="batch_id",
412 vector_store_id="vector_store_id",
413 )
414
415 assert response.is_closed is True
416 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
417 file_batch = response.parse()
418 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
419
420 @parametrize
421 async def test_streaming_response_list_files(self, async_client: AsyncOpenAI) -> None:
422 async with async_client.vector_stores.file_batches.with_streaming_response.list_files(
423 batch_id="batch_id",
424 vector_store_id="vector_store_id",
425 ) as response:
426 assert not response.is_closed
427 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
428
429 file_batch = await response.parse()
430 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
431
432 assert cast(Any, response.is_closed) is True
433
434 @parametrize
435 async def test_path_params_list_files(self, async_client: AsyncOpenAI) -> None:
436 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
437 await async_client.vector_stores.file_batches.with_raw_response.list_files(
438 batch_id="batch_id",
439 vector_store_id="",
440 )
441
442 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
443 await async_client.vector_stores.file_batches.with_raw_response.list_files(
444 batch_id="",
445 vector_store_id="vector_store_id",
446 )
447