Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/traceloop-sdk/tests/test_user_feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ def test_user_feedback_initialization(mock_http):

def test_create_basic_feedback(user_feedback: UserFeedback, mock_http: Mock):
"""Test creating basic user feedback"""
user_feedback.create(
result = user_feedback.create(
annotation_task="task_123", entity_id="instance_456", tags={"sentiment": "positive"}
)

assert result == {"status": "success"}
mock_http.post.assert_called_once_with(
"annotation-tasks/task_123/annotations",
{
Expand All @@ -60,8 +61,9 @@ def test_create_feedback_complex_tags(user_feedback: UserFeedback, mock_http: Mo
"""Test creating user feedback with complex tags"""
tags = {"sentiment": "positive", "relevance": 0.95, "tones": ["happy", "nice"]}

user_feedback.create(annotation_task="task_123", entity_id="instance_456", tags=tags)
result = user_feedback.create(annotation_task="task_123", entity_id="instance_456", tags=tags)

assert result == {"status": "success"}
mock_http.post.assert_called_once_with(
"annotation-tasks/task_123/annotations",
{
Expand All @@ -87,3 +89,14 @@ def test_create_feedback_parameter_validation(user_feedback: UserFeedback):

with pytest.raises(ValueError, match="tags cannot be empty"):
user_feedback.create(annotation_task="task_123", entity_id="instance_456", tags={})


def test_create_feedback_returns_none_when_write_fails(user_feedback: UserFeedback, mock_http: Mock):
"""Test feedback submission returns the HTTP client's failure signal."""
mock_http.post.return_value = None

result = user_feedback.create(
annotation_task="task_123", entity_id="instance_456", tags={"sentiment": "positive"}
)

assert result is None
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Any
from typing import Any, Dict

from ..client.http import HTTPClient

Expand All @@ -23,7 +23,7 @@ def create(
annotation_task: str,
entity_id: str,
tags: Dict[str, Any],
) -> None:
) -> Any:
"""Create an user feedback annotation for a specific task.

Args:
Expand All @@ -34,6 +34,10 @@ def create(
tags (Dict[str, Any]): Dictionary containing the tags to be reported.
Should match the tags defined in the annotation task

Returns:
The API response returned by the annotation write request, or None
when the underlying HTTP client could not complete the write.

Example:
```python
client = Client(api_key="your-key")
Expand All @@ -56,7 +60,7 @@ def create(
if not tags:
raise ValueError("tags cannot be empty")

self._http.post(
return self._http.post(
f"annotation-tasks/{annotation_task}/annotations",
{
"entity_instance_id": entity_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create(
annotation_task: str,
entity_id: str,
tags: Dict[str, Any],
) -> None:
) -> Any:
"""Create an annotation for a specific task.

Args:
Expand All @@ -24,6 +24,10 @@ def create(
tags (Dict[str, Any]): Dictionary containing the tags to be reported.
Should match the tags defined in the annotation task

Returns:
The API response returned by the annotation write request, or None
when the underlying HTTP client could not complete the write.

Example:
```python
client = Client(api_key="your-key")
Expand Down