openai/openai-python

Public

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

CodeCommitsIssuesPull requestsActionsInsightsSecurity
v1.2.4

Branches

Tags

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

Clone

HTTPS

Download ZIP

tests/api_resources/beta/assistants/test_files.py

190lines · modecode

1# File generated from our OpenAPI spec by Stainless.
2
3from __future__ import annotations
4
5import os
6
7import pytest
8
9from openai import OpenAI, AsyncOpenAI
10from tests.utils import assert_matches_type
11from openai._client import OpenAI, AsyncOpenAI
12from openai.pagination import SyncCursorPage, AsyncCursorPage
13from openai.types.beta.assistants import AssistantFile, FileDeleteResponse
14
15base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010")
16api_key = "My API Key"
17
18
19class TestFiles:
20 strict_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
21 loose_client = OpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
22 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
23
24 @parametrize
25 def test_method_create(self, client: OpenAI) -> None:
26 file = client.beta.assistants.files.create(
27 "file-AF1WoRqd3aJAHsqc9NY7iL8F",
28 file_id="string",
29 )
30 assert_matches_type(AssistantFile, file, path=["response"])
31
32 @parametrize
33 def test_raw_response_create(self, client: OpenAI) -> None:
34 response = client.beta.assistants.files.with_raw_response.create(
35 "file-AF1WoRqd3aJAHsqc9NY7iL8F",
36 file_id="string",
37 )
38 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
39 file = response.parse()
40 assert_matches_type(AssistantFile, file, path=["response"])
41
42 @parametrize
43 def test_method_retrieve(self, client: OpenAI) -> None:
44 file = client.beta.assistants.files.retrieve(
45 "string",
46 assistant_id="string",
47 )
48 assert_matches_type(AssistantFile, file, path=["response"])
49
50 @parametrize
51 def test_raw_response_retrieve(self, client: OpenAI) -> None:
52 response = client.beta.assistants.files.with_raw_response.retrieve(
53 "string",
54 assistant_id="string",
55 )
56 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
57 file = response.parse()
58 assert_matches_type(AssistantFile, file, path=["response"])
59
60 @parametrize
61 def test_method_list(self, client: OpenAI) -> None:
62 file = client.beta.assistants.files.list(
63 "string",
64 )
65 assert_matches_type(SyncCursorPage[AssistantFile], file, path=["response"])
66
67 @parametrize
68 def test_method_list_with_all_params(self, client: OpenAI) -> None:
69 file = client.beta.assistants.files.list(
70 "string",
71 after="string",
72 before="string",
73 limit=0,
74 order="asc",
75 )
76 assert_matches_type(SyncCursorPage[AssistantFile], file, path=["response"])
77
78 @parametrize
79 def test_raw_response_list(self, client: OpenAI) -> None:
80 response = client.beta.assistants.files.with_raw_response.list(
81 "string",
82 )
83 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
84 file = response.parse()
85 assert_matches_type(SyncCursorPage[AssistantFile], file, path=["response"])
86
87 @parametrize
88 def test_method_delete(self, client: OpenAI) -> None:
89 file = client.beta.assistants.files.delete(
90 "string",
91 assistant_id="string",
92 )
93 assert_matches_type(FileDeleteResponse, file, path=["response"])
94
95 @parametrize
96 def test_raw_response_delete(self, client: OpenAI) -> None:
97 response = client.beta.assistants.files.with_raw_response.delete(
98 "string",
99 assistant_id="string",
100 )
101 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
102 file = response.parse()
103 assert_matches_type(FileDeleteResponse, file, path=["response"])
104
105
106class TestAsyncFiles:
107 strict_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=True)
108 loose_client = AsyncOpenAI(base_url=base_url, api_key=api_key, _strict_response_validation=False)
109 parametrize = pytest.mark.parametrize("client", [strict_client, loose_client], ids=["strict", "loose"])
110
111 @parametrize
112 async def test_method_create(self, client: AsyncOpenAI) -> None:
113 file = await client.beta.assistants.files.create(
114 "file-AF1WoRqd3aJAHsqc9NY7iL8F",
115 file_id="string",
116 )
117 assert_matches_type(AssistantFile, file, path=["response"])
118
119 @parametrize
120 async def test_raw_response_create(self, client: AsyncOpenAI) -> None:
121 response = await client.beta.assistants.files.with_raw_response.create(
122 "file-AF1WoRqd3aJAHsqc9NY7iL8F",
123 file_id="string",
124 )
125 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
126 file = response.parse()
127 assert_matches_type(AssistantFile, file, path=["response"])
128
129 @parametrize
130 async def test_method_retrieve(self, client: AsyncOpenAI) -> None:
131 file = await client.beta.assistants.files.retrieve(
132 "string",
133 assistant_id="string",
134 )
135 assert_matches_type(AssistantFile, file, path=["response"])
136
137 @parametrize
138 async def test_raw_response_retrieve(self, client: AsyncOpenAI) -> None:
139 response = await client.beta.assistants.files.with_raw_response.retrieve(
140 "string",
141 assistant_id="string",
142 )
143 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
144 file = response.parse()
145 assert_matches_type(AssistantFile, file, path=["response"])
146
147 @parametrize
148 async def test_method_list(self, client: AsyncOpenAI) -> None:
149 file = await client.beta.assistants.files.list(
150 "string",
151 )
152 assert_matches_type(AsyncCursorPage[AssistantFile], file, path=["response"])
153
154 @parametrize
155 async def test_method_list_with_all_params(self, client: AsyncOpenAI) -> None:
156 file = await client.beta.assistants.files.list(
157 "string",
158 after="string",
159 before="string",
160 limit=0,
161 order="asc",
162 )
163 assert_matches_type(AsyncCursorPage[AssistantFile], file, path=["response"])
164
165 @parametrize
166 async def test_raw_response_list(self, client: AsyncOpenAI) -> None:
167 response = await client.beta.assistants.files.with_raw_response.list(
168 "string",
169 )
170 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
171 file = response.parse()
172 assert_matches_type(AsyncCursorPage[AssistantFile], file, path=["response"])
173
174 @parametrize
175 async def test_method_delete(self, client: AsyncOpenAI) -> None:
176 file = await client.beta.assistants.files.delete(
177 "string",
178 assistant_id="string",
179 )
180 assert_matches_type(FileDeleteResponse, file, path=["response"])
181
182 @parametrize
183 async def test_raw_response_delete(self, client: AsyncOpenAI) -> None:
184 response = await client.beta.assistants.files.with_raw_response.delete(
185 "string",
186 assistant_id="string",
187 )
188 assert response.http_request.headers.get("X-Stainless-Lang") == "python"
189 file = response.parse()
190 assert_matches_type(FileDeleteResponse, file, path=["response"])
191