67 lines
2.0 KiB
Python
67 lines
2.0 KiB
Python
"""Test fixtures for castle-api."""
|
|
|
|
from collections.abc import Generator
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
import yaml
|
|
from fastapi.testclient import TestClient
|
|
|
|
from castle_api.config import settings
|
|
from castle_api.main import app
|
|
|
|
|
|
@pytest.fixture
|
|
def castle_root(tmp_path: Path) -> Generator[Path, None, None]:
|
|
"""Create a temporary castle root with castle.yaml."""
|
|
castle_yaml = tmp_path / "castle.yaml"
|
|
config = {
|
|
"gateway": {"port": 9000},
|
|
"components": {
|
|
"test-svc": {
|
|
"description": "Test service",
|
|
"run": {
|
|
"runner": "python_uv_tool",
|
|
"tool": "test-svc",
|
|
"cwd": "test-svc",
|
|
},
|
|
"expose": {
|
|
"http": {
|
|
"internal": {"port": 19000},
|
|
"health_path": "/health",
|
|
}
|
|
},
|
|
"proxy": {"caddy": {"path_prefix": "/test-svc"}},
|
|
"manage": {"systemd": {}},
|
|
},
|
|
"test-tool": {
|
|
"description": "Test tool",
|
|
"install": {"path": {"alias": "test-tool"}},
|
|
"tool": {
|
|
"source": "test-tool",
|
|
"system_dependencies": ["pandoc"],
|
|
},
|
|
},
|
|
"test-tool-2": {
|
|
"description": "Another test tool",
|
|
"tool": {
|
|
"source": "test-tool-2",
|
|
"version": "2.0.0",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
castle_yaml.write_text(yaml.dump(config, default_flow_style=False))
|
|
|
|
original = settings.castle_root
|
|
settings.castle_root = tmp_path
|
|
yield tmp_path
|
|
settings.castle_root = original
|
|
|
|
|
|
@pytest.fixture
|
|
def client(castle_root: Path) -> Generator[TestClient, None, None]:
|
|
"""Create a test client pointing to temporary castle root."""
|
|
with TestClient(app) as client:
|
|
yield client
|