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