"""Tests for Pydantic models.
Task 1.2.1: 2-8 focused tests for core model functionality.
"""
from datetime import datetime
from uuid import UUID
from mcp_task_aggregator.models import (
ExternalTaskMetadata,
GitHubMetadata,
JiraMetadata,
LinearMetadata,
Tag,
Todo,
TodoSource,
TodoStatus,
)
class TestTodoStatus:
"""Tests for TodoStatus enum."""
def test_status_values(self):
"""Test that all expected status values exist."""
assert TodoStatus.TODO == "todo"
assert TodoStatus.IN_PROGRESS == "in_progress"
assert TodoStatus.DONE == "done"
assert TodoStatus.BLOCKED == "blocked"
assert TodoStatus.IN_REVIEW == "in_review"
assert TodoStatus.CANCELLED == "cancelled"
class TestTodoSource:
"""Tests for TodoSource enum."""
def test_source_values(self):
"""Test that all expected source values exist."""
assert TodoSource.LOCAL == "local"
assert TodoSource.JIRA == "jira"
assert TodoSource.GITHUB == "github"
assert TodoSource.LINEAR == "linear"
class TestTag:
"""Tests for Tag model."""
def test_tag_creation(self):
"""Test basic tag creation."""
tag = Tag(name="test-tag")
assert tag.name == "test-tag"
assert tag.id is None
def test_tag_with_id(self):
"""Test tag with explicit ID."""
tag = Tag(id=1, name="priority")
assert tag.id == 1
assert tag.name == "priority"
class TestTodo:
"""Tests for the Todo model."""
def test_todo_creation_minimal(self):
"""Test Todo creation with minimal fields."""
todo = Todo(content="Test task")
assert todo.content == "Test task"
assert todo.status == TodoStatus.TODO
assert todo.priority == 0
assert todo.source_system == TodoSource.LOCAL
assert isinstance(todo.uuid, UUID)
assert isinstance(todo.created_at, datetime)
def test_todo_creation_full(self):
"""Test Todo creation with all fields."""
now = datetime.now()
todo = Todo(
content="Full task",
status=TodoStatus.IN_PROGRESS,
priority=3,
due_date=now,
source_system=TodoSource.JIRA,
source_id="AGENTOPS-123",
source_url="https://jira.example.com/browse/AGENTOPS-123",
)
assert todo.content == "Full task"
assert todo.status == TodoStatus.IN_PROGRESS
assert todo.priority == 3
assert todo.source_system == TodoSource.JIRA
assert todo.source_id == "AGENTOPS-123"
def test_todo_to_dict(self):
"""Test Todo serialization to dictionary."""
todo = Todo(
content="Serialize me",
status=TodoStatus.DONE,
priority=5,
)
data = todo.to_dict()
assert data["content"] == "Serialize me"
assert data["status"] == "done"
assert data["priority"] == 5
assert isinstance(data["uuid"], str)
assert isinstance(data["created_at"], str)
def test_todo_from_row(self):
"""Test Todo creation from database row."""
now = datetime.now()
row = {
"id": 1,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"content": "From database",
"status": "in_progress",
"priority": 2,
"due_date": now.isoformat(),
"completed_at": None,
"created_at": now.isoformat(),
"updated_at": now.isoformat(),
"source_system": "jira",
"source_id": "AGENTOPS-456",
"source_url": None,
"external_metadata": None,
"last_synced_at": None,
"sync_hash": None,
}
todo = Todo.from_row(row)
assert todo.id == 1
assert todo.content == "From database"
assert todo.status == TodoStatus.IN_PROGRESS
assert todo.source_system == TodoSource.JIRA
assert todo.source_id == "AGENTOPS-456"
class TestExternalMetadata:
"""Tests for external metadata models."""
def test_jira_metadata(self):
"""Test JiraMetadata model."""
metadata = JiraMetadata(
key="AGENTOPS-123",
project_key="AGENTOPS",
issue_type="Task",
reporter="john.doe",
assignee="jane.doe",
labels=["backend", "urgent"],
components=["api"],
parent_key="AGENTOPS-100",
)
assert metadata.key == "AGENTOPS-123"
assert metadata.project_key == "AGENTOPS"
assert metadata.parent_key == "AGENTOPS-100"
assert "backend" in metadata.labels
def test_github_metadata(self):
"""Test GitHubMetadata model."""
metadata = GitHubMetadata(
repo_full_name="org/repo",
number=42,
issue_type="issue",
author="developer",
assignees=["dev1", "dev2"],
labels=["bug", "p1"],
)
assert metadata.repo_full_name == "org/repo"
assert metadata.number == 42
assert metadata.issue_type == "issue"
def test_linear_metadata(self):
"""Test LinearMetadata model."""
metadata = LinearMetadata(
identifier="LIN-123",
team_key="ENG",
project_name="Core Platform",
creator="alice",
assignee="bob",
labels=["feature"],
)
assert metadata.identifier == "LIN-123"
assert metadata.team_key == "ENG"
assert metadata.project_name == "Core Platform"
def test_external_task_metadata(self):
"""Test ExternalTaskMetadata with nested system-specific data."""
jira_meta = JiraMetadata(
key="AGENTOPS-123",
project_key="AGENTOPS",
issue_type="Story",
)
metadata = ExternalTaskMetadata(
jira=jira_meta,
raw_response={"id": "123", "key": "AGENTOPS-123"},
fetched_at=datetime.now(),
)
assert metadata.jira is not None
assert metadata.jira.key == "AGENTOPS-123"
assert metadata.github is None
assert metadata.linear is None
assert metadata.raw_response is not None
def test_external_metadata_serialization(self):
"""Test ExternalTaskMetadata JSON serialization."""
jira_meta = JiraMetadata(
key="TEST-1",
project_key="TEST",
issue_type="Bug",
)
metadata = ExternalTaskMetadata(
jira=jira_meta,
fetched_at=datetime.now(),
)
json_str = metadata.model_dump_json()
assert "TEST-1" in json_str
assert "Bug" in json_str