openai/openai-python

Public

mirrored from https://github.com/openai/openai-pythonAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.100.0

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

tests/api_resources/responses/test_input_items.py

125lines · modeblame

2954945eRobert Craigie1 years ago1# 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
bff8da95stainless-app[bot]1 years ago13from openai.types.responses import ResponseItem
2954945eRobert Craigie1 years ago14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16
17
18class TestInputItems:
19parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"])
20
21@parametrize
22def test_method_list(self, client: OpenAI) -> None:
23input_item = client.responses.input_items.list(
24response_id="response_id",
25)
bff8da95stainless-app[bot]1 years ago26assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago27
28@parametrize
29def test_method_list_with_all_params(self, client: OpenAI) -> None:
30input_item = client.responses.input_items.list(
31response_id="response_id",
32after="after",
33before="before",
18e0b36astainless-app[bot]12 months ago34include=["code_interpreter_call.outputs"],
2954945eRobert Craigie1 years ago35limit=0,
36order="asc",
37)
bff8da95stainless-app[bot]1 years ago38assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago39
40@parametrize
41def test_raw_response_list(self, client: OpenAI) -> None:
42response = client.responses.input_items.with_raw_response.list(
43response_id="response_id",
44)
45
46assert response.is_closed is True
47assert response.http_request.headers.get("X-Stainless-Lang") == "python"
48input_item = response.parse()
bff8da95stainless-app[bot]1 years ago49assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago50
51@parametrize
52def test_streaming_response_list(self, client: OpenAI) -> None:
53with client.responses.input_items.with_streaming_response.list(
54response_id="response_id",
55) as response:
56assert not response.is_closed
57assert response.http_request.headers.get("X-Stainless-Lang") == "python"
58
59input_item = response.parse()
bff8da95stainless-app[bot]1 years ago60assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago61
62assert cast(Any, response.is_closed) is True
63
64@parametrize
65def test_path_params_list(self, client: OpenAI) -> None:
66with pytest.raises(ValueError, match=r"Expected a non-empty value for `response_id` but received ''"):
67client.responses.input_items.with_raw_response.list(
68response_id="",
69)
70
71
72class TestAsyncInputItems:
c62e9907stainless-app[bot]1 years ago73parametrize = pytest.mark.parametrize(
74"async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"]
75)
2954945eRobert Craigie1 years ago76
77@parametrize
78async def test_method_list(self, async_client: AsyncOpenAI) -> None:
79input_item = await async_client.responses.input_items.list(
80response_id="response_id",
81)
bff8da95stainless-app[bot]1 years ago82assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago83
84@parametrize
85async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
86input_item = await async_client.responses.input_items.list(
87response_id="response_id",
88after="after",
89before="before",
18e0b36astainless-app[bot]12 months ago90include=["code_interpreter_call.outputs"],
2954945eRobert Craigie1 years ago91limit=0,
92order="asc",
93)
bff8da95stainless-app[bot]1 years ago94assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago95
96@parametrize
97async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
98response = await async_client.responses.input_items.with_raw_response.list(
99response_id="response_id",
100)
101
102assert response.is_closed is True
103assert response.http_request.headers.get("X-Stainless-Lang") == "python"
104input_item = response.parse()
bff8da95stainless-app[bot]1 years ago105assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago106
107@parametrize
108async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
109async with async_client.responses.input_items.with_streaming_response.list(
110response_id="response_id",
111) as response:
112assert not response.is_closed
113assert response.http_request.headers.get("X-Stainless-Lang") == "python"
114
115input_item = await response.parse()
bff8da95stainless-app[bot]1 years ago116assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago117
118assert cast(Any, response.is_closed) is True
119
120@parametrize
121async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
122with pytest.raises(ValueError, match=r"Expected a non-empty value for `response_id` but received ''"):
123await async_client.responses.input_items.with_raw_response.list(
124response_id="",
125)