Fix MSS template test: add engine initialization and create TemplateStore

- Add engine.initialize() call in test endpoint to fix "Engine not initialized" error for MSS and DXcam
- Create template.py with CaptureTemplate dataclass for template data model
- Create template_store.py with TemplateStore class for template CRUD operations
- TemplateStore loads from capture_templates.json and provides get_all, create, get, update, delete methods

Fixes MSS capture test failing with "Engine not initialized" error. WGC worked because it auto-initializes in capture_display(), but MSS and DXcam require explicit initialization.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-09 19:23:20 +03:00
parent fd38481e17
commit fdb73c9fc9
3 changed files with 284 additions and 1 deletions

View File

@@ -0,0 +1,61 @@
"""Capture template data model."""
from dataclasses import dataclass
from datetime import datetime
from typing import Any, Dict, Optional
@dataclass
class CaptureTemplate:
"""Represents a screen capture template configuration."""
id: str
name: str
engine_type: str
engine_config: Dict[str, Any]
is_default: bool
created_at: datetime
updated_at: datetime
description: Optional[str] = None
def to_dict(self) -> dict:
"""Convert template to dictionary.
Returns:
Dictionary representation
"""
return {
"id": self.id,
"name": self.name,
"engine_type": self.engine_type,
"engine_config": self.engine_config,
"is_default": self.is_default,
"created_at": self.created_at.isoformat(),
"updated_at": self.updated_at.isoformat(),
"description": self.description,
}
@classmethod
def from_dict(cls, data: dict) -> "CaptureTemplate":
"""Create template from dictionary.
Args:
data: Dictionary with template data
Returns:
CaptureTemplate instance
"""
return cls(
id=data["id"],
name=data["name"],
engine_type=data["engine_type"],
engine_config=data.get("engine_config", {}),
is_default=data.get("is_default", False),
created_at=datetime.fromisoformat(data["created_at"])
if isinstance(data.get("created_at"), str)
else data.get("created_at", datetime.utcnow()),
updated_at=datetime.fromisoformat(data["updated_at"])
if isinstance(data.get("updated_at"), str)
else data.get("updated_at", datetime.utcnow()),
description=data.get("description"),
)