Skip to content

Conversation

@tisnik
Copy link
Contributor

@tisnik tisnik commented Sep 7, 2025

Description

LCORE-641: split unit tests for HTTP responses models

Type of change

  • Refactor
  • New feature
  • Bug fix
  • CVE fix
  • Optimization
  • Documentation Update
  • Configuration Update
  • Bump-up service version
  • Bump-up dependent library
  • Bump-up library or tool used for development (does not change the final image)
  • CI configuration change
  • Konflux configuration change
  • Unit tests improvement
  • Integration tests improvement
  • End to end tests improvement

Related Tickets & Documents

  • Related Issue #LCORE-641

Summary by CodeRabbit

  • Tests

    • Expanded and reorganized unit tests for response handling, including authorization, query, status, and error scenarios.
    • Enhanced validation coverage and modular test structure for clearer intent and easier maintenance.
  • Chores

    • Removed legacy consolidated tests to eliminate duplication and streamline the suite.
  • Notes

    • No user-facing changes; app behavior remains unchanged.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 7, 2025

Walkthrough

Adds four new unit test modules under tests/unit/models/responses for individual response models and removes the prior consolidated test file tests/unit/models/test_responses.py. Tests cover constructors and validation behavior for AuthorizedResponse, QueryResponse, StatusResponse, and UnauthorizedResponse.

Changes

Cohort / File(s) Summary
Added granular response model tests
tests/unit/models/responses/test_authorized_response.py, tests/unit/models/responses/test_query_response.py, tests/unit/models/responses/test_status_response.py, tests/unit/models/responses/test_unauthorized_response.py
New unit tests per model verifying construction and validation (required/optional fields) for AuthorizedResponse, QueryResponse, StatusResponse, and UnauthorizedResponse.
Removed legacy consolidated tests
tests/unit/models/test_responses.py
Deleted combined test suite that previously covered the same four response models.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Poem

Thump-thump, I hop through tests anew,
Four tidy burrows, neat and true.
Old warren sealed, paths split with care,
Each response model gets its share.
Nose twitch—asserts all pass the check,
Carrot emoji: 🥕—ship it, spec by spec!

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (5)
tests/unit/models/responses/test_unauthorized_response.py (1)

20-23: Strengthen the ValidationError assertion and prefer tool-agnostic ignore.

Capture the exception and assert the missing field to avoid false positives; also use a cross-checker-friendly ignore comment.

-    def test_constructor_fields_required(self) -> None:
-        """Test the UnauthorizedResponse constructor."""
-        with pytest.raises(ValidationError):
-            _ = UnauthorizedResponse()  # pyright: ignore
+    def test_constructor_fields_required(self) -> None:
+        """Test the UnauthorizedResponse constructor."""
+        with pytest.raises(ValidationError) as excinfo:
+            _ = UnauthorizedResponse()  # type: ignore[call-arg]
+        errors = excinfo.value.errors()
+        assert any("detail" in e.get("loc", []) for e in errors)
tests/unit/models/responses/test_authorized_response.py (2)

22-33: DRY up missing-field tests with parametrization and assert the exact missing field.

Reduces duplication and tightens validation.

-    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
+    @pytest.mark.parametrize(
+        ("kwargs", "missing"),
+        [
+            ({"username": "testuser"}, "user_id"),
+            ({"user_id": "123e4567-e89b-12d3-a456-426614174000"}, "username"),
+        ],
+    )
+    def test_constructor_fields_required(self, kwargs, missing) -> None:
+        """Test the AuthorizedResponse constructor."""
+        with pytest.raises(ValidationError) as excinfo:
+            _ = AuthorizedResponse(**kwargs)  # type: ignore[call-arg]
+        assert any(missing in e.get("loc", []) for e in excinfo.value.errors())

15-21: Optional: validate UUID format explicitly.

If user_id is typed as UUID, add a negative test (e.g., user_id="not-a-uuid") to assert a ValidationError with loc containing "user_id".

tests/unit/models/responses/test_query_response.py (1)

18-22: Add a negative test for required ‘response’.

Ensures we fail fast when the core payload is missing.

+import pytest
+from pydantic import ValidationError
@@
 class TestQueryResponse:
@@
     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"
+
+    def test_constructor_requires_response(self) -> None:
+        """Ensure `response` is required."""
+        with pytest.raises(ValidationError):
+            _ = QueryResponse()  # type: ignore[call-arg]
tests/unit/models/responses/test_status_response.py (1)

9-19: Parametrize enabled/disabled to reduce duplication.

Functionally equivalent but more concise and scalable for future cases.

-    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}
+    @pytest.mark.parametrize("enabled", [True, False])
+    def test_constructor_feedback_enabled_flag(self, enabled: bool) -> None:
+        """Test the StatusResponse constructor."""
+        sr = StatusResponse(functionality="feedback", status={"enabled": enabled})
+        assert sr.functionality == "feedback"
+        assert sr.status == {"enabled": enabled}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 59a7cde and af7baa6.

📒 Files selected for processing (5)
  • tests/unit/models/responses/test_authorized_response.py (1 hunks)
  • tests/unit/models/responses/test_query_response.py (1 hunks)
  • tests/unit/models/responses/test_status_response.py (1 hunks)
  • tests/unit/models/responses/test_unauthorized_response.py (1 hunks)
  • tests/unit/models/test_responses.py (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/unit/models/test_responses.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build-pr
🔇 Additional comments (3)
tests/unit/models/responses/test_unauthorized_response.py (1)

13-19: LGTM: constructor happy-path is clear and readable.

tests/unit/models/responses/test_authorized_response.py (1)

13-21: LGTM: positive-path assertions look good.

tests/unit/models/responses/test_query_response.py (1)

9-17: LGTM: covers primary fields and values.

@tisnik tisnik merged commit 409cf01 into lightspeed-core:main Sep 7, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant