openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.67.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

121lines · 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",
34limit=0,
35order="asc",
36)
bff8da95stainless-app[bot]1 years ago37assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago38
39@parametrize
40def test_raw_response_list(self, client: OpenAI) -> None:
41response = client.responses.input_items.with_raw_response.list(
42response_id="response_id",
43)
44
45assert response.is_closed is True
46assert response.http_request.headers.get("X-Stainless-Lang") == "python"
47input_item = response.parse()
bff8da95stainless-app[bot]1 years ago48assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago49
50@parametrize
51def test_streaming_response_list(self, client: OpenAI) -> None:
52with client.responses.input_items.with_streaming_response.list(
53response_id="response_id",
54) as response:
55assert not response.is_closed
56assert response.http_request.headers.get("X-Stainless-Lang") == "python"
57
58input_item = response.parse()
bff8da95stainless-app[bot]1 years ago59assert_matches_type(SyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago60
61assert cast(Any, response.is_closed) is True
62
63@parametrize
64def test_path_params_list(self, client: OpenAI) -> None:
65with pytest.raises(ValueError, match=r"Expected a non-empty value for `response_id` but received ''"):
66client.responses.input_items.with_raw_response.list(
67response_id="",
68)
69
70
71class TestAsyncInputItems:
72parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"])
73
74@parametrize
75async def test_method_list(self, async_client: AsyncOpenAI) -> None:
76input_item = await async_client.responses.input_items.list(
77response_id="response_id",
78)
bff8da95stainless-app[bot]1 years ago79assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago80
81@parametrize
82async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None:
83input_item = await async_client.responses.input_items.list(
84response_id="response_id",
85after="after",
86before="before",
87limit=0,
88order="asc",
89)
bff8da95stainless-app[bot]1 years ago90assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago91
92@parametrize
93async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None:
94response = await async_client.responses.input_items.with_raw_response.list(
95response_id="response_id",
96)
97
98assert response.is_closed is True
99assert response.http_request.headers.get("X-Stainless-Lang") == "python"
100input_item = response.parse()
bff8da95stainless-app[bot]1 years ago101assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago102
103@parametrize
104async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None:
105async with async_client.responses.input_items.with_streaming_response.list(
106response_id="response_id",
107) as response:
108assert not response.is_closed
109assert response.http_request.headers.get("X-Stainless-Lang") == "python"
110
111input_item = await response.parse()
bff8da95stainless-app[bot]1 years ago112assert_matches_type(AsyncCursorPage[ResponseItem], input_item, path=["response"])
2954945eRobert Craigie1 years ago113
114assert cast(Any, response.is_closed) is True
115
116@parametrize
117async def test_path_params_list(self, async_client: AsyncOpenAI) -> None:
118with pytest.raises(ValueError, match=r"Expected a non-empty value for `response_id` but received ''"):
119await async_client.responses.input_items.with_raw_response.list(
120response_id="",
121)