Skip to content

~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.

test: strengthen overmocked rating_storage.create test to verify field mapping (#4246)

LearningCircuit57bc3c3b7d64
diff --git a/tests/news/rating_system/test_storage.py b/tests/news/rating_system/test_storage.py
index 12fe8b0c8f..9ce13ecbe6 100644
--- a/tests/news/rating_system/test_storage.py
+++ b/tests/news/rating_system/test_storage.py
@@ -59,7 +59,10 @@ class TestCreate:
@patch("local_deep_research.news.rating_system.storage.UserRating")
def test_create_rating_success(self, mock_model_class):
- """Test successful rating creation."""
+ """create() must map rating_value to UserRating.relevance_vote
+ (the SUT docstring documents this remap) and pass through
+ user_id, item_id, item_type unchanged. The returned id is the
+ str() of the persisted row's id."""
from local_deep_research.news.rating_system.storage import (
SQLRatingStorage,
)
@@ -84,9 +87,21 @@ class TestCreate:
result = storage.create(data)
assert result == "123"
- mock_session.add.assert_called_once()
+ mock_session.add.assert_called_once_with(mock_rating)
mock_session.commit.assert_called_once()
+ # Verify the SUT mapped fields correctly into the UserRating ctor.
+ kwargs = mock_model_class.call_args.kwargs
+ assert kwargs["user_id"] == "user123"
+ assert kwargs["item_id"] == "item456"
+ assert kwargs["item_type"] == "card"
+ assert kwargs["relevance_vote"] == "up", (
+ "rating_value must be remapped to relevance_vote per SUT contract"
+ )
+ # SUT always passes quality_rating=data.get(...) — verify the key
+ # is present and explicitly None when not supplied.
+ assert kwargs["quality_rating"] is None
+
@patch("local_deep_research.news.rating_system.storage.UserRating")
def test_create_rating_with_default_item_type(self, mock_model_class):
"""Test rating creation uses default item_type."""