openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.21.2

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

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