From af7baa6d73518a984a2e6cab3e5a2feba2c92415 Mon Sep 17 00:00:00 2001 From: Pavel Tisnovsky Date: Sun, 7 Sep 2025 15:59:10 +0200 Subject: [PATCH] LCORE-641: split unit tests for HTTP responses models --- .../responses/test_authorized_response.py | 33 +++++++ .../models/responses/test_query_response.py | 22 +++++ .../models/responses/test_status_response.py | 19 ++++ .../responses/test_unauthorized_response.py | 23 +++++ tests/unit/models/test_responses.py | 86 ------------------- 5 files changed, 97 insertions(+), 86 deletions(-) create mode 100644 tests/unit/models/responses/test_authorized_response.py create mode 100644 tests/unit/models/responses/test_query_response.py create mode 100644 tests/unit/models/responses/test_status_response.py create mode 100644 tests/unit/models/responses/test_unauthorized_response.py delete mode 100644 tests/unit/models/test_responses.py diff --git a/tests/unit/models/responses/test_authorized_response.py b/tests/unit/models/responses/test_authorized_response.py new file mode 100644 index 00000000..08721317 --- /dev/null +++ b/tests/unit/models/responses/test_authorized_response.py @@ -0,0 +1,33 @@ +"""Unit tests for AuthorizedResponse model.""" + +import pytest + +from pydantic import ValidationError + +from models.responses import AuthorizedResponse + + +class TestAuthorizedResponse: + """Test cases for the AuthorizedResponse model.""" + + def test_constructor(self) -> None: + """Test the AuthorizedResponse constructor.""" + ar = AuthorizedResponse( + user_id="123e4567-e89b-12d3-a456-426614174000", + username="testuser", + ) + assert ar.user_id == "123e4567-e89b-12d3-a456-426614174000" + assert ar.username == "testuser" + + def test_constructor_fields_required(self) -> None: + """Test the AuthorizedResponse constructor.""" + + with pytest.raises(ValidationError): + # missing user_id parameter + _ = AuthorizedResponse(username="testuser") # pyright: ignore + + with pytest.raises(ValidationError): + # missing username parameter + _ = AuthorizedResponse( + user_id="123e4567-e89b-12d3-a456-426614174000" + ) # pyright: ignore diff --git a/tests/unit/models/responses/test_query_response.py b/tests/unit/models/responses/test_query_response.py new file mode 100644 index 00000000..76b3136d --- /dev/null +++ b/tests/unit/models/responses/test_query_response.py @@ -0,0 +1,22 @@ +"""Unit tests for QueryResponse model.""" + +from models.responses import QueryResponse + + +class TestQueryResponse: + """Test cases for the QueryResponse model.""" + + def test_constructor(self) -> None: + """Test the QueryResponse constructor.""" + qr = QueryResponse( + conversation_id="123e4567-e89b-12d3-a456-426614174000", + response="LLM answer", + ) + assert qr.conversation_id == "123e4567-e89b-12d3-a456-426614174000" + assert qr.response == "LLM answer" + + def test_optional_conversation_id(self) -> None: + """Test the QueryResponse with default conversation ID.""" + qr = QueryResponse(response="LLM answer") + assert qr.conversation_id is None + assert qr.response == "LLM answer" diff --git a/tests/unit/models/responses/test_status_response.py b/tests/unit/models/responses/test_status_response.py new file mode 100644 index 00000000..3974ba97 --- /dev/null +++ b/tests/unit/models/responses/test_status_response.py @@ -0,0 +1,19 @@ +"""Unit tests for StatusResponse model.""" + +from models.responses import StatusResponse + + +class TestStatusResponse: + """Test cases for the StatusResponse model.""" + + def test_constructor_feedback_enabled(self) -> None: + """Test the StatusResponse constructor.""" + sr = StatusResponse(functionality="feedback", status={"enabled": True}) + assert sr.functionality == "feedback" + assert sr.status == {"enabled": True} + + def test_constructor_feedback_disabled(self) -> None: + """Test the StatusResponse constructor.""" + sr = StatusResponse(functionality="feedback", status={"enabled": False}) + assert sr.functionality == "feedback" + assert sr.status == {"enabled": False} diff --git a/tests/unit/models/responses/test_unauthorized_response.py b/tests/unit/models/responses/test_unauthorized_response.py new file mode 100644 index 00000000..242d68bf --- /dev/null +++ b/tests/unit/models/responses/test_unauthorized_response.py @@ -0,0 +1,23 @@ +"""Unit tests for UnauthorizedResponse model.""" + +import pytest + +from pydantic import ValidationError + +from models.responses import UnauthorizedResponse + + +class TestUnauthorizedResponse: + """Test cases for the UnauthorizedResponse model.""" + + def test_constructor(self) -> None: + """Test the UnauthorizedResponse constructor.""" + ur = UnauthorizedResponse( + detail="Missing or invalid credentials provided by client" + ) + assert ur.detail == "Missing or invalid credentials provided by client" + + def test_constructor_fields_required(self) -> None: + """Test the UnauthorizedResponse constructor.""" + with pytest.raises(ValidationError): + _ = UnauthorizedResponse() # pyright: ignore diff --git a/tests/unit/models/test_responses.py b/tests/unit/models/test_responses.py deleted file mode 100644 index 45c5af32..00000000 --- a/tests/unit/models/test_responses.py +++ /dev/null @@ -1,86 +0,0 @@ -"""Tests for QueryResponse. StatusResponse, AuthorizedResponse, and UnauthorizedResponse models.""" - -import pytest - -from pydantic import ValidationError - -from models.responses import ( - QueryResponse, - StatusResponse, - AuthorizedResponse, - UnauthorizedResponse, -) - - -class TestQueryResponse: - """Test cases for the QueryResponse model.""" - - def test_constructor(self) -> None: - """Test the QueryResponse constructor.""" - qr = QueryResponse( - conversation_id="123e4567-e89b-12d3-a456-426614174000", - response="LLM answer", - ) - assert qr.conversation_id == "123e4567-e89b-12d3-a456-426614174000" - assert qr.response == "LLM answer" - - def test_optional_conversation_id(self) -> None: - """Test the QueryResponse with default conversation ID.""" - qr = QueryResponse(response="LLM answer") - assert qr.conversation_id is None - assert qr.response == "LLM answer" - - -class TestStatusResponse: - """Test cases for the StatusResponse model.""" - - def test_constructor_feedback_enabled(self) -> None: - """Test the StatusResponse constructor.""" - sr = StatusResponse(functionality="feedback", status={"enabled": True}) - assert sr.functionality == "feedback" - assert sr.status == {"enabled": True} - - def test_constructor_feedback_disabled(self) -> None: - """Test the StatusResponse constructor.""" - sr = StatusResponse(functionality="feedback", status={"enabled": False}) - assert sr.functionality == "feedback" - assert sr.status == {"enabled": False} - - -class TestAuthorizedResponse: - """Test cases for the AuthorizedResponse model.""" - - def test_constructor(self) -> None: - """Test the AuthorizedResponse constructor.""" - ar = AuthorizedResponse( - user_id="123e4567-e89b-12d3-a456-426614174000", - username="testuser", - ) - assert ar.user_id == "123e4567-e89b-12d3-a456-426614174000" - assert ar.username == "testuser" - - def test_constructor_fields_required(self) -> None: - """Test the AuthorizedResponse constructor.""" - with pytest.raises(ValidationError): - AuthorizedResponse(username="testuser") # pyright: ignore - - with pytest.raises(ValidationError): - AuthorizedResponse( - user_id="123e4567-e89b-12d3-a456-426614174000" - ) # pyright: ignore - - -class TestUnauthorizedResponse: - """Test cases for the UnauthorizedResponse model.""" - - def test_constructor(self) -> None: - """Test the UnauthorizedResponse constructor.""" - ur = UnauthorizedResponse( - detail="Missing or invalid credentials provided by client" - ) - assert ur.detail == "Missing or invalid credentials provided by client" - - def test_constructor_fields_required(self) -> None: - """Test the UnauthorizedResponse constructor.""" - with pytest.raises(Exception): - UnauthorizedResponse() # pyright: ignore