|
10 | 10 |
|
11 | 11 | from openai import OpenAI, AsyncOpenAI
|
12 | 12 | from tests.utils import assert_matches_type
|
| 13 | +from openai.pagination import SyncCursorPage, AsyncCursorPage |
13 | 14 | from openai.types.chat import (
|
14 | 15 | ChatCompletion,
|
| 16 | + ChatCompletionDeleted, |
15 | 17 | )
|
16 | 18 |
|
17 | 19 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
|
@@ -248,6 +250,160 @@ def test_streaming_response_create_overload_2(self, client: OpenAI) -> None:
|
248 | 250 |
|
249 | 251 | assert cast(Any, response.is_closed) is True
|
250 | 252 |
|
| 253 | + @parametrize |
| 254 | + def test_method_retrieve(self, client: OpenAI) -> None: |
| 255 | + completion = client.chat.completions.retrieve( |
| 256 | + "completion_id", |
| 257 | + ) |
| 258 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 259 | + |
| 260 | + @parametrize |
| 261 | + def test_raw_response_retrieve(self, client: OpenAI) -> None: |
| 262 | + response = client.chat.completions.with_raw_response.retrieve( |
| 263 | + "completion_id", |
| 264 | + ) |
| 265 | + |
| 266 | + assert response.is_closed is True |
| 267 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 268 | + completion = response.parse() |
| 269 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 270 | + |
| 271 | + @parametrize |
| 272 | + def test_streaming_response_retrieve(self, client: OpenAI) -> None: |
| 273 | + with client.chat.completions.with_streaming_response.retrieve( |
| 274 | + "completion_id", |
| 275 | + ) as response: |
| 276 | + assert not response.is_closed |
| 277 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 278 | + |
| 279 | + completion = response.parse() |
| 280 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 281 | + |
| 282 | + assert cast(Any, response.is_closed) is True |
| 283 | + |
| 284 | + @parametrize |
| 285 | + def test_path_params_retrieve(self, client: OpenAI) -> None: |
| 286 | + with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"): |
| 287 | + client.chat.completions.with_raw_response.retrieve( |
| 288 | + "", |
| 289 | + ) |
| 290 | + |
| 291 | + @parametrize |
| 292 | + def test_method_update(self, client: OpenAI) -> None: |
| 293 | + completion = client.chat.completions.update( |
| 294 | + completion_id="completion_id", |
| 295 | + metadata={"foo": "string"}, |
| 296 | + ) |
| 297 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 298 | + |
| 299 | + @parametrize |
| 300 | + def test_raw_response_update(self, client: OpenAI) -> None: |
| 301 | + response = client.chat.completions.with_raw_response.update( |
| 302 | + completion_id="completion_id", |
| 303 | + metadata={"foo": "string"}, |
| 304 | + ) |
| 305 | + |
| 306 | + assert response.is_closed is True |
| 307 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 308 | + completion = response.parse() |
| 309 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 310 | + |
| 311 | + @parametrize |
| 312 | + def test_streaming_response_update(self, client: OpenAI) -> None: |
| 313 | + with client.chat.completions.with_streaming_response.update( |
| 314 | + completion_id="completion_id", |
| 315 | + metadata={"foo": "string"}, |
| 316 | + ) as response: |
| 317 | + assert not response.is_closed |
| 318 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 319 | + |
| 320 | + completion = response.parse() |
| 321 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 322 | + |
| 323 | + assert cast(Any, response.is_closed) is True |
| 324 | + |
| 325 | + @parametrize |
| 326 | + def test_path_params_update(self, client: OpenAI) -> None: |
| 327 | + with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"): |
| 328 | + client.chat.completions.with_raw_response.update( |
| 329 | + completion_id="", |
| 330 | + metadata={"foo": "string"}, |
| 331 | + ) |
| 332 | + |
| 333 | + @parametrize |
| 334 | + def test_method_list(self, client: OpenAI) -> None: |
| 335 | + completion = client.chat.completions.list() |
| 336 | + assert_matches_type(SyncCursorPage[ChatCompletion], completion, path=["response"]) |
| 337 | + |
| 338 | + @parametrize |
| 339 | + def test_method_list_with_all_params(self, client: OpenAI) -> None: |
| 340 | + completion = client.chat.completions.list( |
| 341 | + after="after", |
| 342 | + limit=0, |
| 343 | + metadata={"foo": "string"}, |
| 344 | + model="model", |
| 345 | + order="asc", |
| 346 | + ) |
| 347 | + assert_matches_type(SyncCursorPage[ChatCompletion], completion, path=["response"]) |
| 348 | + |
| 349 | + @parametrize |
| 350 | + def test_raw_response_list(self, client: OpenAI) -> None: |
| 351 | + response = client.chat.completions.with_raw_response.list() |
| 352 | + |
| 353 | + assert response.is_closed is True |
| 354 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 355 | + completion = response.parse() |
| 356 | + assert_matches_type(SyncCursorPage[ChatCompletion], completion, path=["response"]) |
| 357 | + |
| 358 | + @parametrize |
| 359 | + def test_streaming_response_list(self, client: OpenAI) -> None: |
| 360 | + with client.chat.completions.with_streaming_response.list() as response: |
| 361 | + assert not response.is_closed |
| 362 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 363 | + |
| 364 | + completion = response.parse() |
| 365 | + assert_matches_type(SyncCursorPage[ChatCompletion], completion, path=["response"]) |
| 366 | + |
| 367 | + assert cast(Any, response.is_closed) is True |
| 368 | + |
| 369 | + @parametrize |
| 370 | + def test_method_delete(self, client: OpenAI) -> None: |
| 371 | + completion = client.chat.completions.delete( |
| 372 | + "completion_id", |
| 373 | + ) |
| 374 | + assert_matches_type(ChatCompletionDeleted, completion, path=["response"]) |
| 375 | + |
| 376 | + @parametrize |
| 377 | + def test_raw_response_delete(self, client: OpenAI) -> None: |
| 378 | + response = client.chat.completions.with_raw_response.delete( |
| 379 | + "completion_id", |
| 380 | + ) |
| 381 | + |
| 382 | + assert response.is_closed is True |
| 383 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 384 | + completion = response.parse() |
| 385 | + assert_matches_type(ChatCompletionDeleted, completion, path=["response"]) |
| 386 | + |
| 387 | + @parametrize |
| 388 | + def test_streaming_response_delete(self, client: OpenAI) -> None: |
| 389 | + with client.chat.completions.with_streaming_response.delete( |
| 390 | + "completion_id", |
| 391 | + ) as response: |
| 392 | + assert not response.is_closed |
| 393 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 394 | + |
| 395 | + completion = response.parse() |
| 396 | + assert_matches_type(ChatCompletionDeleted, completion, path=["response"]) |
| 397 | + |
| 398 | + assert cast(Any, response.is_closed) is True |
| 399 | + |
| 400 | + @parametrize |
| 401 | + def test_path_params_delete(self, client: OpenAI) -> None: |
| 402 | + with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"): |
| 403 | + client.chat.completions.with_raw_response.delete( |
| 404 | + "", |
| 405 | + ) |
| 406 | + |
251 | 407 | @parametrize
|
252 | 408 | def test_method_create_disallows_pydantic(self, client: OpenAI) -> None:
|
253 | 409 | class MyModel(pydantic.BaseModel):
|
@@ -497,6 +653,160 @@ async def test_streaming_response_create_overload_2(self, async_client: AsyncOpe
|
497 | 653 |
|
498 | 654 | assert cast(Any, response.is_closed) is True
|
499 | 655 |
|
| 656 | + @parametrize |
| 657 | + async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 658 | + completion = await async_client.chat.completions.retrieve( |
| 659 | + "completion_id", |
| 660 | + ) |
| 661 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 662 | + |
| 663 | + @parametrize |
| 664 | + async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 665 | + response = await async_client.chat.completions.with_raw_response.retrieve( |
| 666 | + "completion_id", |
| 667 | + ) |
| 668 | + |
| 669 | + assert response.is_closed is True |
| 670 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 671 | + completion = response.parse() |
| 672 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 673 | + |
| 674 | + @parametrize |
| 675 | + async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 676 | + async with async_client.chat.completions.with_streaming_response.retrieve( |
| 677 | + "completion_id", |
| 678 | + ) as response: |
| 679 | + assert not response.is_closed |
| 680 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 681 | + |
| 682 | + completion = await response.parse() |
| 683 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 684 | + |
| 685 | + assert cast(Any, response.is_closed) is True |
| 686 | + |
| 687 | + @parametrize |
| 688 | + async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 689 | + with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"): |
| 690 | + await async_client.chat.completions.with_raw_response.retrieve( |
| 691 | + "", |
| 692 | + ) |
| 693 | + |
| 694 | + @parametrize |
| 695 | + async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
| 696 | + completion = await async_client.chat.completions.update( |
| 697 | + completion_id="completion_id", |
| 698 | + metadata={"foo": "string"}, |
| 699 | + ) |
| 700 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 701 | + |
| 702 | + @parametrize |
| 703 | + async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
| 704 | + response = await async_client.chat.completions.with_raw_response.update( |
| 705 | + completion_id="completion_id", |
| 706 | + metadata={"foo": "string"}, |
| 707 | + ) |
| 708 | + |
| 709 | + assert response.is_closed is True |
| 710 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 711 | + completion = response.parse() |
| 712 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 713 | + |
| 714 | + @parametrize |
| 715 | + async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
| 716 | + async with async_client.chat.completions.with_streaming_response.update( |
| 717 | + completion_id="completion_id", |
| 718 | + metadata={"foo": "string"}, |
| 719 | + ) as response: |
| 720 | + assert not response.is_closed |
| 721 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 722 | + |
| 723 | + completion = await response.parse() |
| 724 | + assert_matches_type(ChatCompletion, completion, path=["response"]) |
| 725 | + |
| 726 | + assert cast(Any, response.is_closed) is True |
| 727 | + |
| 728 | + @parametrize |
| 729 | + async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
| 730 | + with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"): |
| 731 | + await async_client.chat.completions.with_raw_response.update( |
| 732 | + completion_id="", |
| 733 | + metadata={"foo": "string"}, |
| 734 | + ) |
| 735 | + |
| 736 | + @parametrize |
| 737 | + async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 738 | + completion = await async_client.chat.completions.list() |
| 739 | + assert_matches_type(AsyncCursorPage[ChatCompletion], completion, path=["response"]) |
| 740 | + |
| 741 | + @parametrize |
| 742 | + async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 743 | + completion = await async_client.chat.completions.list( |
| 744 | + after="after", |
| 745 | + limit=0, |
| 746 | + metadata={"foo": "string"}, |
| 747 | + model="model", |
| 748 | + order="asc", |
| 749 | + ) |
| 750 | + assert_matches_type(AsyncCursorPage[ChatCompletion], completion, path=["response"]) |
| 751 | + |
| 752 | + @parametrize |
| 753 | + async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 754 | + response = await async_client.chat.completions.with_raw_response.list() |
| 755 | + |
| 756 | + assert response.is_closed is True |
| 757 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 758 | + completion = response.parse() |
| 759 | + assert_matches_type(AsyncCursorPage[ChatCompletion], completion, path=["response"]) |
| 760 | + |
| 761 | + @parametrize |
| 762 | + async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 763 | + async with async_client.chat.completions.with_streaming_response.list() as response: |
| 764 | + assert not response.is_closed |
| 765 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 766 | + |
| 767 | + completion = await response.parse() |
| 768 | + assert_matches_type(AsyncCursorPage[ChatCompletion], completion, path=["response"]) |
| 769 | + |
| 770 | + assert cast(Any, response.is_closed) is True |
| 771 | + |
| 772 | + @parametrize |
| 773 | + async def test_method_delete(self, async_client: AsyncOpenAI) -> None: |
| 774 | + completion = await async_client.chat.completions.delete( |
| 775 | + "completion_id", |
| 776 | + ) |
| 777 | + assert_matches_type(ChatCompletionDeleted, completion, path=["response"]) |
| 778 | + |
| 779 | + @parametrize |
| 780 | + async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 781 | + response = await async_client.chat.completions.with_raw_response.delete( |
| 782 | + "completion_id", |
| 783 | + ) |
| 784 | + |
| 785 | + assert response.is_closed is True |
| 786 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 787 | + completion = response.parse() |
| 788 | + assert_matches_type(ChatCompletionDeleted, completion, path=["response"]) |
| 789 | + |
| 790 | + @parametrize |
| 791 | + async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: |
| 792 | + async with async_client.chat.completions.with_streaming_response.delete( |
| 793 | + "completion_id", |
| 794 | + ) as response: |
| 795 | + assert not response.is_closed |
| 796 | + assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 797 | + |
| 798 | + completion = await response.parse() |
| 799 | + assert_matches_type(ChatCompletionDeleted, completion, path=["response"]) |
| 800 | + |
| 801 | + assert cast(Any, response.is_closed) is True |
| 802 | + |
| 803 | + @parametrize |
| 804 | + async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: |
| 805 | + with pytest.raises(ValueError, match=r"Expected a non-empty value for `completion_id` but received ''"): |
| 806 | + await async_client.chat.completions.with_raw_response.delete( |
| 807 | + "", |
| 808 | + ) |
| 809 | + |
500 | 810 | @parametrize
|
501 | 811 | async def test_method_create_disallows_pydantic(self, async_client: AsyncOpenAI) -> None:
|
502 | 812 | class MyModel(pydantic.BaseModel):
|
|
0 commit comments