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_file_batches.py

444lines · 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("async_client", [False, True], indirect=True, ids=["loose", "strict"])
236
237 @parametrize
238 async def test_method_create(self, async_client: AsyncOpenAI) -> None:
239 file_batch = await async_client.vector_stores.file_batches.create(
240 vector_store_id="vs_abc123",
241 file_ids=["string"],
242 )
243 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
244
245 @parametrize
246 async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None:
247 file_batch = await async_client.vector_stores.file_batches.create(
248 vector_store_id="vs_abc123",
249 file_ids=["string"],
250 attributes={"foo": "string"},
251 chunking_strategy={"type": "auto"},
252 )
253 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
254
255 @parametrize
256 async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None:
257 response = await async_client.vector_stores.file_batches.with_raw_response.create(
258 vector_store_id="vs_abc123",
259 file_ids=["string"],
260 )
261
262 assert response.is_closed is True
263 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
264 file_batch = response.parse()
265 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
266
267 @parametrize
268 async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None:
269 async with async_client.vector_stores.file_batches.with_streaming_response.create(
270 vector_store_id="vs_abc123",
271 file_ids=["string"],
272 ) as response:
273 assert not response.is_closed
274 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
275
276 file_batch = await response.parse()
277 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
278
279 assert cast(Any, response.is_closed) is True
280
281 @parametrize
282 async def test_path_params_create(self, async_client: AsyncOpenAI) -> None:
283 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
284 await async_client.vector_stores.file_batches.with_raw_response.create(
285 vector_store_id="",
286 file_ids=["string"],
287 )
288
289 @parametrize
290 async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None:
291 file_batch = await async_client.vector_stores.file_batches.retrieve(
292 batch_id="vsfb_abc123",
293 vector_store_id="vs_abc123",
294 )
295 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
296
297 @parametrize
298 async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None:
299 response = await async_client.vector_stores.file_batches.with_raw_response.retrieve(
300 batch_id="vsfb_abc123",
301 vector_store_id="vs_abc123",
302 )
303
304 assert response.is_closed is True
305 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
306 file_batch = response.parse()
307 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
308
309 @parametrize
310 async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None:
311 async with async_client.vector_stores.file_batches.with_streaming_response.retrieve(
312 batch_id="vsfb_abc123",
313 vector_store_id="vs_abc123",
314 ) as response:
315 assert not response.is_closed
316 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
317
318 file_batch = await response.parse()
319 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
320
321 assert cast(Any, response.is_closed) is True
322
323 @parametrize
324 async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None:
325 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
326 await async_client.vector_stores.file_batches.with_raw_response.retrieve(
327 batch_id="vsfb_abc123",
328 vector_store_id="",
329 )
330
331 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
332 await async_client.vector_stores.file_batches.with_raw_response.retrieve(
333 batch_id="",
334 vector_store_id="vs_abc123",
335 )
336
337 @parametrize
338 async def test_method_cancel(self, async_client: AsyncOpenAI) -> None:
339 file_batch = await async_client.vector_stores.file_batches.cancel(
340 batch_id="batch_id",
341 vector_store_id="vector_store_id",
342 )
343 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
344
345 @parametrize
346 async def test_raw_response_cancel(self, async_client: AsyncOpenAI) -> None:
347 response = await async_client.vector_stores.file_batches.with_raw_response.cancel(
348 batch_id="batch_id",
349 vector_store_id="vector_store_id",
350 )
351
352 assert response.is_closed is True
353 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
354 file_batch = response.parse()
355 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
356
357 @parametrize
358 async def test_streaming_response_cancel(self, async_client: AsyncOpenAI) -> None:
359 async with async_client.vector_stores.file_batches.with_streaming_response.cancel(
360 batch_id="batch_id",
361 vector_store_id="vector_store_id",
362 ) as response:
363 assert not response.is_closed
364 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
365
366 file_batch = await response.parse()
367 assert_matches_type(VectorStoreFileBatch, file_batch, path=["response"])
368
369 assert cast(Any, response.is_closed) is True
370
371 @parametrize
372 async def test_path_params_cancel(self, async_client: AsyncOpenAI) -> None:
373 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
374 await async_client.vector_stores.file_batches.with_raw_response.cancel(
375 batch_id="batch_id",
376 vector_store_id="",
377 )
378
379 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
380 await async_client.vector_stores.file_batches.with_raw_response.cancel(
381 batch_id="",
382 vector_store_id="vector_store_id",
383 )
384
385 @parametrize
386 async def test_method_list_files(self, async_client: AsyncOpenAI) -> None:
387 file_batch = await async_client.vector_stores.file_batches.list_files(
388 batch_id="batch_id",
389 vector_store_id="vector_store_id",
390 )
391 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
392
393 @parametrize
394 async def test_method_list_files_with_all_params(self, async_client: AsyncOpenAI) -> None:
395 file_batch = await async_client.vector_stores.file_batches.list_files(
396 batch_id="batch_id",
397 vector_store_id="vector_store_id",
398 after="after",
399 before="before",
400 filter="in_progress",
401 limit=0,
402 order="asc",
403 )
404 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
405
406 @parametrize
407 async def test_raw_response_list_files(self, async_client: AsyncOpenAI) -> None:
408 response = await async_client.vector_stores.file_batches.with_raw_response.list_files(
409 batch_id="batch_id",
410 vector_store_id="vector_store_id",
411 )
412
413 assert response.is_closed is True
414 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
415 file_batch = response.parse()
416 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
417
418 @parametrize
419 async def test_streaming_response_list_files(self, async_client: AsyncOpenAI) -> None:
420 async with async_client.vector_stores.file_batches.with_streaming_response.list_files(
421 batch_id="batch_id",
422 vector_store_id="vector_store_id",
423 ) as response:
424 assert not response.is_closed
425 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
426
427 file_batch = await response.parse()
428 assert_matches_type(AsyncCursorPage[VectorStoreFile], file_batch, path=["response"])
429
430 assert cast(Any, response.is_closed) is True
431
432 @parametrize
433 async def test_path_params_list_files(self, async_client: AsyncOpenAI) -> None:
434 with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"):
435 await async_client.vector_stores.file_batches.with_raw_response.list_files(
436 batch_id="batch_id",
437 vector_store_id="",
438 )
439
440 with pytest.raises(ValueError, match=r"Expected a non-empty value for `batch_id` but received ''"):
441 await async_client.vector_stores.file_batches.with_raw_response.list_files(
442 batch_id="",
443 vector_store_id="vector_store_id",
444 )
445