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