main
1# File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
3from __future__ import annotations
4
5import os
6from typing import Any, cast
7
8import pytest
9
10from openai import OpenAI, AsyncOpenAI
11from tests.utils import assert_matches_type
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.responses import ResponseItem
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16
17
18class TestInputItems:
19 parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
20
21 @parametrize
22 def test_method_list(self, client: OpenAI) -> None:
23 input_item = client.responses.input_items.list(
24 response_id="response_id",
25 )
26 assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
27
28 @parametrize
29 def test_method_list_with_all_params(self, client: OpenAI) -> None:
30 input_item = client.responses.input_items.list(
31 response_id="response_id",
32 after="after",
33 include=["file_search_call.results"],
34 limit=0,
35 order="asc",
36 )
37 assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
38
39 @parametrize
40 def test_raw_response_list(self, client: OpenAI) -> None:
41 response = client.responses.input_items.with_raw_response.list(
42 response_id="response_id",
43 )
44
45 assert response.is_closed is True
46 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
47 input_item = response.parse()
48 assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
49
50 @parametrize
51 def test_streaming_response_list(self, client: OpenAI) -> None:
52 with client.responses.input_items.with_streaming_response.list(
53 response_id="response_id",
54 ) as response:
55 assert not response.is_closed
56 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
57
58 input_item = response.parse()
59 assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
60
61 assert cast(Any, response.is_closed) is True
62
63 @parametrize
64 def test_path_params_list(self, client: OpenAI) -> None:
65 with pytest.raises(ValueError, match=r"Expected a non-empty value for `response_id` but received ''"):
66 client.responses.input_items.with_raw_response.list(
67 response_id="",
68 )
69
70
71class TestAsyncInputItems:
72 parametrize = pytest.mark.parametrize(
73 "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
74 )
75
76 @parametrize
77 async def test_method_list(self, async_client: AsyncOpenAI) -> None:
78 input_item = await async_client.responses.input_items.list(
79 response_id="response_id",
80 )
81 assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
82
83 @parametrize
84 async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
85 input_item = await async_client.responses.input_items.list(
86 response_id="response_id",
87 after="after",
88 include=["file_search_call.results"],
89 limit=0,
90 order="asc",
91 )
92 assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
93
94 @parametrize
95 async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
96 response = await async_client.responses.input_items.with_raw_response.list(
97 response_id="response_id",
98 )
99
100 assert response.is_closed is True
101 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
102 input_item = response.parse()
103 assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
104
105 @parametrize
106 async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
107 async with async_client.responses.input_items.with_streaming_response.list(
108 response_id="response_id",
109 ) as response:
110 assert not response.is_closed
111 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
112
113 input_item = await response.parse()
114 assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
115
116 assert cast(Any, response.is_closed) is True
117
118 @parametrize
119 async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
120 with pytest.raises(ValueError, match=r"Expected a non-empty value for `response_id` but received ''"):
121 await async_client.responses.input_items.with_raw_response.list(
122 response_id="",
123 )