"""Pytest fixtures for coordinator tests.""" import pytest from fastapi.testclient import TestClient @pytest.fixture def webhook_secret() -> str: """Return a test webhook secret.""" return "test-webhook-secret-12345" @pytest.fixture def gitea_url() -> str: """Return a test Gitea URL.""" return "https://git.mosaicstack.dev" @pytest.fixture def sample_assigned_payload() -> dict[str, object]: """Return a sample Gitea 'assigned' issue webhook payload.""" return { "action": "assigned", "number": 157, "issue": { "id": 157, "number": 157, "title": "[COORD-001] Set up webhook receiver endpoint", "state": "open", "assignee": { "id": 1, "login": "mosaic", "full_name": "Mosaic Bot", }, }, "repository": { "name": "stack", "full_name": "mosaic/stack", "owner": {"login": "mosaic"}, }, "sender": { "id": 2, "login": "admin", "full_name": "Admin User", }, } @pytest.fixture def sample_unassigned_payload() -> dict[str, object]: """Return a sample Gitea 'unassigned' issue webhook payload.""" return { "action": "unassigned", "number": 157, "issue": { "id": 157, "number": 157, "title": "[COORD-001] Set up webhook receiver endpoint", "state": "open", "assignee": None, }, "repository": { "name": "stack", "full_name": "mosaic/stack", "owner": {"login": "mosaic"}, }, "sender": { "id": 2, "login": "admin", "full_name": "Admin User", }, } @pytest.fixture def sample_closed_payload() -> dict[str, object]: """Return a sample Gitea 'closed' issue webhook payload.""" return { "action": "closed", "number": 157, "issue": { "id": 157, "number": 157, "title": "[COORD-001] Set up webhook receiver endpoint", "state": "closed", "assignee": { "id": 1, "login": "mosaic", "full_name": "Mosaic Bot", }, }, "repository": { "name": "stack", "full_name": "mosaic/stack", "owner": {"login": "mosaic"}, }, "sender": { "id": 2, "login": "admin", "full_name": "Admin User", }, } @pytest.fixture def client(webhook_secret: str, gitea_url: str, monkeypatch: pytest.MonkeyPatch) -> TestClient: """Create a FastAPI test client with test configuration.""" # Set test environment variables monkeypatch.setenv("GITEA_WEBHOOK_SECRET", webhook_secret) monkeypatch.setenv("GITEA_URL", gitea_url) monkeypatch.setenv("ANTHROPIC_API_KEY", "test-anthropic-api-key") monkeypatch.setenv("LOG_LEVEL", "debug") # Force reload of settings import importlib from src import config importlib.reload(config) # Import app after settings are configured from src.main import app return TestClient(app)