openai/openai-python
Publicmirrored fromhttps://github.com/openai/openai-pythonAvailable
tests/api_resources/realtime/test_calls.py
704lines · modecode
| 1 | # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | import os |
| 6 | from typing import Any, cast |
| 7 | |
| 8 | import httpx |
| 9 | import pytest |
| 10 | from respx import MockRouter |
| 11 | |
| 12 | import openai._legacy_response as _legacy_response |
| 13 | from openai import OpenAI, AsyncOpenAI |
| 14 | from tests.utils import assert_matches_type |
| 15 | |
| 16 | # pyright: reportDeprecated=false |
| 17 | |
| 18 | base_url = os.environ.get("TEST_API_BASE_URL", "http://127.0.0.1:4010") |
| 19 | |
| 20 | |
| 21 | class TestCalls: |
| 22 | parametrize = pytest.mark.parametrize("client", [False, True], indirect=True, ids=["loose", "strict"]) |
| 23 | |
| 24 | @parametrize |
| 25 | @pytest.mark.respx(base_url=base_url) |
| 26 | def test_method_create(self, client: OpenAI, respx_mock: MockRouter) -> None: |
| 27 | respx_mock.post("/realtime/calls").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 28 | call = client.realtime.calls.create( |
| 29 | sdp="sdp", |
| 30 | ) |
| 31 | assert isinstance(call, _legacy_response.HttpxBinaryResponseContent) |
| 32 | assert call.json() == {"foo": "bar"} |
| 33 | |
| 34 | @parametrize |
| 35 | @pytest.mark.respx(base_url=base_url) |
| 36 | def test_method_create_with_all_params(self, client: OpenAI, respx_mock: MockRouter) -> None: |
| 37 | respx_mock.post("/realtime/calls").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 38 | call = client.realtime.calls.create( |
| 39 | sdp="sdp", |
| 40 | session={ |
| 41 | "type": "realtime", |
| 42 | "audio": { |
| 43 | "input": { |
| 44 | "format": { |
| 45 | "rate": 24000, |
| 46 | "type": "audio/pcm", |
| 47 | }, |
| 48 | "noise_reduction": {"type": "near_field"}, |
| 49 | "transcription": { |
| 50 | "delay": "minimal", |
| 51 | "language": "language", |
| 52 | "model": "whisper-1", |
| 53 | "prompt": "prompt", |
| 54 | }, |
| 55 | "turn_detection": { |
| 56 | "type": "server_vad", |
| 57 | "create_response": True, |
| 58 | "idle_timeout_ms": 5000, |
| 59 | "interrupt_response": True, |
| 60 | "prefix_padding_ms": 0, |
| 61 | "silence_duration_ms": 0, |
| 62 | "threshold": 0, |
| 63 | }, |
| 64 | }, |
| 65 | "output": { |
| 66 | "format": { |
| 67 | "rate": 24000, |
| 68 | "type": "audio/pcm", |
| 69 | }, |
| 70 | "speed": 0.25, |
| 71 | "voice": "alloy", |
| 72 | }, |
| 73 | }, |
| 74 | "include": ["item.input_audio_transcription.logprobs"], |
| 75 | "instructions": "instructions", |
| 76 | "max_output_tokens": "inf", |
| 77 | "model": "gpt-realtime", |
| 78 | "output_modalities": ["text"], |
| 79 | "parallel_tool_calls": True, |
| 80 | "prompt": { |
| 81 | "id": "id", |
| 82 | "variables": {"foo": "string"}, |
| 83 | "version": "version", |
| 84 | }, |
| 85 | "reasoning": {"effort": "minimal"}, |
| 86 | "tool_choice": "none", |
| 87 | "tools": [ |
| 88 | { |
| 89 | "description": "description", |
| 90 | "name": "name", |
| 91 | "parameters": {}, |
| 92 | "type": "function", |
| 93 | } |
| 94 | ], |
| 95 | "tracing": "auto", |
| 96 | "truncation": "auto", |
| 97 | }, |
| 98 | ) |
| 99 | assert isinstance(call, _legacy_response.HttpxBinaryResponseContent) |
| 100 | assert call.json() == {"foo": "bar"} |
| 101 | |
| 102 | @parametrize |
| 103 | @pytest.mark.respx(base_url=base_url) |
| 104 | def test_raw_response_create(self, client: OpenAI, respx_mock: MockRouter) -> None: |
| 105 | respx_mock.post("/realtime/calls").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 106 | |
| 107 | response = client.realtime.calls.with_raw_response.create( |
| 108 | sdp="sdp", |
| 109 | ) |
| 110 | |
| 111 | assert response.is_closed is True |
| 112 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 113 | call = response.parse() |
| 114 | assert_matches_type(_legacy_response.HttpxBinaryResponseContent, call, path=["response"]) |
| 115 | |
| 116 | @parametrize |
| 117 | @pytest.mark.respx(base_url=base_url) |
| 118 | def test_streaming_response_create(self, client: OpenAI, respx_mock: MockRouter) -> None: |
| 119 | respx_mock.post("/realtime/calls").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 120 | with client.realtime.calls.with_streaming_response.create( |
| 121 | sdp="sdp", |
| 122 | ) as response: |
| 123 | assert not response.is_closed |
| 124 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 125 | |
| 126 | call = response.parse() |
| 127 | assert_matches_type(bytes, call, path=["response"]) |
| 128 | |
| 129 | assert cast(Any, response.is_closed) is True |
| 130 | |
| 131 | @parametrize |
| 132 | def test_method_accept(self, client: OpenAI) -> None: |
| 133 | call = client.realtime.calls.accept( |
| 134 | call_id="call_id", |
| 135 | type="realtime", |
| 136 | ) |
| 137 | assert call is None |
| 138 | |
| 139 | @parametrize |
| 140 | def test_method_accept_with_all_params(self, client: OpenAI) -> None: |
| 141 | call = client.realtime.calls.accept( |
| 142 | call_id="call_id", |
| 143 | type="realtime", |
| 144 | audio={ |
| 145 | "input": { |
| 146 | "format": { |
| 147 | "rate": 24000, |
| 148 | "type": "audio/pcm", |
| 149 | }, |
| 150 | "noise_reduction": {"type": "near_field"}, |
| 151 | "transcription": { |
| 152 | "delay": "minimal", |
| 153 | "language": "language", |
| 154 | "model": "whisper-1", |
| 155 | "prompt": "prompt", |
| 156 | }, |
| 157 | "turn_detection": { |
| 158 | "type": "server_vad", |
| 159 | "create_response": True, |
| 160 | "idle_timeout_ms": 5000, |
| 161 | "interrupt_response": True, |
| 162 | "prefix_padding_ms": 0, |
| 163 | "silence_duration_ms": 0, |
| 164 | "threshold": 0, |
| 165 | }, |
| 166 | }, |
| 167 | "output": { |
| 168 | "format": { |
| 169 | "rate": 24000, |
| 170 | "type": "audio/pcm", |
| 171 | }, |
| 172 | "speed": 0.25, |
| 173 | "voice": "alloy", |
| 174 | }, |
| 175 | }, |
| 176 | include=["item.input_audio_transcription.logprobs"], |
| 177 | instructions="instructions", |
| 178 | max_output_tokens="inf", |
| 179 | model="gpt-realtime", |
| 180 | output_modalities=["text"], |
| 181 | parallel_tool_calls=True, |
| 182 | prompt={ |
| 183 | "id": "id", |
| 184 | "variables": {"foo": "string"}, |
| 185 | "version": "version", |
| 186 | }, |
| 187 | reasoning={"effort": "minimal"}, |
| 188 | tool_choice="none", |
| 189 | tools=[ |
| 190 | { |
| 191 | "description": "description", |
| 192 | "name": "name", |
| 193 | "parameters": {}, |
| 194 | "type": "function", |
| 195 | } |
| 196 | ], |
| 197 | tracing="auto", |
| 198 | truncation="auto", |
| 199 | ) |
| 200 | assert call is None |
| 201 | |
| 202 | @parametrize |
| 203 | def test_raw_response_accept(self, client: OpenAI) -> None: |
| 204 | response = client.realtime.calls.with_raw_response.accept( |
| 205 | call_id="call_id", |
| 206 | type="realtime", |
| 207 | ) |
| 208 | |
| 209 | assert response.is_closed is True |
| 210 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 211 | call = response.parse() |
| 212 | assert call is None |
| 213 | |
| 214 | @parametrize |
| 215 | def test_streaming_response_accept(self, client: OpenAI) -> None: |
| 216 | with client.realtime.calls.with_streaming_response.accept( |
| 217 | call_id="call_id", |
| 218 | type="realtime", |
| 219 | ) as response: |
| 220 | assert not response.is_closed |
| 221 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 222 | |
| 223 | call = response.parse() |
| 224 | assert call is None |
| 225 | |
| 226 | assert cast(Any, response.is_closed) is True |
| 227 | |
| 228 | @parametrize |
| 229 | def test_path_params_accept(self, client: OpenAI) -> None: |
| 230 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `call_id` but received ''"): |
| 231 | client.realtime.calls.with_raw_response.accept( |
| 232 | call_id="", |
| 233 | type="realtime", |
| 234 | ) |
| 235 | |
| 236 | @parametrize |
| 237 | def test_method_hangup(self, client: OpenAI) -> None: |
| 238 | call = client.realtime.calls.hangup( |
| 239 | "call_id", |
| 240 | ) |
| 241 | assert call is None |
| 242 | |
| 243 | @parametrize |
| 244 | def test_raw_response_hangup(self, client: OpenAI) -> None: |
| 245 | response = client.realtime.calls.with_raw_response.hangup( |
| 246 | "call_id", |
| 247 | ) |
| 248 | |
| 249 | assert response.is_closed is True |
| 250 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 251 | call = response.parse() |
| 252 | assert call is None |
| 253 | |
| 254 | @parametrize |
| 255 | def test_streaming_response_hangup(self, client: OpenAI) -> None: |
| 256 | with client.realtime.calls.with_streaming_response.hangup( |
| 257 | "call_id", |
| 258 | ) as response: |
| 259 | assert not response.is_closed |
| 260 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 261 | |
| 262 | call = response.parse() |
| 263 | assert call is None |
| 264 | |
| 265 | assert cast(Any, response.is_closed) is True |
| 266 | |
| 267 | @parametrize |
| 268 | def test_path_params_hangup(self, client: OpenAI) -> None: |
| 269 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `call_id` but received ''"): |
| 270 | client.realtime.calls.with_raw_response.hangup( |
| 271 | "", |
| 272 | ) |
| 273 | |
| 274 | @parametrize |
| 275 | def test_method_refer(self, client: OpenAI) -> None: |
| 276 | call = client.realtime.calls.refer( |
| 277 | call_id="call_id", |
| 278 | target_uri="tel:+14155550123", |
| 279 | ) |
| 280 | assert call is None |
| 281 | |
| 282 | @parametrize |
| 283 | def test_raw_response_refer(self, client: OpenAI) -> None: |
| 284 | response = client.realtime.calls.with_raw_response.refer( |
| 285 | call_id="call_id", |
| 286 | target_uri="tel:+14155550123", |
| 287 | ) |
| 288 | |
| 289 | assert response.is_closed is True |
| 290 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 291 | call = response.parse() |
| 292 | assert call is None |
| 293 | |
| 294 | @parametrize |
| 295 | def test_streaming_response_refer(self, client: OpenAI) -> None: |
| 296 | with client.realtime.calls.with_streaming_response.refer( |
| 297 | call_id="call_id", |
| 298 | target_uri="tel:+14155550123", |
| 299 | ) as response: |
| 300 | assert not response.is_closed |
| 301 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 302 | |
| 303 | call = response.parse() |
| 304 | assert call is None |
| 305 | |
| 306 | assert cast(Any, response.is_closed) is True |
| 307 | |
| 308 | @parametrize |
| 309 | def test_path_params_refer(self, client: OpenAI) -> None: |
| 310 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `call_id` but received ''"): |
| 311 | client.realtime.calls.with_raw_response.refer( |
| 312 | call_id="", |
| 313 | target_uri="tel:+14155550123", |
| 314 | ) |
| 315 | |
| 316 | @parametrize |
| 317 | def test_method_reject(self, client: OpenAI) -> None: |
| 318 | call = client.realtime.calls.reject( |
| 319 | call_id="call_id", |
| 320 | ) |
| 321 | assert call is None |
| 322 | |
| 323 | @parametrize |
| 324 | def test_method_reject_with_all_params(self, client: OpenAI) -> None: |
| 325 | call = client.realtime.calls.reject( |
| 326 | call_id="call_id", |
| 327 | status_code=486, |
| 328 | ) |
| 329 | assert call is None |
| 330 | |
| 331 | @parametrize |
| 332 | def test_raw_response_reject(self, client: OpenAI) -> None: |
| 333 | response = client.realtime.calls.with_raw_response.reject( |
| 334 | call_id="call_id", |
| 335 | ) |
| 336 | |
| 337 | assert response.is_closed is True |
| 338 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 339 | call = response.parse() |
| 340 | assert call is None |
| 341 | |
| 342 | @parametrize |
| 343 | def test_streaming_response_reject(self, client: OpenAI) -> None: |
| 344 | with client.realtime.calls.with_streaming_response.reject( |
| 345 | call_id="call_id", |
| 346 | ) as response: |
| 347 | assert not response.is_closed |
| 348 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 349 | |
| 350 | call = response.parse() |
| 351 | assert call is None |
| 352 | |
| 353 | assert cast(Any, response.is_closed) is True |
| 354 | |
| 355 | @parametrize |
| 356 | def test_path_params_reject(self, client: OpenAI) -> None: |
| 357 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `call_id` but received ''"): |
| 358 | client.realtime.calls.with_raw_response.reject( |
| 359 | call_id="", |
| 360 | ) |
| 361 | |
| 362 | |
| 363 | class TestAsyncCalls: |
| 364 | parametrize = pytest.mark.parametrize( |
| 365 | "async_client", [False, True, {"http_client": "aiohttp"}], indirect=True, ids=["loose", "strict", "aiohttp"] |
| 366 | ) |
| 367 | |
| 368 | @parametrize |
| 369 | @pytest.mark.respx(base_url=base_url) |
| 370 | async def test_method_create(self, async_client: AsyncOpenAI, respx_mock: MockRouter) -> None: |
| 371 | respx_mock.post("/realtime/calls").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 372 | call = await async_client.realtime.calls.create( |
| 373 | sdp="sdp", |
| 374 | ) |
| 375 | assert isinstance(call, _legacy_response.HttpxBinaryResponseContent) |
| 376 | assert call.json() == {"foo": "bar"} |
| 377 | |
| 378 | @parametrize |
| 379 | @pytest.mark.respx(base_url=base_url) |
| 380 | async def test_method_create_with_all_params(self, async_client: AsyncOpenAI, respx_mock: MockRouter) -> None: |
| 381 | respx_mock.post("/realtime/calls").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 382 | call = await async_client.realtime.calls.create( |
| 383 | sdp="sdp", |
| 384 | session={ |
| 385 | "type": "realtime", |
| 386 | "audio": { |
| 387 | "input": { |
| 388 | "format": { |
| 389 | "rate": 24000, |
| 390 | "type": "audio/pcm", |
| 391 | }, |
| 392 | "noise_reduction": {"type": "near_field"}, |
| 393 | "transcription": { |
| 394 | "delay": "minimal", |
| 395 | "language": "language", |
| 396 | "model": "whisper-1", |
| 397 | "prompt": "prompt", |
| 398 | }, |
| 399 | "turn_detection": { |
| 400 | "type": "server_vad", |
| 401 | "create_response": True, |
| 402 | "idle_timeout_ms": 5000, |
| 403 | "interrupt_response": True, |
| 404 | "prefix_padding_ms": 0, |
| 405 | "silence_duration_ms": 0, |
| 406 | "threshold": 0, |
| 407 | }, |
| 408 | }, |
| 409 | "output": { |
| 410 | "format": { |
| 411 | "rate": 24000, |
| 412 | "type": "audio/pcm", |
| 413 | }, |
| 414 | "speed": 0.25, |
| 415 | "voice": "alloy", |
| 416 | }, |
| 417 | }, |
| 418 | "include": ["item.input_audio_transcription.logprobs"], |
| 419 | "instructions": "instructions", |
| 420 | "max_output_tokens": "inf", |
| 421 | "model": "gpt-realtime", |
| 422 | "output_modalities": ["text"], |
| 423 | "parallel_tool_calls": True, |
| 424 | "prompt": { |
| 425 | "id": "id", |
| 426 | "variables": {"foo": "string"}, |
| 427 | "version": "version", |
| 428 | }, |
| 429 | "reasoning": {"effort": "minimal"}, |
| 430 | "tool_choice": "none", |
| 431 | "tools": [ |
| 432 | { |
| 433 | "description": "description", |
| 434 | "name": "name", |
| 435 | "parameters": {}, |
| 436 | "type": "function", |
| 437 | } |
| 438 | ], |
| 439 | "tracing": "auto", |
| 440 | "truncation": "auto", |
| 441 | }, |
| 442 | ) |
| 443 | assert isinstance(call, _legacy_response.HttpxBinaryResponseContent) |
| 444 | assert call.json() == {"foo": "bar"} |
| 445 | |
| 446 | @parametrize |
| 447 | @pytest.mark.respx(base_url=base_url) |
| 448 | async def test_raw_response_create(self, async_client: AsyncOpenAI, respx_mock: MockRouter) -> None: |
| 449 | respx_mock.post("/realtime/calls").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 450 | |
| 451 | response = await async_client.realtime.calls.with_raw_response.create( |
| 452 | sdp="sdp", |
| 453 | ) |
| 454 | |
| 455 | assert response.is_closed is True |
| 456 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 457 | call = response.parse() |
| 458 | assert_matches_type(_legacy_response.HttpxBinaryResponseContent, call, path=["response"]) |
| 459 | |
| 460 | @parametrize |
| 461 | @pytest.mark.respx(base_url=base_url) |
| 462 | async def test_streaming_response_create(self, async_client: AsyncOpenAI, respx_mock: MockRouter) -> None: |
| 463 | respx_mock.post("/realtime/calls").mock(return_value=httpx.Response(200, json={"foo": "bar"})) |
| 464 | async with async_client.realtime.calls.with_streaming_response.create( |
| 465 | sdp="sdp", |
| 466 | ) as response: |
| 467 | assert not response.is_closed |
| 468 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 469 | |
| 470 | call = await response.parse() |
| 471 | assert_matches_type(bytes, call, path=["response"]) |
| 472 | |
| 473 | assert cast(Any, response.is_closed) is True |
| 474 | |
| 475 | @parametrize |
| 476 | async def test_method_accept(self, async_client: AsyncOpenAI) -> None: |
| 477 | call = await async_client.realtime.calls.accept( |
| 478 | call_id="call_id", |
| 479 | type="realtime", |
| 480 | ) |
| 481 | assert call is None |
| 482 | |
| 483 | @parametrize |
| 484 | async def test_method_accept_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 485 | call = await async_client.realtime.calls.accept( |
| 486 | call_id="call_id", |
| 487 | type="realtime", |
| 488 | audio={ |
| 489 | "input": { |
| 490 | "format": { |
| 491 | "rate": 24000, |
| 492 | "type": "audio/pcm", |
| 493 | }, |
| 494 | "noise_reduction": {"type": "near_field"}, |
| 495 | "transcription": { |
| 496 | "delay": "minimal", |
| 497 | "language": "language", |
| 498 | "model": "whisper-1", |
| 499 | "prompt": "prompt", |
| 500 | }, |
| 501 | "turn_detection": { |
| 502 | "type": "server_vad", |
| 503 | "create_response": True, |
| 504 | "idle_timeout_ms": 5000, |
| 505 | "interrupt_response": True, |
| 506 | "prefix_padding_ms": 0, |
| 507 | "silence_duration_ms": 0, |
| 508 | "threshold": 0, |
| 509 | }, |
| 510 | }, |
| 511 | "output": { |
| 512 | "format": { |
| 513 | "rate": 24000, |
| 514 | "type": "audio/pcm", |
| 515 | }, |
| 516 | "speed": 0.25, |
| 517 | "voice": "alloy", |
| 518 | }, |
| 519 | }, |
| 520 | include=["item.input_audio_transcription.logprobs"], |
| 521 | instructions="instructions", |
| 522 | max_output_tokens="inf", |
| 523 | model="gpt-realtime", |
| 524 | output_modalities=["text"], |
| 525 | parallel_tool_calls=True, |
| 526 | prompt={ |
| 527 | "id": "id", |
| 528 | "variables": {"foo": "string"}, |
| 529 | "version": "version", |
| 530 | }, |
| 531 | reasoning={"effort": "minimal"}, |
| 532 | tool_choice="none", |
| 533 | tools=[ |
| 534 | { |
| 535 | "description": "description", |
| 536 | "name": "name", |
| 537 | "parameters": {}, |
| 538 | "type": "function", |
| 539 | } |
| 540 | ], |
| 541 | tracing="auto", |
| 542 | truncation="auto", |
| 543 | ) |
| 544 | assert call is None |
| 545 | |
| 546 | @parametrize |
| 547 | async def test_raw_response_accept(self, async_client: AsyncOpenAI) -> None: |
| 548 | response = await async_client.realtime.calls.with_raw_response.accept( |
| 549 | call_id="call_id", |
| 550 | type="realtime", |
| 551 | ) |
| 552 | |
| 553 | assert response.is_closed is True |
| 554 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 555 | call = response.parse() |
| 556 | assert call is None |
| 557 | |
| 558 | @parametrize |
| 559 | async def test_streaming_response_accept(self, async_client: AsyncOpenAI) -> None: |
| 560 | async with async_client.realtime.calls.with_streaming_response.accept( |
| 561 | call_id="call_id", |
| 562 | type="realtime", |
| 563 | ) as response: |
| 564 | assert not response.is_closed |
| 565 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 566 | |
| 567 | call = await response.parse() |
| 568 | assert call is None |
| 569 | |
| 570 | assert cast(Any, response.is_closed) is True |
| 571 | |
| 572 | @parametrize |
| 573 | async def test_path_params_accept(self, async_client: AsyncOpenAI) -> None: |
| 574 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `call_id` but received ''"): |
| 575 | await async_client.realtime.calls.with_raw_response.accept( |
| 576 | call_id="", |
| 577 | type="realtime", |
| 578 | ) |
| 579 | |
| 580 | @parametrize |
| 581 | async def test_method_hangup(self, async_client: AsyncOpenAI) -> None: |
| 582 | call = await async_client.realtime.calls.hangup( |
| 583 | "call_id", |
| 584 | ) |
| 585 | assert call is None |
| 586 | |
| 587 | @parametrize |
| 588 | async def test_raw_response_hangup(self, async_client: AsyncOpenAI) -> None: |
| 589 | response = await async_client.realtime.calls.with_raw_response.hangup( |
| 590 | "call_id", |
| 591 | ) |
| 592 | |
| 593 | assert response.is_closed is True |
| 594 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 595 | call = response.parse() |
| 596 | assert call is None |
| 597 | |
| 598 | @parametrize |
| 599 | async def test_streaming_response_hangup(self, async_client: AsyncOpenAI) -> None: |
| 600 | async with async_client.realtime.calls.with_streaming_response.hangup( |
| 601 | "call_id", |
| 602 | ) as response: |
| 603 | assert not response.is_closed |
| 604 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 605 | |
| 606 | call = await response.parse() |
| 607 | assert call is None |
| 608 | |
| 609 | assert cast(Any, response.is_closed) is True |
| 610 | |
| 611 | @parametrize |
| 612 | async def test_path_params_hangup(self, async_client: AsyncOpenAI) -> None: |
| 613 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `call_id` but received ''"): |
| 614 | await async_client.realtime.calls.with_raw_response.hangup( |
| 615 | "", |
| 616 | ) |
| 617 | |
| 618 | @parametrize |
| 619 | async def test_method_refer(self, async_client: AsyncOpenAI) -> None: |
| 620 | call = await async_client.realtime.calls.refer( |
| 621 | call_id="call_id", |
| 622 | target_uri="tel:+14155550123", |
| 623 | ) |
| 624 | assert call is None |
| 625 | |
| 626 | @parametrize |
| 627 | async def test_raw_response_refer(self, async_client: AsyncOpenAI) -> None: |
| 628 | response = await async_client.realtime.calls.with_raw_response.refer( |
| 629 | call_id="call_id", |
| 630 | target_uri="tel:+14155550123", |
| 631 | ) |
| 632 | |
| 633 | assert response.is_closed is True |
| 634 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 635 | call = response.parse() |
| 636 | assert call is None |
| 637 | |
| 638 | @parametrize |
| 639 | async def test_streaming_response_refer(self, async_client: AsyncOpenAI) -> None: |
| 640 | async with async_client.realtime.calls.with_streaming_response.refer( |
| 641 | call_id="call_id", |
| 642 | target_uri="tel:+14155550123", |
| 643 | ) as response: |
| 644 | assert not response.is_closed |
| 645 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 646 | |
| 647 | call = await response.parse() |
| 648 | assert call is None |
| 649 | |
| 650 | assert cast(Any, response.is_closed) is True |
| 651 | |
| 652 | @parametrize |
| 653 | async def test_path_params_refer(self, async_client: AsyncOpenAI) -> None: |
| 654 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `call_id` but received ''"): |
| 655 | await async_client.realtime.calls.with_raw_response.refer( |
| 656 | call_id="", |
| 657 | target_uri="tel:+14155550123", |
| 658 | ) |
| 659 | |
| 660 | @parametrize |
| 661 | async def test_method_reject(self, async_client: AsyncOpenAI) -> None: |
| 662 | call = await async_client.realtime.calls.reject( |
| 663 | call_id="call_id", |
| 664 | ) |
| 665 | assert call is None |
| 666 | |
| 667 | @parametrize |
| 668 | async def test_method_reject_with_all_params(self, async_client: AsyncOpenAI) -> None: |
| 669 | call = await async_client.realtime.calls.reject( |
| 670 | call_id="call_id", |
| 671 | status_code=486, |
| 672 | ) |
| 673 | assert call is None |
| 674 | |
| 675 | @parametrize |
| 676 | async def test_raw_response_reject(self, async_client: AsyncOpenAI) -> None: |
| 677 | response = await async_client.realtime.calls.with_raw_response.reject( |
| 678 | call_id="call_id", |
| 679 | ) |
| 680 | |
| 681 | assert response.is_closed is True |
| 682 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 683 | call = response.parse() |
| 684 | assert call is None |
| 685 | |
| 686 | @parametrize |
| 687 | async def test_streaming_response_reject(self, async_client: AsyncOpenAI) -> None: |
| 688 | async with async_client.realtime.calls.with_streaming_response.reject( |
| 689 | call_id="call_id", |
| 690 | ) as response: |
| 691 | assert not response.is_closed |
| 692 | assert response.http_request.headers.get("X-Stainless-Lang") == "python" |
| 693 | |
| 694 | call = await response.parse() |
| 695 | assert call is None |
| 696 | |
| 697 | assert cast(Any, response.is_closed) is True |
| 698 | |
| 699 | @parametrize |
| 700 | async def test_path_params_reject(self, async_client: AsyncOpenAI) -> None: |
| 701 | with pytest.raises(ValueError, match=r"Expected a non-empty value for `call_id` but received ''"): |
| 702 | await async_client.realtime.calls.with_raw_response.reject( |
| 703 | call_id="", |
| 704 | ) |
| 705 | |