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