From c77c06c1e9ba15eb0e6f1399e386dcc8d2998edb Mon Sep 17 00:00:00 2001 From: Asuka Minato Date: Wed, 15 Jul 2026 12:37:16 +0900 Subject: [PATCH] test: move hit testing service coverage to unit tests (#38925) --- .../services/test_hit_testing_service.py | 25 --------------- .../services/test_hit_testing_service.py | 32 +++++++++++++++++++ 2 files changed, 32 insertions(+), 25 deletions(-) create mode 100644 api/tests/unit_tests/services/test_hit_testing_service.py diff --git a/api/tests/test_containers_integration_tests/services/test_hit_testing_service.py b/api/tests/test_containers_integration_tests/services/test_hit_testing_service.py index 67b3a2d3e57..4106b68545c 100644 --- a/api/tests/test_containers_integration_tests/services/test_hit_testing_service.py +++ b/api/tests/test_containers_integration_tests/services/test_hit_testing_service.py @@ -153,31 +153,6 @@ def _create_segment(db_session: Session, *, document: DatasetDocument | None = N class TestHitTestingService: - # ── Utility methods (pure logic, no DB) ──────────────────────────── - - def test_escape_query_for_search_should_escape_double_quotes(self) -> None: - query = 'test "query" with quotes' - result = HitTestingService.escape_query_for_search(query) - assert result == 'test \\"query\\" with quotes' - - def test_hit_testing_args_check_should_pass_with_valid_query(self) -> None: - HitTestingService.hit_testing_args_check({"query": "valid query"}) - - def test_hit_testing_args_check_should_pass_with_valid_attachments(self) -> None: - HitTestingService.hit_testing_args_check({"attachment_ids": ["id1", "id2"]}) - - def test_hit_testing_args_check_should_raise_error_when_no_query_or_attachments(self) -> None: - with pytest.raises(ValueError, match="Query or attachment_ids is required"): - HitTestingService.hit_testing_args_check({}) - - def test_hit_testing_args_check_should_raise_error_when_query_too_long(self) -> None: - with pytest.raises(ValueError, match="Query cannot exceed 250 characters"): - HitTestingService.hit_testing_args_check({"query": "a" * 251}) - - def test_hit_testing_args_check_should_raise_error_when_attachments_not_list(self) -> None: - with pytest.raises(ValueError, match="Attachment_ids must be a list"): - HitTestingService.hit_testing_args_check({"attachment_ids": "not a list"}) - # ── Response formatting ──────────────────────────────────────────── @patch("core.rag.datasource.retrieval_service.RetrievalService.format_retrieval_documents") diff --git a/api/tests/unit_tests/services/test_hit_testing_service.py b/api/tests/unit_tests/services/test_hit_testing_service.py new file mode 100644 index 00000000000..c251ac5147d --- /dev/null +++ b/api/tests/unit_tests/services/test_hit_testing_service.py @@ -0,0 +1,32 @@ +"""Unit tests for the database-independent hit-testing helpers.""" + +import pytest + +from services.hit_testing_service import HitTestingService + + +class TestHitTestingServiceArguments: + def test_escape_query_for_search_should_escape_double_quotes(self) -> None: + query = 'test "query" with quotes' + + result = HitTestingService.escape_query_for_search(query) + + assert result == 'test \\"query\\" with quotes' + + def test_hit_testing_args_check_should_pass_with_valid_query(self) -> None: + HitTestingService.hit_testing_args_check({"query": "valid query"}) + + def test_hit_testing_args_check_should_pass_with_valid_attachments(self) -> None: + HitTestingService.hit_testing_args_check({"attachment_ids": ["id1", "id2"]}) + + def test_hit_testing_args_check_should_raise_error_when_no_query_or_attachments(self) -> None: + with pytest.raises(ValueError, match="Query or attachment_ids is required"): + HitTestingService.hit_testing_args_check({}) + + def test_hit_testing_args_check_should_raise_error_when_query_too_long(self) -> None: + with pytest.raises(ValueError, match="Query cannot exceed 250 characters"): + HitTestingService.hit_testing_args_check({"query": "a" * 251}) + + def test_hit_testing_args_check_should_raise_error_when_attachments_not_list(self) -> None: + with pytest.raises(ValueError, match="Attachment_ids must be a list"): + HitTestingService.hit_testing_args_check({"attachment_ids": "not a list"})