From 63783383e7ea518dfee1eca916d6bca21278e095 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 13 Mar 2025 15:25:50 -0700 Subject: [PATCH] add basic validation tests for e2e responses create endpoint --- .../test_openai_responses_api.py | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/openai_endpoints_tests/test_openai_responses_api.py b/tests/openai_endpoints_tests/test_openai_responses_api.py index 473d49bd7cc..f853d53532a 100644 --- a/tests/openai_endpoints_tests/test_openai_responses_api.py +++ b/tests/openai_endpoints_tests/test_openai_responses_api.py @@ -29,8 +29,21 @@ def validate_response(response): Validate basic response structure from OpenAI responses API """ assert response is not None - assert isinstance(response.choices[0].message.content, str) + assert hasattr(response, "choices") assert len(response.choices) > 0 + assert hasattr(response.choices[0], "message") + assert hasattr(response.choices[0].message, "content") + assert isinstance(response.choices[0].message.content, str) + assert hasattr(response, "id") + assert isinstance(response.id, str) + assert hasattr(response, "model") + assert isinstance(response.model, str) + assert hasattr(response, "created") + assert isinstance(response.created, int) + assert hasattr(response, "usage") + assert hasattr(response.usage, "prompt_tokens") + assert hasattr(response.usage, "completion_tokens") + assert hasattr(response.usage, "total_tokens") def validate_stream_chunk(chunk): @@ -38,7 +51,23 @@ def validate_stream_chunk(chunk): Validate streaming chunk structure from OpenAI responses API """ assert chunk is not None - assert isinstance(chunk.choices[0].delta.content, str) + assert hasattr(chunk, "choices") + assert len(chunk.choices) > 0 + assert hasattr(chunk.choices[0], "delta") + + # Some chunks might not have content in the delta + if ( + hasattr(chunk.choices[0].delta, "content") + and chunk.choices[0].delta.content is not None + ): + assert isinstance(chunk.choices[0].delta.content, str) + + assert hasattr(chunk, "id") + assert isinstance(chunk.id, str) + assert hasattr(chunk, "model") + assert isinstance(chunk.model, str) + assert hasattr(chunk, "created") + assert isinstance(chunk.created, int) def test_basic_response():