openai/openai-python
Publicmirrored from https://github.com/openai/openai-pythonAvailable
tests/api_resources/beta/threads/test_messages.py
556lines · modeblame
5cfb125aStainless Bot2 years ago | 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
baa9f07fRobert Craigie2 years ago | 2 | |
| 3 | from __future__ import annotations | |
| 4 | | |
| 5 | import os | |
86379b44Stainless Bot2 years ago | 6 | from typing import Any, cast |
baa9f07fRobert Craigie2 years ago | 7 | |
| 8 | import pytest | |
| 9 | | |
| 10 | from openai import OpenAI, AsyncOpenAI | |
| 11 | from tests.utils import assert_matches_type | |
| 12 | from openai.pagination import SyncCursorPage, AsyncCursorPage | |
d2738d42Stainless Bot2 years ago | 13 | from openai.types.beta.threads import ( |
| 14 | Message, | |
| 15 | MessageDeleted, | |
| 16 | ) | |
baa9f07fRobert Craigie2 years ago | 17 | |
| 18 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") | |
| 19 | | |
| 20 | | |
| 21 | class TestMessages: | |
98d779fbStainless Bot2 years ago | 22 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
baa9f07fRobert Craigie2 years ago | 23 | |
| 24 | @parametrize | |
| 25 | def test_method_create(self, client: OpenAI) -> None: | |
| 26 | message = client.beta.threads.messages.create( | |
| 27 | "string", | |
79a0b401Stainless Bot2 years ago | 28 | content="string", |
baa9f07fRobert Craigie2 years ago | 29 | role="user", |
| 30 | ) | |
5429f696Stainless Bot2 years ago | 31 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 32 | |
| 33 | @parametrize | |
| 34 | def test_method_create_with_all_params(self, client: OpenAI) -> None: | |
| 35 | message = client.beta.threads.messages.create( | |
| 36 | "string", | |
79a0b401Stainless Bot2 years ago | 37 | content="string", |
baa9f07fRobert Craigie2 years ago | 38 | role="user", |
5b20698dStainless Bot2 years ago | 39 | attachments=[ |
| 40 | { | |
dd19d4f9Stainless Bot1 years ago | 41 | "file_id": "file_id", |
| 42 | "tools": [{"type": "code_interpreter"}], | |
| 43 | } | |
5b20698dStainless Bot2 years ago | 44 | ], |
fdd52476stainless-app[bot]1 years ago | 45 | metadata={"foo": "string"}, |
baa9f07fRobert Craigie2 years ago | 46 | ) |
5429f696Stainless Bot2 years ago | 47 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 48 | |
| 49 | @parametrize | |
| 50 | def test_raw_response_create(self, client: OpenAI) -> None: | |
| 51 | response = client.beta.threads.messages.with_raw_response.create( | |
| 52 | "string", | |
79a0b401Stainless Bot2 years ago | 53 | content="string", |
baa9f07fRobert Craigie2 years ago | 54 | role="user", |
| 55 | ) | |
86379b44Stainless Bot2 years ago | 56 | |
| 57 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 58 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 59 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 60 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 61 | |
86379b44Stainless Bot2 years ago | 62 | @parametrize |
| 63 | def test_streaming_response_create(self, client: OpenAI) -> None: | |
| 64 | with client.beta.threads.messages.with_streaming_response.create( | |
| 65 | "string", | |
79a0b401Stainless Bot2 years ago | 66 | content="string", |
86379b44Stainless Bot2 years ago | 67 | role="user", |
| 68 | ) as response: | |
| 69 | assert not response.is_closed | |
| 70 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 71 | | |
| 72 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 73 | assert_matches_type(Message, message, path=["response"]) |
86379b44Stainless Bot2 years ago | 74 | |
| 75 | assert cast(Any, response.is_closed) is True | |
| 76 | | |
023a4e66Stainless Bot2 years ago | 77 | @parametrize |
| 78 | def test_path_params_create(self, client: OpenAI) -> None: | |
| 79 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 80 | client.beta.threads.messages.with_raw_response.create( | |
| 81 | "", | |
79a0b401Stainless Bot2 years ago | 82 | content="string", |
023a4e66Stainless Bot2 years ago | 83 | role="user", |
| 84 | ) | |
| 85 | | |
baa9f07fRobert Craigie2 years ago | 86 | @parametrize |
| 87 | def test_method_retrieve(self, client: OpenAI) -> None: | |
| 88 | message = client.beta.threads.messages.retrieve( | |
| 89 | "string", | |
| 90 | thread_id="string", | |
| 91 | ) | |
5429f696Stainless Bot2 years ago | 92 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 93 | |
| 94 | @parametrize | |
| 95 | def test_raw_response_retrieve(self, client: OpenAI) -> None: | |
| 96 | response = client.beta.threads.messages.with_raw_response.retrieve( | |
| 97 | "string", | |
| 98 | thread_id="string", | |
| 99 | ) | |
86379b44Stainless Bot2 years ago | 100 | |
| 101 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 102 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 103 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 104 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 105 | |
86379b44Stainless Bot2 years ago | 106 | @parametrize |
| 107 | def test_streaming_response_retrieve(self, client: OpenAI) -> None: | |
| 108 | with client.beta.threads.messages.with_streaming_response.retrieve( | |
| 109 | "string", | |
| 110 | thread_id="string", | |
| 111 | ) as response: | |
| 112 | assert not response.is_closed | |
| 113 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 114 | | |
| 115 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 116 | assert_matches_type(Message, message, path=["response"]) |
86379b44Stainless Bot2 years ago | 117 | |
| 118 | assert cast(Any, response.is_closed) is True | |
| 119 | | |
023a4e66Stainless Bot2 years ago | 120 | @parametrize |
| 121 | def test_path_params_retrieve(self, client: OpenAI) -> None: | |
| 122 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 123 | client.beta.threads.messages.with_raw_response.retrieve( | |
| 124 | "string", | |
| 125 | thread_id="", | |
| 126 | ) | |
| 127 | | |
| 128 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): | |
| 129 | client.beta.threads.messages.with_raw_response.retrieve( | |
| 130 | "", | |
| 131 | thread_id="string", | |
| 132 | ) | |
| 133 | | |
baa9f07fRobert Craigie2 years ago | 134 | @parametrize |
| 135 | def test_method_update(self, client: OpenAI) -> None: | |
| 136 | message = client.beta.threads.messages.update( | |
| 137 | "string", | |
| 138 | thread_id="string", | |
| 139 | ) | |
5429f696Stainless Bot2 years ago | 140 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 141 | |
| 142 | @parametrize | |
| 143 | def test_method_update_with_all_params(self, client: OpenAI) -> None: | |
| 144 | message = client.beta.threads.messages.update( | |
fdd52476stainless-app[bot]1 years ago | 145 | message_id="message_id", |
| 146 | thread_id="thread_id", | |
| 147 | metadata={"foo": "string"}, | |
baa9f07fRobert Craigie2 years ago | 148 | ) |
5429f696Stainless Bot2 years ago | 149 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 150 | |
| 151 | @parametrize | |
| 152 | def test_raw_response_update(self, client: OpenAI) -> None: | |
| 153 | response = client.beta.threads.messages.with_raw_response.update( | |
| 154 | "string", | |
| 155 | thread_id="string", | |
| 156 | ) | |
86379b44Stainless Bot2 years ago | 157 | |
| 158 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 159 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 160 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 161 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 162 | |
86379b44Stainless Bot2 years ago | 163 | @parametrize |
| 164 | def test_streaming_response_update(self, client: OpenAI) -> None: | |
| 165 | with client.beta.threads.messages.with_streaming_response.update( | |
| 166 | "string", | |
| 167 | thread_id="string", | |
| 168 | ) as response: | |
| 169 | assert not response.is_closed | |
| 170 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 171 | | |
| 172 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 173 | assert_matches_type(Message, message, path=["response"]) |
86379b44Stainless Bot2 years ago | 174 | |
| 175 | assert cast(Any, response.is_closed) is True | |
| 176 | | |
023a4e66Stainless Bot2 years ago | 177 | @parametrize |
| 178 | def test_path_params_update(self, client: OpenAI) -> None: | |
| 179 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 180 | client.beta.threads.messages.with_raw_response.update( | |
| 181 | "string", | |
| 182 | thread_id="", | |
| 183 | ) | |
| 184 | | |
| 185 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): | |
| 186 | client.beta.threads.messages.with_raw_response.update( | |
| 187 | "", | |
| 188 | thread_id="string", | |
| 189 | ) | |
| 190 | | |
baa9f07fRobert Craigie2 years ago | 191 | @parametrize |
| 192 | def test_method_list(self, client: OpenAI) -> None: | |
| 193 | message = client.beta.threads.messages.list( | |
| 194 | "string", | |
| 195 | ) | |
5429f696Stainless Bot2 years ago | 196 | assert_matches_type(SyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 197 | |
| 198 | @parametrize | |
| 199 | def test_method_list_with_all_params(self, client: OpenAI) -> None: | |
| 200 | message = client.beta.threads.messages.list( | |
| 201 | "string", | |
| 202 | after="string", | |
| 203 | before="string", | |
| 204 | limit=0, | |
| 205 | order="asc", | |
8efca3a3Stainless Bot2 years ago | 206 | run_id="string", |
baa9f07fRobert Craigie2 years ago | 207 | ) |
5429f696Stainless Bot2 years ago | 208 | assert_matches_type(SyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 209 | |
| 210 | @parametrize | |
| 211 | def test_raw_response_list(self, client: OpenAI) -> None: | |
| 212 | response = client.beta.threads.messages.with_raw_response.list( | |
| 213 | "string", | |
| 214 | ) | |
86379b44Stainless Bot2 years ago | 215 | |
| 216 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 217 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 218 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 219 | assert_matches_type(SyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 220 | |
86379b44Stainless Bot2 years ago | 221 | @parametrize |
| 222 | def test_streaming_response_list(self, client: OpenAI) -> None: | |
| 223 | with client.beta.threads.messages.with_streaming_response.list( | |
| 224 | "string", | |
| 225 | ) as response: | |
| 226 | assert not response.is_closed | |
| 227 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 228 | | |
| 229 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 230 | assert_matches_type(SyncCursorPage[Message], message, path=["response"]) |
86379b44Stainless Bot2 years ago | 231 | |
| 232 | assert cast(Any, response.is_closed) is True | |
| 233 | | |
023a4e66Stainless Bot2 years ago | 234 | @parametrize |
| 235 | def test_path_params_list(self, client: OpenAI) -> None: | |
| 236 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 237 | client.beta.threads.messages.with_raw_response.list( | |
| 238 | "", | |
| 239 | ) | |
| 240 | | |
d2738d42Stainless Bot2 years ago | 241 | @parametrize |
| 242 | def test_method_delete(self, client: OpenAI) -> None: | |
| 243 | message = client.beta.threads.messages.delete( | |
| 244 | "string", | |
| 245 | thread_id="string", | |
| 246 | ) | |
| 247 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
| 248 | | |
| 249 | @parametrize | |
| 250 | def test_raw_response_delete(self, client: OpenAI) -> None: | |
| 251 | response = client.beta.threads.messages.with_raw_response.delete( | |
| 252 | "string", | |
| 253 | thread_id="string", | |
| 254 | ) | |
| 255 | | |
| 256 | assert response.is_closed is True | |
| 257 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 258 | message = response.parse() | |
| 259 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
| 260 | | |
| 261 | @parametrize | |
| 262 | def test_streaming_response_delete(self, client: OpenAI) -> None: | |
| 263 | with client.beta.threads.messages.with_streaming_response.delete( | |
| 264 | "string", | |
| 265 | thread_id="string", | |
| 266 | ) as response: | |
| 267 | assert not response.is_closed | |
| 268 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 269 | | |
| 270 | message = response.parse() | |
| 271 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
| 272 | | |
| 273 | assert cast(Any, response.is_closed) is True | |
| 274 | | |
| 275 | @parametrize | |
| 276 | def test_path_params_delete(self, client: OpenAI) -> None: | |
| 277 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 278 | client.beta.threads.messages.with_raw_response.delete( | |
| 279 | "string", | |
| 280 | thread_id="", | |
| 281 | ) | |
| 282 | | |
| 283 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): | |
| 284 | client.beta.threads.messages.with_raw_response.delete( | |
| 285 | "", | |
| 286 | thread_id="string", | |
| 287 | ) | |
| 288 | | |
baa9f07fRobert Craigie2 years ago | 289 | |
| 290 | class TestAsyncMessages: | |
98d779fbStainless Bot2 years ago | 291 | parametrize = pytest.mark.parametrize("async_client", [False, True], indirect=True, ids=["loose", "strict"]) |
baa9f07fRobert Craigie2 years ago | 292 | |
| 293 | @parametrize | |
98d779fbStainless Bot2 years ago | 294 | async def test_method_create(self, async_client: AsyncOpenAI) -> None: |
| 295 | message = await async_client.beta.threads.messages.create( | |
baa9f07fRobert Craigie2 years ago | 296 | "string", |
79a0b401Stainless Bot2 years ago | 297 | content="string", |
baa9f07fRobert Craigie2 years ago | 298 | role="user", |
| 299 | ) | |
5429f696Stainless Bot2 years ago | 300 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 301 | |
| 302 | @parametrize | |
98d779fbStainless Bot2 years ago | 303 | async def test_method_create_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 304 | message = await async_client.beta.threads.messages.create( | |
baa9f07fRobert Craigie2 years ago | 305 | "string", |
79a0b401Stainless Bot2 years ago | 306 | content="string", |
baa9f07fRobert Craigie2 years ago | 307 | role="user", |
5b20698dStainless Bot2 years ago | 308 | attachments=[ |
| 309 | { | |
dd19d4f9Stainless Bot1 years ago | 310 | "file_id": "file_id", |
| 311 | "tools": [{"type": "code_interpreter"}], | |
| 312 | } | |
5b20698dStainless Bot2 years ago | 313 | ], |
fdd52476stainless-app[bot]1 years ago | 314 | metadata={"foo": "string"}, |
baa9f07fRobert Craigie2 years ago | 315 | ) |
5429f696Stainless Bot2 years ago | 316 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 317 | |
| 318 | @parametrize | |
98d779fbStainless Bot2 years ago | 319 | async def test_raw_response_create(self, async_client: AsyncOpenAI) -> None: |
| 320 | response = await async_client.beta.threads.messages.with_raw_response.create( | |
baa9f07fRobert Craigie2 years ago | 321 | "string", |
79a0b401Stainless Bot2 years ago | 322 | content="string", |
baa9f07fRobert Craigie2 years ago | 323 | role="user", |
| 324 | ) | |
86379b44Stainless Bot2 years ago | 325 | |
| 326 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 327 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 328 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 329 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 330 | |
86379b44Stainless Bot2 years ago | 331 | @parametrize |
98d779fbStainless Bot2 years ago | 332 | async def test_streaming_response_create(self, async_client: AsyncOpenAI) -> None: |
| 333 | async with async_client.beta.threads.messages.with_streaming_response.create( | |
86379b44Stainless Bot2 years ago | 334 | "string", |
79a0b401Stainless Bot2 years ago | 335 | content="string", |
86379b44Stainless Bot2 years ago | 336 | role="user", |
| 337 | ) as response: | |
| 338 | assert not response.is_closed | |
| 339 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 340 | | |
| 341 | message = await response.parse() | |
5429f696Stainless Bot2 years ago | 342 | assert_matches_type(Message, message, path=["response"]) |
86379b44Stainless Bot2 years ago | 343 | |
| 344 | assert cast(Any, response.is_closed) is True | |
| 345 | | |
023a4e66Stainless Bot2 years ago | 346 | @parametrize |
98d779fbStainless Bot2 years ago | 347 | async def test_path_params_create(self, async_client: AsyncOpenAI) -> None: |
023a4e66Stainless Bot2 years ago | 348 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
98d779fbStainless Bot2 years ago | 349 | await async_client.beta.threads.messages.with_raw_response.create( |
023a4e66Stainless Bot2 years ago | 350 | "", |
79a0b401Stainless Bot2 years ago | 351 | content="string", |
023a4e66Stainless Bot2 years ago | 352 | role="user", |
| 353 | ) | |
| 354 | | |
baa9f07fRobert Craigie2 years ago | 355 | @parametrize |
98d779fbStainless Bot2 years ago | 356 | async def test_method_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 357 | message = await async_client.beta.threads.messages.retrieve( | |
baa9f07fRobert Craigie2 years ago | 358 | "string", |
| 359 | thread_id="string", | |
| 360 | ) | |
5429f696Stainless Bot2 years ago | 361 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 362 | |
| 363 | @parametrize | |
98d779fbStainless Bot2 years ago | 364 | async def test_raw_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 365 | response = await async_client.beta.threads.messages.with_raw_response.retrieve( | |
baa9f07fRobert Craigie2 years ago | 366 | "string", |
| 367 | thread_id="string", | |
| 368 | ) | |
86379b44Stainless Bot2 years ago | 369 | |
| 370 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 371 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 372 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 373 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 374 | |
86379b44Stainless Bot2 years ago | 375 | @parametrize |
98d779fbStainless Bot2 years ago | 376 | async def test_streaming_response_retrieve(self, async_client: AsyncOpenAI) -> None: |
| 377 | async with async_client.beta.threads.messages.with_streaming_response.retrieve( | |
86379b44Stainless Bot2 years ago | 378 | "string", |
| 379 | thread_id="string", | |
| 380 | ) as response: | |
| 381 | assert not response.is_closed | |
| 382 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 383 | | |
| 384 | message = await response.parse() | |
5429f696Stainless Bot2 years ago | 385 | assert_matches_type(Message, message, path=["response"]) |
86379b44Stainless Bot2 years ago | 386 | |
| 387 | assert cast(Any, response.is_closed) is True | |
| 388 | | |
023a4e66Stainless Bot2 years ago | 389 | @parametrize |
98d779fbStainless Bot2 years ago | 390 | async def test_path_params_retrieve(self, async_client: AsyncOpenAI) -> None: |
023a4e66Stainless Bot2 years ago | 391 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
98d779fbStainless Bot2 years ago | 392 | await async_client.beta.threads.messages.with_raw_response.retrieve( |
023a4e66Stainless Bot2 years ago | 393 | "string", |
| 394 | thread_id="", | |
| 395 | ) | |
| 396 | | |
| 397 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): | |
98d779fbStainless Bot2 years ago | 398 | await async_client.beta.threads.messages.with_raw_response.retrieve( |
023a4e66Stainless Bot2 years ago | 399 | "", |
| 400 | thread_id="string", | |
| 401 | ) | |
| 402 | | |
baa9f07fRobert Craigie2 years ago | 403 | @parametrize |
98d779fbStainless Bot2 years ago | 404 | async def test_method_update(self, async_client: AsyncOpenAI) -> None: |
| 405 | message = await async_client.beta.threads.messages.update( | |
baa9f07fRobert Craigie2 years ago | 406 | "string", |
| 407 | thread_id="string", | |
| 408 | ) | |
5429f696Stainless Bot2 years ago | 409 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 410 | |
| 411 | @parametrize | |
98d779fbStainless Bot2 years ago | 412 | async def test_method_update_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 413 | message = await async_client.beta.threads.messages.update( | |
fdd52476stainless-app[bot]1 years ago | 414 | message_id="message_id", |
| 415 | thread_id="thread_id", | |
| 416 | metadata={"foo": "string"}, | |
baa9f07fRobert Craigie2 years ago | 417 | ) |
5429f696Stainless Bot2 years ago | 418 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 419 | |
| 420 | @parametrize | |
98d779fbStainless Bot2 years ago | 421 | async def test_raw_response_update(self, async_client: AsyncOpenAI) -> None: |
| 422 | response = await async_client.beta.threads.messages.with_raw_response.update( | |
baa9f07fRobert Craigie2 years ago | 423 | "string", |
| 424 | thread_id="string", | |
| 425 | ) | |
86379b44Stainless Bot2 years ago | 426 | |
| 427 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 428 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 429 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 430 | assert_matches_type(Message, message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 431 | |
86379b44Stainless Bot2 years ago | 432 | @parametrize |
98d779fbStainless Bot2 years ago | 433 | async def test_streaming_response_update(self, async_client: AsyncOpenAI) -> None: |
| 434 | async with async_client.beta.threads.messages.with_streaming_response.update( | |
86379b44Stainless Bot2 years ago | 435 | "string", |
| 436 | thread_id="string", | |
| 437 | ) as response: | |
| 438 | assert not response.is_closed | |
| 439 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 440 | | |
| 441 | message = await response.parse() | |
5429f696Stainless Bot2 years ago | 442 | assert_matches_type(Message, message, path=["response"]) |
86379b44Stainless Bot2 years ago | 443 | |
| 444 | assert cast(Any, response.is_closed) is True | |
| 445 | | |
023a4e66Stainless Bot2 years ago | 446 | @parametrize |
98d779fbStainless Bot2 years ago | 447 | async def test_path_params_update(self, async_client: AsyncOpenAI) -> None: |
023a4e66Stainless Bot2 years ago | 448 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
98d779fbStainless Bot2 years ago | 449 | await async_client.beta.threads.messages.with_raw_response.update( |
023a4e66Stainless Bot2 years ago | 450 | "string", |
| 451 | thread_id="", | |
| 452 | ) | |
| 453 | | |
| 454 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): | |
98d779fbStainless Bot2 years ago | 455 | await async_client.beta.threads.messages.with_raw_response.update( |
023a4e66Stainless Bot2 years ago | 456 | "", |
| 457 | thread_id="string", | |
| 458 | ) | |
| 459 | | |
baa9f07fRobert Craigie2 years ago | 460 | @parametrize |
98d779fbStainless Bot2 years ago | 461 | async def test_method_list(self, async_client: AsyncOpenAI) -> None: |
| 462 | message = await async_client.beta.threads.messages.list( | |
baa9f07fRobert Craigie2 years ago | 463 | "string", |
| 464 | ) | |
5429f696Stainless Bot2 years ago | 465 | assert_matches_type(AsyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 466 | |
| 467 | @parametrize | |
98d779fbStainless Bot2 years ago | 468 | async def test_method_list_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 469 | message = await async_client.beta.threads.messages.list( | |
baa9f07fRobert Craigie2 years ago | 470 | "string", |
| 471 | after="string", | |
| 472 | before="string", | |
| 473 | limit=0, | |
| 474 | order="asc", | |
8efca3a3Stainless Bot2 years ago | 475 | run_id="string", |
baa9f07fRobert Craigie2 years ago | 476 | ) |
5429f696Stainless Bot2 years ago | 477 | assert_matches_type(AsyncCursorPage[Message], message, path=["response"]) |
baa9f07fRobert Craigie2 years ago | 478 | |
| 479 | @parametrize | |
98d779fbStainless Bot2 years ago | 480 | async def test_raw_response_list(self, async_client: AsyncOpenAI) -> None: |
| 481 | response = await async_client.beta.threads.messages.with_raw_response.list( | |
baa9f07fRobert Craigie2 years ago | 482 | "string", |
| 483 | ) | |
86379b44Stainless Bot2 years ago | 484 | |
| 485 | assert response.is_closed is True | |
baa9f07fRobert Craigie2 years ago | 486 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 487 | message = response.parse() | |
5429f696Stainless Bot2 years ago | 488 | assert_matches_type(AsyncCursorPage[Message], message, path=["response"]) |
86379b44Stainless Bot2 years ago | 489 | |
| 490 | @parametrize | |
98d779fbStainless Bot2 years ago | 491 | async def test_streaming_response_list(self, async_client: AsyncOpenAI) -> None: |
| 492 | async with async_client.beta.threads.messages.with_streaming_response.list( | |
86379b44Stainless Bot2 years ago | 493 | "string", |
| 494 | ) as response: | |
| 495 | assert not response.is_closed | |
| 496 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 497 | | |
| 498 | message = await response.parse() | |
5429f696Stainless Bot2 years ago | 499 | assert_matches_type(AsyncCursorPage[Message], message, path=["response"]) |
86379b44Stainless Bot2 years ago | 500 | |
| 501 | assert cast(Any, response.is_closed) is True | |
023a4e66Stainless Bot2 years ago | 502 | |
| 503 | @parametrize | |
98d779fbStainless Bot2 years ago | 504 | async def test_path_params_list(self, async_client: AsyncOpenAI) -> None: |
023a4e66Stainless Bot2 years ago | 505 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): |
98d779fbStainless Bot2 years ago | 506 | await async_client.beta.threads.messages.with_raw_response.list( |
023a4e66Stainless Bot2 years ago | 507 | "", |
| 508 | ) | |
d2738d42Stainless Bot2 years ago | 509 | |
| 510 | @parametrize | |
| 511 | async def test_method_delete(self, async_client: AsyncOpenAI) -> None: | |
| 512 | message = await async_client.beta.threads.messages.delete( | |
| 513 | "string", | |
| 514 | thread_id="string", | |
| 515 | ) | |
| 516 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
| 517 | | |
| 518 | @parametrize | |
| 519 | async def test_raw_response_delete(self, async_client: AsyncOpenAI) -> None: | |
| 520 | response = await async_client.beta.threads.messages.with_raw_response.delete( | |
| 521 | "string", | |
| 522 | thread_id="string", | |
| 523 | ) | |
| 524 | | |
| 525 | assert response.is_closed is True | |
| 526 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 527 | message = response.parse() | |
| 528 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
| 529 | | |
| 530 | @parametrize | |
| 531 | async def test_streaming_response_delete(self, async_client: AsyncOpenAI) -> None: | |
| 532 | async with async_client.beta.threads.messages.with_streaming_response.delete( | |
| 533 | "string", | |
| 534 | thread_id="string", | |
| 535 | ) as response: | |
| 536 | assert not response.is_closed | |
| 537 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" | |
| 538 | | |
| 539 | message = await response.parse() | |
| 540 | assert_matches_type(MessageDeleted, message, path=["response"]) | |
| 541 | | |
| 542 | assert cast(Any, response.is_closed) is True | |
| 543 | | |
| 544 | @parametrize | |
| 545 | async def test_path_params_delete(self, async_client: AsyncOpenAI) -> None: | |
| 546 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `thread_id` but received ''"): | |
| 547 | await async_client.beta.threads.messages.with_raw_response.delete( | |
| 548 | "string", | |
| 549 | thread_id="", | |
| 550 | ) | |
| 551 | | |
| 552 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `message_id` but received ''"): | |
| 553 | await async_client.beta.threads.messages.with_raw_response.delete( | |
| 554 | "", | |
| 555 | thread_id="string", | |
| 556 | ) |