Files
tracker-cli/tests/conftest.py
Daniel Arroyo 2735562b65 Add comprehensive test suite for MVP-1 Personal Tracker CLI
Implements 72 tests covering:
- Model tests (Project, Session, Note, Change)
- ProjectService tests (create, get, list, ensure structure)
- SessionService tests (active session management)
- FileStorage tests (read/write operations)
- Complete flow tests (init -> start -> note -> stop -> show)
- Note consolidation tests

Uses pytest with tmp_path fixtures for isolated testing.
2026-03-23 09:40:46 -03:00

103 lines
3.0 KiB
Python

"""Pytest fixtures for tracker tests."""
import json
import tempfile
from datetime import datetime, timedelta
from pathlib import Path
from typing import Optional
import pytest
from tracker.models import Project, Session, Note, NoteType, Change
@pytest.fixture
def tmp_project_dir(tmp_path):
"""Create a temporary directory for project tests."""
projects_root = tmp_path / "projects"
projects_root.mkdir()
return projects_root
@pytest.fixture
def sample_project_data():
"""Sample project data for testing."""
return {
"id": "test-project-id-123",
"name": "Test Project",
"slug": "test-project",
"description": "A test project for unit testing",
"type": "code",
"status": "active",
"tags": ["python", "testing"],
"root_path": "/path/to/projects/test-project",
"repo_path": "/path/to/repos/test-project",
"created_at": datetime(2024, 1, 15, 10, 0, 0),
"updated_at": datetime(2024, 1, 15, 10, 0, 0),
"last_session_at": None,
}
@pytest.fixture
def sample_project(sample_project_data):
"""Create a sample Project instance."""
return Project(**sample_project_data)
@pytest.fixture
def mock_session(sample_project):
"""Create a mock session for testing."""
return Session(
id="session-123",
project_slug=sample_project.slug,
started_at=datetime(2024, 1, 15, 10, 0, 0),
ended_at=datetime(2024, 1, 15, 11, 30, 0),
duration_minutes=90,
objective="Complete initial implementation",
summary="Worked on core features",
work_done=["Implemented feature A", "Fixed bug B"],
changes=["Added new endpoint"],
decisions=["Use JSON for storage"],
blockers=[],
next_steps=["Add tests", "Write documentation"],
references=["https://example.com/docs"],
raw_notes=[
{"type": "work", "text": "Working on feature A", "timestamp": "2024-01-15T10:15:00"},
{"type": "idea", "text": "Consider using caching", "timestamp": "2024-01-15T10:30:00"},
],
)
@pytest.fixture
def sample_note():
"""Create a sample note for testing."""
return Note(
type=NoteType.WORK,
text="Completed the implementation of feature X",
created_at=datetime(2024, 1, 15, 10, 30, 0),
)
@pytest.fixture
def sample_change():
"""Create a sample change for testing."""
return Change(
date=datetime(2024, 1, 15).date(),
type="code",
title="Added user authentication",
impact="Improved security",
references=["#123"],
)
@pytest.fixture
def tmp_project_with_structure(tmp_project_dir, sample_project_data):
"""Create a temporary project with directory structure."""
slug = sample_project_data["slug"]
project_root = tmp_project_dir / slug
(project_root / "sessions").mkdir(parents=True)
(project_root / "docs").mkdir(parents=True)
(project_root / "assets").mkdir(parents=True)
(project_root / "meta").mkdir(parents=True)
return project_root