openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
dfdcf571ced31f7859cd1871be39e2fb3af6bafa

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/vector_stores/test_files.py

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