chore: import upstream snapshot with attribution
TypeScript SDK Compatibility V1.x E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / TypeScript SDK Compatibility V1.x E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
TypeScript SDK E2E Tests / TypeScript SDK E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
Python SDK E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK E2E Tests / Python SDK E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK E2E Tests / build-opik (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Python SDK Compatibility V1.x E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK E2E Tests / build-opik (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer E2E Tests Python ${{matrix.python_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer Integration Smoke Tests (push) Has been cancelled
🐙 Code Quality / detect (push) Has been cancelled
🐙 Code Quality / lint (${{ matrix.leg.name }}) (push) Has been cancelled
🐙 Code Quality / summary (push) Has been cancelled
TypeScript SDK Library Integration Tests / Check Secrets (push) Has been cancelled
TypeScript SDK Library Integration Tests / opik-vercel (Vercel AI SDK / eve) (push) Has been cancelled
SDK Library Integration Tests Runner / Check Secrets (push) Has been cancelled
SDK Library Integration Tests Runner / Missed OpenAI API Key Warning (push) Has been cancelled
SDK Library Integration Tests Runner / Build (push) Has been cancelled
SDK Library Integration Tests Runner / openai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_legacy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / llama_index_tests (push) Has been cancelled
SDK Library Integration Tests Runner / anthropic_tests (push) Has been cancelled
SDK Library Integration Tests Runner / mistral_tests (push) Has been cancelled
SDK Library Integration Tests Runner / groq_tests (push) Has been cancelled
SDK Library Integration Tests Runner / aisuite_tests (push) Has been cancelled
SDK Library Integration Tests Runner / haystack_tests (push) Has been cancelled
SDK Library Integration Tests Runner / dspy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v1_tests (push) Has been cancelled
SDK Library Integration Tests Runner / genai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_legacy_1_3_0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / evaluation_metrics_tests (push) Has been cancelled
SDK Library Integration Tests Runner / bedrock_tests (push) Has been cancelled
SDK Library Integration Tests Runner / litellm_tests (push) Has been cancelled
SDK Library Integration Tests Runner / harbor_tests (push) Has been cancelled
SDK Library Integration Tests Runner / Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / render-equality (push) Has been cancelled
Opik Optimizer - Unit Tests / Opik Optimizer Unit Tests Python ${{matrix.python_version}} (push) Has been cancelled
Python BE E2E Tests / Python BE E2E (push) Has been cancelled
Python Backend Tests / run-python-backend-tests (push) Has been cancelled
Python SDK Unit Tests / Python SDK Unit Tests ${{matrix.python_version}} (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
SDK E2E Libraries Integration Tests / Check Secrets (push) Has been cancelled
SDK E2E Libraries Integration Tests / Missed OpenAI API Key Warning (push) Has been cancelled
SDK E2E Libraries Integration Tests / build-opik (push) Has been cancelled
SDK E2E Libraries Integration Tests / E2E Lib Integration Python ${{matrix.python_version}} (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-gemini) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-langchain) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-openai) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-otel) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-vercel) (push) Has been cancelled
TypeScript SDK Build & Publish / build-and-publish (push) Has been cancelled
TypeScript SDK Unit Tests / Test on Node ${{ matrix.node-version }} (push) Has been cancelled
Backend Tests / discover-tests (push) Has been cancelled
Backend Tests / ${{ matrix.name }} (push) Has been cancelled
Build and Publish SDK / build-and-publish (push) Has been cancelled
Build Opik Docker Images / set-version (push) Has been cancelled
Build Opik Docker Images / build-backend (push) Has been cancelled
Build Opik Docker Images / build-sandbox-executor-python (push) Has been cancelled
Build Opik Docker Images / build-python-backend (push) Has been cancelled
Build Opik Docker Images / build-frontend (push) Has been cancelled
Build Opik Docker Images / create-git-tag (push) Has been cancelled
ClickHouse Migration Cluster Check / validate-clickhouse-migrations (push) Has been cancelled
Docs - Publish / run (push) Has been cancelled
E2E Tests - Post Merge (v2) / 🧪 E2E v2 Tests (${{ github.event.inputs.tier || 't1' }}) (push) Has been cancelled
E2E Tests - Post Merge (v2) / 📢 Slack Notification (push) Has been cancelled
Frontend Unit Tests / Test on Node 20 (push) Has been cancelled
Guardrails E2E Tests / Select Python version matrix (push) Has been cancelled
Guardrails E2E Tests / Guardrails E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Guardrails E2E Tests / 📢 Slack Notification (push) Has been cancelled
Guardrails Backend Unit Tests / Guardrails Backend Unit Tests (push) Has been cancelled
Guardrails Backend Unit Tests / 📢 Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v3.21.0) (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v4.2.0) (push) Has been cancelled
Lint Opik Helm Chart / unittest-helm-chart (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / TypeScript SDK Compatibility V1.x E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
TypeScript SDK E2E Tests / TypeScript SDK E2E Tests Node ${{matrix.node_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
Python SDK E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK E2E Tests / Python SDK E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK E2E Tests / build-opik (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Select Python version matrix (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / Python SDK Compatibility V1.x E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Python SDK Compatibility V1.x E2E Tests / build-opik (push) Has been cancelled
TypeScript SDK E2E Tests / Select Node version matrix (push) Has been cancelled
TypeScript SDK E2E Tests / build-opik (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer E2E Tests Python ${{matrix.python_version}} (push) Has been cancelled
Opik Optimizer - E2E Tests / Opik Optimizer Integration Smoke Tests (push) Has been cancelled
🐙 Code Quality / detect (push) Has been cancelled
🐙 Code Quality / lint (${{ matrix.leg.name }}) (push) Has been cancelled
🐙 Code Quality / summary (push) Has been cancelled
TypeScript SDK Library Integration Tests / Check Secrets (push) Has been cancelled
TypeScript SDK Library Integration Tests / opik-vercel (Vercel AI SDK / eve) (push) Has been cancelled
SDK Library Integration Tests Runner / Check Secrets (push) Has been cancelled
SDK Library Integration Tests Runner / Missed OpenAI API Key Warning (push) Has been cancelled
SDK Library Integration Tests Runner / Build (push) Has been cancelled
SDK Library Integration Tests Runner / openai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_tests (push) Has been cancelled
SDK Library Integration Tests Runner / langchain_legacy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / llama_index_tests (push) Has been cancelled
SDK Library Integration Tests Runner / anthropic_tests (push) Has been cancelled
SDK Library Integration Tests Runner / mistral_tests (push) Has been cancelled
SDK Library Integration Tests Runner / groq_tests (push) Has been cancelled
SDK Library Integration Tests Runner / aisuite_tests (push) Has been cancelled
SDK Library Integration Tests Runner / haystack_tests (push) Has been cancelled
SDK Library Integration Tests Runner / dspy_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / crewai_v1_tests (push) Has been cancelled
SDK Library Integration Tests Runner / genai_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_tests (push) Has been cancelled
SDK Library Integration Tests Runner / adk_legacy_1_3_0_tests (push) Has been cancelled
SDK Library Integration Tests Runner / evaluation_metrics_tests (push) Has been cancelled
SDK Library Integration Tests Runner / bedrock_tests (push) Has been cancelled
SDK Library Integration Tests Runner / litellm_tests (push) Has been cancelled
SDK Library Integration Tests Runner / harbor_tests (push) Has been cancelled
SDK Library Integration Tests Runner / Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / render-equality (push) Has been cancelled
Opik Optimizer - Unit Tests / Opik Optimizer Unit Tests Python ${{matrix.python_version}} (push) Has been cancelled
Python BE E2E Tests / Python BE E2E (push) Has been cancelled
Python Backend Tests / run-python-backend-tests (push) Has been cancelled
Python SDK Unit Tests / Python SDK Unit Tests ${{matrix.python_version}} (push) Has been cancelled
Release Drafter / update_release_draft (push) Has been cancelled
SDK E2E Libraries Integration Tests / Check Secrets (push) Has been cancelled
SDK E2E Libraries Integration Tests / Missed OpenAI API Key Warning (push) Has been cancelled
SDK E2E Libraries Integration Tests / build-opik (push) Has been cancelled
SDK E2E Libraries Integration Tests / E2E Lib Integration Python ${{matrix.python_version}} (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-gemini) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-langchain) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-openai) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-otel) (push) Has been cancelled
TypeScript SDK Integration Build & Publish / build-and-publish (opik-vercel) (push) Has been cancelled
TypeScript SDK Build & Publish / build-and-publish (push) Has been cancelled
TypeScript SDK Unit Tests / Test on Node ${{ matrix.node-version }} (push) Has been cancelled
Backend Tests / discover-tests (push) Has been cancelled
Backend Tests / ${{ matrix.name }} (push) Has been cancelled
Build and Publish SDK / build-and-publish (push) Has been cancelled
Build Opik Docker Images / set-version (push) Has been cancelled
Build Opik Docker Images / build-backend (push) Has been cancelled
Build Opik Docker Images / build-sandbox-executor-python (push) Has been cancelled
Build Opik Docker Images / build-python-backend (push) Has been cancelled
Build Opik Docker Images / build-frontend (push) Has been cancelled
Build Opik Docker Images / create-git-tag (push) Has been cancelled
ClickHouse Migration Cluster Check / validate-clickhouse-migrations (push) Has been cancelled
Docs - Publish / run (push) Has been cancelled
E2E Tests - Post Merge (v2) / 🧪 E2E v2 Tests (${{ github.event.inputs.tier || 't1' }}) (push) Has been cancelled
E2E Tests - Post Merge (v2) / 📢 Slack Notification (push) Has been cancelled
Frontend Unit Tests / Test on Node 20 (push) Has been cancelled
Guardrails E2E Tests / Select Python version matrix (push) Has been cancelled
Guardrails E2E Tests / Guardrails E2E Tests ${{matrix.python_version}} (push) Has been cancelled
Guardrails E2E Tests / 📢 Slack Notification (push) Has been cancelled
Guardrails Backend Unit Tests / Guardrails Backend Unit Tests (push) Has been cancelled
Guardrails Backend Unit Tests / 📢 Slack Notification (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v3.21.0) (push) Has been cancelled
Lint Opik Helm Chart / lint-helm-chart (Helm v4.2.0) (push) Has been cancelled
Lint Opik Helm Chart / unittest-helm-chart (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,391 @@
|
||||
import json
|
||||
from unittest.mock import Mock
|
||||
import pytest
|
||||
|
||||
from opik.api_objects.annotation_queue.annotation_queue import (
|
||||
TracesAnnotationQueue,
|
||||
ThreadsAnnotationQueue,
|
||||
)
|
||||
from opik.rest_api.types import (
|
||||
trace_public,
|
||||
trace_thread,
|
||||
)
|
||||
from opik.exceptions import OpikException
|
||||
|
||||
|
||||
class TestTracesAnnotationQueueProperties:
|
||||
def test_id__returns_id(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
assert queue.id == "queue-123"
|
||||
|
||||
def test_name__returns_name(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
assert queue.name == "test_queue"
|
||||
|
||||
def test_scope__returns_trace(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
assert queue.scope == "trace"
|
||||
|
||||
def test_items_count__cached_value__returns_cached_count(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
items_count=10,
|
||||
)
|
||||
|
||||
assert queue.items_count == 10
|
||||
mock_rest_client.annotation_queues.get_annotation_queue_by_id.assert_not_called()
|
||||
|
||||
def test_items_count__no_cached_value__fetches_from_backend(self):
|
||||
mock_rest_client = Mock()
|
||||
mock_rest_client.annotation_queues.get_annotation_queue_by_id.return_value = (
|
||||
Mock(items_count=25)
|
||||
)
|
||||
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
items_count=None,
|
||||
)
|
||||
|
||||
assert queue.items_count == 25
|
||||
mock_rest_client.annotation_queues.get_annotation_queue_by_id.assert_called_once_with(
|
||||
"queue-123"
|
||||
)
|
||||
|
||||
|
||||
class TestThreadsAnnotationQueueProperties:
|
||||
def test_scope__returns_thread(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = ThreadsAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
assert queue.scope == "thread"
|
||||
|
||||
|
||||
class TestTracesAnnotationQueueUpdate:
|
||||
def test_update__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
description="old description",
|
||||
)
|
||||
|
||||
queue.update(
|
||||
name="new_name",
|
||||
description="new description",
|
||||
instructions="new instructions",
|
||||
)
|
||||
|
||||
mock_rest_client.annotation_queues.update_annotation_queue.assert_called_once_with(
|
||||
id="queue-123",
|
||||
name="new_name",
|
||||
description="new description",
|
||||
instructions="new instructions",
|
||||
comments_enabled=None,
|
||||
feedback_definition_names=None,
|
||||
)
|
||||
|
||||
assert queue.name == "new_name"
|
||||
assert queue.description == "new description"
|
||||
assert queue.instructions == "new instructions"
|
||||
|
||||
def test_update__partial_update__only_specified_fields_updated(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
description="old description",
|
||||
instructions="old instructions",
|
||||
)
|
||||
|
||||
queue.update(description="new description")
|
||||
|
||||
mock_rest_client.annotation_queues.update_annotation_queue.assert_called_once_with(
|
||||
id="queue-123",
|
||||
name=None,
|
||||
description="new description",
|
||||
instructions=None,
|
||||
comments_enabled=None,
|
||||
feedback_definition_names=None,
|
||||
)
|
||||
|
||||
assert queue.name == "test_queue"
|
||||
assert queue.description == "new description"
|
||||
assert queue.instructions == "old instructions"
|
||||
|
||||
|
||||
class TestTracesAnnotationQueueDelete:
|
||||
def test_delete__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
queue.delete()
|
||||
|
||||
mock_rest_client.annotation_queues.delete_annotation_queue_batch.assert_called_once_with(
|
||||
ids=["queue-123"]
|
||||
)
|
||||
|
||||
|
||||
class TestTracesAnnotationQueueAddTraces:
|
||||
def test_add_traces__single_trace_in_list__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
items_count=5,
|
||||
)
|
||||
|
||||
trace = Mock(spec=trace_public.TracePublic)
|
||||
trace.id = "trace-1"
|
||||
|
||||
queue.add_traces([trace])
|
||||
|
||||
mock_rest_client.annotation_queues.add_items_to_annotation_queue.assert_called_once_with(
|
||||
id="queue-123", ids=["trace-1"]
|
||||
)
|
||||
assert queue._items_count is None
|
||||
|
||||
def test_add_traces__multiple_traces__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
traces = [
|
||||
Mock(spec=trace_public.TracePublic, id="trace-1"),
|
||||
Mock(spec=trace_public.TracePublic, id="trace-2"),
|
||||
Mock(spec=trace_public.TracePublic, id="trace-3"),
|
||||
]
|
||||
|
||||
queue.add_traces(traces)
|
||||
|
||||
mock_rest_client.annotation_queues.add_items_to_annotation_queue.assert_called_once_with(
|
||||
id="queue-123", ids=["trace-1", "trace-2", "trace-3"]
|
||||
)
|
||||
|
||||
def test_add_traces__trace_without_id__raises_exception(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
trace = Mock(spec=trace_public.TracePublic)
|
||||
trace.id = None
|
||||
|
||||
with pytest.raises(OpikException) as exc_info:
|
||||
queue.add_traces([trace])
|
||||
|
||||
assert "no id" in str(exc_info.value)
|
||||
|
||||
def test_add_traces__empty_list__no_api_call(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
queue.add_traces([])
|
||||
|
||||
mock_rest_client.annotation_queues.add_items_to_annotation_queue.assert_not_called()
|
||||
|
||||
|
||||
class TestThreadsAnnotationQueueAddThreads:
|
||||
def test_add_threads__single_thread_in_list__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = ThreadsAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
items_count=5,
|
||||
)
|
||||
|
||||
thread = Mock(spec=trace_thread.TraceThread)
|
||||
thread.thread_model_id = "thread-model-1"
|
||||
|
||||
queue.add_threads([thread])
|
||||
|
||||
mock_rest_client.annotation_queues.add_items_to_annotation_queue.assert_called_once_with(
|
||||
id="queue-123", ids=["thread-model-1"]
|
||||
)
|
||||
assert queue._items_count is None
|
||||
|
||||
def test_add_threads__multiple_threads__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = ThreadsAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
thread1 = Mock(spec=trace_thread.TraceThread)
|
||||
thread1.thread_model_id = "thread-model-1"
|
||||
thread2 = Mock(spec=trace_thread.TraceThread)
|
||||
thread2.thread_model_id = "thread-model-2"
|
||||
threads = [thread1, thread2]
|
||||
|
||||
queue.add_threads(threads)
|
||||
|
||||
mock_rest_client.annotation_queues.add_items_to_annotation_queue.assert_called_once_with(
|
||||
id="queue-123", ids=["thread-model-1", "thread-model-2"]
|
||||
)
|
||||
|
||||
def test_add_threads__thread_without_thread_model_id__raises_exception(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = ThreadsAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
thread = Mock(spec=trace_thread.TraceThread)
|
||||
thread.thread_model_id = None
|
||||
|
||||
with pytest.raises(OpikException) as exc_info:
|
||||
queue.add_threads([thread])
|
||||
|
||||
assert "thread_model_id" in str(exc_info.value)
|
||||
|
||||
|
||||
class TestTracesAnnotationQueueRemoveTraces:
|
||||
def test_remove_traces__single_trace_in_list__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
items_count=5,
|
||||
)
|
||||
|
||||
trace = Mock(spec=trace_public.TracePublic)
|
||||
trace.id = "trace-1"
|
||||
|
||||
queue.remove_traces([trace])
|
||||
|
||||
mock_rest_client.annotation_queues.remove_items_from_annotation_queue.assert_called_once_with(
|
||||
id="queue-123", ids=["trace-1"]
|
||||
)
|
||||
assert queue._items_count is None
|
||||
|
||||
|
||||
class TestThreadsAnnotationQueueRemoveThreads:
|
||||
def test_remove_threads__single_thread_in_list__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
queue = ThreadsAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
items_count=5,
|
||||
)
|
||||
|
||||
thread = Mock(spec=trace_thread.TraceThread)
|
||||
thread.thread_model_id = "thread-model-1"
|
||||
|
||||
queue.remove_threads([thread])
|
||||
|
||||
mock_rest_client.annotation_queues.remove_items_from_annotation_queue.assert_called_once_with(
|
||||
id="queue-123", ids=["thread-model-1"]
|
||||
)
|
||||
assert queue._items_count is None
|
||||
|
||||
|
||||
class TestTracesAnnotationQueueGetItems:
|
||||
def test_get_items__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
mock_rest_client.traces.search_traces.return_value = [
|
||||
json.dumps({"id": "trace-1", "start_time": "2024-01-01T00:00:00Z"}).encode(
|
||||
"utf-8"
|
||||
)
|
||||
+ b"\n",
|
||||
json.dumps({"id": "trace-2", "start_time": "2024-01-01T00:00:00Z"}).encode(
|
||||
"utf-8"
|
||||
),
|
||||
]
|
||||
|
||||
queue = TracesAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
items = queue.get_items()
|
||||
|
||||
assert [item.id for item in items] == ["trace-1", "trace-2"]
|
||||
assert all(isinstance(item, trace_public.TracePublic) for item in items)
|
||||
|
||||
|
||||
class TestThreadsAnnotationQueueGetItems:
|
||||
def test_get_items__happyflow(self):
|
||||
mock_rest_client = Mock()
|
||||
mock_rest_client.traces.search_trace_threads.return_value = [
|
||||
json.dumps({"id": "thread-1"}).encode("utf-8") + b"\n",
|
||||
json.dumps({"id": "thread-2"}).encode("utf-8"),
|
||||
]
|
||||
|
||||
queue = ThreadsAnnotationQueue(
|
||||
id="queue-123",
|
||||
name="test_queue",
|
||||
project_id="project-123",
|
||||
rest_client=mock_rest_client,
|
||||
)
|
||||
|
||||
items = queue.get_items()
|
||||
|
||||
assert [item.id for item in items] == ["thread-1", "thread-2"]
|
||||
assert all(isinstance(item, trace_thread.TraceThread) for item in items)
|
||||
Reference in New Issue
Block a user