openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
tests/api_resources/vector_stores/test_files.py
650lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | from typing import Any, cast |
| 7 | |
| 8 | import pytest |
| 9 | |
| 10 | from openai import OpenAI, AsyncOpenAI |
| 11 | from tests.utils import assert_matches_type |
| 12 | from openai._utils import assert_signatures_in_sync |
| 13 | from openai.pagination import SyncPage, AsyncPage, SyncCursorPage, AsyncCursorPage |
| 14 | from openai.types.vector_stores import ( |
| 15 | VectorStoreFile, |
| 16 | FileContentResponse, |
| 17 | VectorStoreFileDeleted, |
| 18 | ) |
| 19 | |
| 20 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 21 | |
| 22 | |
| 23 | class TestFiles: |
| 24 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 25 | |
| 26 | @parametrize |
| 27 | def test_method_create(self, client: OpenAI) -> None: |
| 28 | file = client.vector_stores.files.create( |
| 29 | vector_store_id="vs_abc123", |
| 30 | file_id="file_id", |
| 31 | ) |
| 32 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 33 | |
| 34 | @parametrize |
| 35 | def test_method_create_with_all_params(self, client: OpenAI) -> None: |
| 36 | file = client.vector_stores.files.create( |
| 37 | vector_store_id="vs_abc123", |
| 38 | file_id="file_id", |
| 39 | attributes={"foo": "string"}, |
| 40 | chunking_strategy={"type": "auto"}, |
| 41 | ) |
| 42 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 43 | |
| 44 | @parametrize |
| 45 | def test_raw_response_create(self, client: OpenAI) -> None: |
| 46 | response = client.vector_stores.files.with_raw_response.create( |
| 47 | vector_store_id="vs_abc123", |
| 48 | file_id="file_id", |
| 49 | ) |
| 50 | |
| 51 | assert response.is_closed is True |
| 52 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 53 | file = response.parse() |
| 54 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 55 | |
| 56 | @parametrize |
| 57 | def test_streaming_response_create(self, client: OpenAI) -> None: |
| 58 | with client.vector_stores.files.with_streaming_response.create( |
| 59 | vector_store_id="vs_abc123", |
| 60 | file_id="file_id", |
| 61 | ) as response: |
| 62 | assert not response.is_closed |
| 63 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 64 | |
| 65 | file = response.parse() |
| 66 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 67 | |
| 68 | assert cast(Any, response.is_closed) is True |
| 69 | |
| 70 | @parametrize |
| 71 | def test_path_params_create(self, client: OpenAI) -> None: |
| 72 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 73 | client.vector_stores.files.with_raw_response.create( |
| 74 | vector_store_id="", |
| 75 | file_id="file_id", |
| 76 | ) |
| 77 | |
| 78 | @parametrize |
| 79 | def test_method_retrieve(self, client: OpenAI) -> None: |
| 80 | file = client.vector_stores.files.retrieve( |
| 81 | file_id="file-abc123", |
| 82 | vector_store_id="vs_abc123", |
| 83 | ) |
| 84 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 85 | |
| 86 | @parametrize |
| 87 | def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 88 | response = client.vector_stores.files.with_raw_response.retrieve( |
| 89 | file_id="file-abc123", |
| 90 | vector_store_id="vs_abc123", |
| 91 | ) |
| 92 | |
| 93 | assert response.is_closed is True |
| 94 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 95 | file = response.parse() |
| 96 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 97 | |
| 98 | @parametrize |
| 99 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 100 | with client.vector_stores.files.with_streaming_response.retrieve( |
| 101 | file_id="file-abc123", |
| 102 | vector_store_id="vs_abc123", |
| 103 | ) as response: |
| 104 | assert not response.is_closed |
| 105 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 106 | |
| 107 | file = response.parse() |
| 108 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 109 | |
| 110 | assert cast(Any, response.is_closed) is True |
| 111 | |
| 112 | @parametrize |
| 113 | def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 114 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 115 | client.vector_stores.files.with_raw_response.retrieve( |
| 116 | file_id="file-abc123", |
| 117 | vector_store_id="", |
| 118 | ) |
| 119 | |
| 120 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 121 | client.vector_stores.files.with_raw_response.retrieve( |
| 122 | file_id="", |
| 123 | vector_store_id="vs_abc123", |
| 124 | ) |
| 125 | |
| 126 | @parametrize |
| 127 | def test_method_update(self, client: OpenAI) -> None: |
| 128 | file = client.vector_stores.files.update( |
| 129 | file_id="file-abc123", |
| 130 | vector_store_id="vs_abc123", |
| 131 | attributes={"foo": "string"}, |
| 132 | ) |
| 133 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 134 | |
| 135 | @parametrize |
| 136 | def test_raw_response_update(self, client: OpenAI) -> None: |
| 137 | response = client.vector_stores.files.with_raw_response.update( |
| 138 | file_id="file-abc123", |
| 139 | vector_store_id="vs_abc123", |
| 140 | attributes={"foo": "string"}, |
| 141 | ) |
| 142 | |
| 143 | assert response.is_closed is True |
| 144 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 145 | file = response.parse() |
| 146 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 147 | |
| 148 | @parametrize |
| 149 | def test_streaming_response_update(self, client: OpenAI) -> None: |
| 150 | with client.vector_stores.files.with_streaming_response.update( |
| 151 | file_id="file-abc123", |
| 152 | vector_store_id="vs_abc123", |
| 153 | attributes={"foo": "string"}, |
| 154 | ) as response: |
| 155 | assert not response.is_closed |
| 156 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 157 | |
| 158 | file = response.parse() |
| 159 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 160 | |
| 161 | assert cast(Any, response.is_closed) is True |
| 162 | |
| 163 | @parametrize |
| 164 | def test_path_params_update(self, client: OpenAI) -> None: |
| 165 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 166 | client.vector_stores.files.with_raw_response.update( |
| 167 | file_id="file-abc123", |
| 168 | vector_store_id="", |
| 169 | attributes={"foo": "string"}, |
| 170 | ) |
| 171 | |
| 172 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 173 | client.vector_stores.files.with_raw_response.update( |
| 174 | file_id="", |
| 175 | vector_store_id="vs_abc123", |
| 176 | attributes={"foo": "string"}, |
| 177 | ) |
| 178 | |
| 179 | @parametrize |
| 180 | def test_method_list(self, client: OpenAI) -> None: |
| 181 | file = client.vector_stores.files.list( |
| 182 | vector_store_id="vector_store_id", |
| 183 | ) |
| 184 | assert_matches_type(SyncCursorPage[VectorStoreFile], file, path=["response"]) |
| 185 | |
| 186 | @parametrize |
| 187 | def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 188 | file = client.vector_stores.files.list( |
| 189 | vector_store_id="vector_store_id", |
| 190 | after="after", |
| 191 | before="before", |
| 192 | filter="in_progress", |
| 193 | limit=0, |
| 194 | order="asc", |
| 195 | ) |
| 196 | assert_matches_type(SyncCursorPage[VectorStoreFile], file, path=["response"]) |
| 197 | |
| 198 | @parametrize |
| 199 | def test_raw_response_list(self, client: OpenAI) -> None: |
| 200 | response = client.vector_stores.files.with_raw_response.list( |
| 201 | vector_store_id="vector_store_id", |
| 202 | ) |
| 203 | |
| 204 | assert response.is_closed is True |
| 205 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 206 | file = response.parse() |
| 207 | assert_matches_type(SyncCursorPage[VectorStoreFile], file, path=["response"]) |
| 208 | |
| 209 | @parametrize |
| 210 | def test_streaming_response_list(self, client: OpenAI) -> None: |
| 211 | with client.vector_stores.files.with_streaming_response.list( |
| 212 | vector_store_id="vector_store_id", |
| 213 | ) as response: |
| 214 | assert not response.is_closed |
| 215 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 216 | |
| 217 | file = response.parse() |
| 218 | assert_matches_type(SyncCursorPage[VectorStoreFile], file, path=["response"]) |
| 219 | |
| 220 | assert cast(Any, response.is_closed) is True |
| 221 | |
| 222 | @parametrize |
| 223 | def test_path_params_list(self, client: OpenAI) -> None: |
| 224 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 225 | client.vector_stores.files.with_raw_response.list( |
| 226 | vector_store_id="", |
| 227 | ) |
| 228 | |
| 229 | @parametrize |
| 230 | def test_method_delete(self, client: OpenAI) -> None: |
| 231 | file = client.vector_stores.files.delete( |
| 232 | file_id="file_id", |
| 233 | vector_store_id="vector_store_id", |
| 234 | ) |
| 235 | assert_matches_type(VectorStoreFileDeleted, file, path=["response"]) |
| 236 | |
| 237 | @parametrize |
| 238 | def test_raw_response_delete(self, client: OpenAI) -> None: |
| 239 | response = client.vector_stores.files.with_raw_response.delete( |
| 240 | file_id="file_id", |
| 241 | vector_store_id="vector_store_id", |
| 242 | ) |
| 243 | |
| 244 | assert response.is_closed is True |
| 245 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 246 | file = response.parse() |
| 247 | assert_matches_type(VectorStoreFileDeleted, file, path=["response"]) |
| 248 | |
| 249 | @parametrize |
| 250 | def test_streaming_response_delete(self, client: OpenAI) -> None: |
| 251 | with client.vector_stores.files.with_streaming_response.delete( |
| 252 | file_id="file_id", |
| 253 | vector_store_id="vector_store_id", |
| 254 | ) as response: |
| 255 | assert not response.is_closed |
| 256 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 257 | |
| 258 | file = response.parse() |
| 259 | assert_matches_type(VectorStoreFileDeleted, file, path=["response"]) |
| 260 | |
| 261 | assert cast(Any, response.is_closed) is True |
| 262 | |
| 263 | @parametrize |
| 264 | def test_path_params_delete(self, client: OpenAI) -> None: |
| 265 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 266 | client.vector_stores.files.with_raw_response.delete( |
| 267 | file_id="file_id", |
| 268 | vector_store_id="", |
| 269 | ) |
| 270 | |
| 271 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 272 | client.vector_stores.files.with_raw_response.delete( |
| 273 | file_id="", |
| 274 | vector_store_id="vector_store_id", |
| 275 | ) |
| 276 | |
| 277 | @parametrize |
| 278 | def test_method_content(self, client: OpenAI) -> None: |
| 279 | file = client.vector_stores.files.content( |
| 280 | file_id="file-abc123", |
| 281 | vector_store_id="vs_abc123", |
| 282 | ) |
| 283 | assert_matches_type(SyncPage[FileContentResponse], file, path=["response"]) |
| 284 | |
| 285 | @parametrize |
| 286 | def test_raw_response_content(self, client: OpenAI) -> None: |
| 287 | response = client.vector_stores.files.with_raw_response.content( |
| 288 | file_id="file-abc123", |
| 289 | vector_store_id="vs_abc123", |
| 290 | ) |
| 291 | |
| 292 | assert response.is_closed is True |
| 293 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 294 | file = response.parse() |
| 295 | assert_matches_type(SyncPage[FileContentResponse], file, path=["response"]) |
| 296 | |
| 297 | @parametrize |
| 298 | def test_streaming_response_content(self, client: OpenAI) -> None: |
| 299 | with client.vector_stores.files.with_streaming_response.content( |
| 300 | file_id="file-abc123", |
| 301 | vector_store_id="vs_abc123", |
| 302 | ) as response: |
| 303 | assert not response.is_closed |
| 304 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 305 | |
| 306 | file = response.parse() |
| 307 | assert_matches_type(SyncPage[FileContentResponse], file, path=["response"]) |
| 308 | |
| 309 | assert cast(Any, response.is_closed) is True |
| 310 | |
| 311 | @parametrize |
| 312 | def test_path_params_content(self, client: OpenAI) -> None: |
| 313 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 314 | client.vector_stores.files.with_raw_response.content( |
| 315 | file_id="file-abc123", |
| 316 | vector_store_id="", |
| 317 | ) |
| 318 | |
| 319 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 320 | client.vector_stores.files.with_raw_response.content( |
| 321 | file_id="", |
| 322 | vector_store_id="vs_abc123", |
| 323 | ) |
| 324 | |
| 325 | |
| 326 | class TestAsyncFiles: |
| 327 | parametrize = pytest.mark.parametrize( |
| 328 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 329 | ) |
| 330 | |
| 331 | @parametrize |
| 332 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
| 333 | file = await async_client.vector_stores.files.create( |
| 334 | vector_store_id="vs_abc123", |
| 335 | file_id="file_id", |
| 336 | ) |
| 337 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 338 | |
| 339 | @parametrize |
| 340 | async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 341 | file = await async_client.vector_stores.files.create( |
| 342 | vector_store_id="vs_abc123", |
| 343 | file_id="file_id", |
| 344 | attributes={"foo": "string"}, |
| 345 | chunking_strategy={"type": "auto"}, |
| 346 | ) |
| 347 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 348 | |
| 349 | @parametrize |
| 350 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
| 351 | response = await async_client.vector_stores.files.with_raw_response.create( |
| 352 | vector_store_id="vs_abc123", |
| 353 | file_id="file_id", |
| 354 | ) |
| 355 | |
| 356 | assert response.is_closed is True |
| 357 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 358 | file = response.parse() |
| 359 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 360 | |
| 361 | @parametrize |
| 362 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
| 363 | async with async_client.vector_stores.files.with_streaming_response.create( |
| 364 | vector_store_id="vs_abc123", |
| 365 | file_id="file_id", |
| 366 | ) as response: |
| 367 | assert not response.is_closed |
| 368 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 369 | |
| 370 | file = await response.parse() |
| 371 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 372 | |
| 373 | assert cast(Any, response.is_closed) is True |
| 374 | |
| 375 | @parametrize |
| 376 | async def test_path_params_create(self, async_client: AsyncOpenAI) -> None: |
| 377 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 378 | await async_client.vector_stores.files.with_raw_response.create( |
| 379 | vector_store_id="", |
| 380 | file_id="file_id", |
| 381 | ) |
| 382 | |
| 383 | @parametrize |
| 384 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 385 | file = await async_client.vector_stores.files.retrieve( |
| 386 | file_id="file-abc123", |
| 387 | vector_store_id="vs_abc123", |
| 388 | ) |
| 389 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 390 | |
| 391 | @parametrize |
| 392 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 393 | response = await async_client.vector_stores.files.with_raw_response.retrieve( |
| 394 | file_id="file-abc123", |
| 395 | vector_store_id="vs_abc123", |
| 396 | ) |
| 397 | |
| 398 | assert response.is_closed is True |
| 399 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 400 | file = response.parse() |
| 401 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 402 | |
| 403 | @parametrize |
| 404 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 405 | async with async_client.vector_stores.files.with_streaming_response.retrieve( |
| 406 | file_id="file-abc123", |
| 407 | vector_store_id="vs_abc123", |
| 408 | ) as response: |
| 409 | assert not response.is_closed |
| 410 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 411 | |
| 412 | file = await response.parse() |
| 413 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 414 | |
| 415 | assert cast(Any, response.is_closed) is True |
| 416 | |
| 417 | @parametrize |
| 418 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 419 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 420 | await async_client.vector_stores.files.with_raw_response.retrieve( |
| 421 | file_id="file-abc123", |
| 422 | vector_store_id="", |
| 423 | ) |
| 424 | |
| 425 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 426 | await async_client.vector_stores.files.with_raw_response.retrieve( |
| 427 | file_id="", |
| 428 | vector_store_id="vs_abc123", |
| 429 | ) |
| 430 | |
| 431 | @parametrize |
| 432 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
| 433 | file = await async_client.vector_stores.files.update( |
| 434 | file_id="file-abc123", |
| 435 | vector_store_id="vs_abc123", |
| 436 | attributes={"foo": "string"}, |
| 437 | ) |
| 438 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 439 | |
| 440 | @parametrize |
| 441 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
| 442 | response = await async_client.vector_stores.files.with_raw_response.update( |
| 443 | file_id="file-abc123", |
| 444 | vector_store_id="vs_abc123", |
| 445 | attributes={"foo": "string"}, |
| 446 | ) |
| 447 | |
| 448 | assert response.is_closed is True |
| 449 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 450 | file = response.parse() |
| 451 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 452 | |
| 453 | @parametrize |
| 454 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
| 455 | async with async_client.vector_stores.files.with_streaming_response.update( |
| 456 | file_id="file-abc123", |
| 457 | vector_store_id="vs_abc123", |
| 458 | attributes={"foo": "string"}, |
| 459 | ) as response: |
| 460 | assert not response.is_closed |
| 461 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 462 | |
| 463 | file = await response.parse() |
| 464 | assert_matches_type(VectorStoreFile, file, path=["response"]) |
| 465 | |
| 466 | assert cast(Any, response.is_closed) is True |
| 467 | |
| 468 | @parametrize |
| 469 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
| 470 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 471 | await async_client.vector_stores.files.with_raw_response.update( |
| 472 | file_id="file-abc123", |
| 473 | vector_store_id="", |
| 474 | attributes={"foo": "string"}, |
| 475 | ) |
| 476 | |
| 477 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 478 | await async_client.vector_stores.files.with_raw_response.update( |
| 479 | file_id="", |
| 480 | vector_store_id="vs_abc123", |
| 481 | attributes={"foo": "string"}, |
| 482 | ) |
| 483 | |
| 484 | @parametrize |
| 485 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 486 | file = await async_client.vector_stores.files.list( |
| 487 | vector_store_id="vector_store_id", |
| 488 | ) |
| 489 | assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"]) |
| 490 | |
| 491 | @parametrize |
| 492 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 493 | file = await async_client.vector_stores.files.list( |
| 494 | vector_store_id="vector_store_id", |
| 495 | after="after", |
| 496 | before="before", |
| 497 | filter="in_progress", |
| 498 | limit=0, |
| 499 | order="asc", |
| 500 | ) |
| 501 | assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"]) |
| 502 | |
| 503 | @parametrize |
| 504 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 505 | response = await async_client.vector_stores.files.with_raw_response.list( |
| 506 | vector_store_id="vector_store_id", |
| 507 | ) |
| 508 | |
| 509 | assert response.is_closed is True |
| 510 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 511 | file = response.parse() |
| 512 | assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"]) |
| 513 | |
| 514 | @parametrize |
| 515 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 516 | async with async_client.vector_stores.files.with_streaming_response.list( |
| 517 | vector_store_id="vector_store_id", |
| 518 | ) as response: |
| 519 | assert not response.is_closed |
| 520 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 521 | |
| 522 | file = await response.parse() |
| 523 | assert_matches_type(AsyncCursorPage[VectorStoreFile], file, path=["response"]) |
| 524 | |
| 525 | assert cast(Any, response.is_closed) is True |
| 526 | |
| 527 | @parametrize |
| 528 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
| 529 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 530 | await async_client.vector_stores.files.with_raw_response.list( |
| 531 | vector_store_id="", |
| 532 | ) |
| 533 | |
| 534 | @parametrize |
| 535 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: |
| 536 | file = await async_client.vector_stores.files.delete( |
| 537 | file_id="file_id", |
| 538 | vector_store_id="vector_store_id", |
| 539 | ) |
| 540 | assert_matches_type(VectorStoreFileDeleted, file, path=["response"]) |
| 541 | |
| 542 | @parametrize |
| 543 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 544 | response = await async_client.vector_stores.files.with_raw_response.delete( |
| 545 | file_id="file_id", |
| 546 | vector_store_id="vector_store_id", |
| 547 | ) |
| 548 | |
| 549 | assert response.is_closed is True |
| 550 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 551 | file = response.parse() |
| 552 | assert_matches_type(VectorStoreFileDeleted, file, path=["response"]) |
| 553 | |
| 554 | @parametrize |
| 555 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 556 | async with async_client.vector_stores.files.with_streaming_response.delete( |
| 557 | file_id="file_id", |
| 558 | vector_store_id="vector_store_id", |
| 559 | ) as response: |
| 560 | assert not response.is_closed |
| 561 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 562 | |
| 563 | file = await response.parse() |
| 564 | assert_matches_type(VectorStoreFileDeleted, file, path=["response"]) |
| 565 | |
| 566 | assert cast(Any, response.is_closed) is True |
| 567 | |
| 568 | @parametrize |
| 569 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: |
| 570 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 571 | await async_client.vector_stores.files.with_raw_response.delete( |
| 572 | file_id="file_id", |
| 573 | vector_store_id="", |
| 574 | ) |
| 575 | |
| 576 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 577 | await async_client.vector_stores.files.with_raw_response.delete( |
| 578 | file_id="", |
| 579 | vector_store_id="vector_store_id", |
| 580 | ) |
| 581 | |
| 582 | @parametrize |
| 583 | async def test_method_content(self, async_client: AsyncOpenAI) -> None: |
| 584 | file = await async_client.vector_stores.files.content( |
| 585 | file_id="file-abc123", |
| 586 | vector_store_id="vs_abc123", |
| 587 | ) |
| 588 | assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"]) |
| 589 | |
| 590 | @parametrize |
| 591 | async def test_raw_response_content(self, async_client: AsyncOpenAI) -> None: |
| 592 | response = await async_client.vector_stores.files.with_raw_response.content( |
| 593 | file_id="file-abc123", |
| 594 | vector_store_id="vs_abc123", |
| 595 | ) |
| 596 | |
| 597 | assert response.is_closed is True |
| 598 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 599 | file = response.parse() |
| 600 | assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"]) |
| 601 | |
| 602 | @parametrize |
| 603 | async def test_streaming_response_content(self, async_client: AsyncOpenAI) -> None: |
| 604 | async with async_client.vector_stores.files.with_streaming_response.content( |
| 605 | file_id="file-abc123", |
| 606 | vector_store_id="vs_abc123", |
| 607 | ) as response: |
| 608 | assert not response.is_closed |
| 609 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 610 | |
| 611 | file = await response.parse() |
| 612 | assert_matches_type(AsyncPage[FileContentResponse], file, path=["response"]) |
| 613 | |
| 614 | assert cast(Any, response.is_closed) is True |
| 615 | |
| 616 | @parametrize |
| 617 | async def test_path_params_content(self, async_client: AsyncOpenAI) -> None: |
| 618 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `vector_store_id` but received ''"): |
| 619 | await async_client.vector_stores.files.with_raw_response.content( |
| 620 | file_id="file-abc123", |
| 621 | vector_store_id="", |
| 622 | ) |
| 623 | |
| 624 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `file_id` but received ''"): |
| 625 | await async_client.vector_stores.files.with_raw_response.content( |
| 626 | file_id="", |
| 627 | vector_store_id="vs_abc123", |
| 628 | ) |
| 629 | |
| 630 | |
| 631 | @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) |
| 632 | def test_create_and_poll_method_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None: |
| 633 | checking_client: OpenAI | AsyncOpenAI = client if sync else async_client |
| 634 | |
| 635 | assert_signatures_in_sync( |
| 636 | checking_client.vector_stores.files.create, |
| 637 | checking_client.vector_stores.files.create_and_poll, |
| 638 | exclude_params={"extra_headers", "extra_query", "extra_body", "timeout"}, |
| 639 | ) |
| 640 | |
| 641 | |
| 642 | @pytest.mark.parametrize("sync", [True, False], ids=["sync", "async"]) |
| 643 | def test_upload_and_poll_method_in_sync(sync: bool, client: OpenAI, async_client: AsyncOpenAI) -> None: |
| 644 | checking_client: OpenAI | AsyncOpenAI = client if sync else async_client |
| 645 | |
| 646 | assert_signatures_in_sync( |
| 647 | checking_client.vector_stores.files.create, |
| 648 | checking_client.vector_stores.files.upload_and_poll, |
| 649 | exclude_params={"file_id", "extra_headers", "extra_query", "extra_body", "timeout"}, |
| 650 | ) |
| 651 | |