Files
XCClaw/tests/test_models.py

100 lines
3.0 KiB
Python

import pytest
from datetime import datetime
from app.models.session import (
SessionType, TaskStatus, CreateSessionRequest,
Task, PersistentSession, TaskHistory
)
class TestSessionType:
def test_session_types(self):
assert SessionType.EPHEMERAL.value == "ephemeral"
assert SessionType.PERSISTENT.value == "persistent"
assert SessionType.SCHEDULED.value == "scheduled"
class TestTaskStatus:
def test_task_statuses(self):
assert TaskStatus.PENDING.value == "pending"
assert TaskStatus.RUNNING.value == "running"
assert TaskStatus.COMPLETED.value == "completed"
assert TaskStatus.FAILED.value == "failed"
assert TaskStatus.ABORTED.value == "aborted"
class TestCreateSessionRequest:
def test_default_values(self):
req = CreateSessionRequest(prompt="test prompt")
assert req.type == SessionType.EPHEMERAL
assert req.prompt == "test prompt"
assert req.title is None
def test_with_all_fields(self):
req = CreateSessionRequest(
type=SessionType.PERSISTENT,
title="Test Session",
prompt="test prompt"
)
assert req.type == SessionType.PERSISTENT
assert req.title == "Test Session"
assert req.prompt == "test prompt"
class TestTask:
def test_task_creation(self):
task = Task(
id="test-id",
type=SessionType.EPHEMERAL,
prompt="test prompt"
)
assert task.id == "test-id"
assert task.type == SessionType.EPHEMERAL
assert task.prompt == "test prompt"
assert task.status == TaskStatus.PENDING
assert task.session_id is None
def test_task_with_timestamps(self):
now = datetime.now()
task = Task(
id="test-id",
type=SessionType.SCHEDULED,
prompt="scheduled task",
created_at=now,
started_at=now,
finished_at=now,
status=TaskStatus.COMPLETED
)
assert task.created_at == now
assert task.started_at == now
assert task.finished_at == now
assert task.status == TaskStatus.COMPLETED
class TestPersistentSession:
def test_persistent_session_creation(self):
now = datetime.now()
session = PersistentSession(
id="ps-1",
session_id="session-123",
name="My Session",
created_at=now,
last_used_at=now
)
assert session.id == "ps-1"
assert session.session_id == "session-123"
assert session.name == "My Session"
class TestTaskHistory:
def test_task_history_creation(self):
history = TaskHistory(
id="history-1",
type=SessionType.EPHEMERAL,
prompt="test",
status=TaskStatus.COMPLETED,
created_at="2024-01-01T00:00:00",
finished_at="2024-01-01T00:01:00"
)
assert history.id == "history-1"
assert history.status == TaskStatus.COMPLETED