- Authoritative candidate capture with server-issued artifacts and raw-byte
immutability hashing (source_response_hash server-owned)
- Closed-period lifecycle: request-hash bound approvals, persisted closure
immutability violations, byte-for-byte catalog stability on reclosure
- Verification runs: persisted VerificationRun model + FK migration,
publish gate (block_publish), scheduled observability runs (02:00 UTC)
- FR-013 baseline inheritance: prior_release_id migration, plan_inheritance/
execute_inheritance classification and re-extraction, API endpoints
- Visual executor bound to release-deployment environment; caller mismatch
rejected; visual SSIM/reconciliation modules
- Query execution decomposed: envelope/model/executor split, no direct SQL
- AgentRun approvals extracted to submodule; evidence adapter; _utils
- Dashboard testing service decomposed into 30+ modules (all <400 LOC)
- Five Feature-037 agent tools with permission guards (tools_037.py)
- API readiness endpoint; Alembic env/migrations; test fixture repos
- Specs 036/037 contracts, openapi.yaml, schema.json, tasks/traceability
updated; semantic index rebuilt with 0 parse warnings
- Fix ADR-0003 parser ambiguity: remove [DEF🆔ADR] prose example
- Add axiom-mcp-agent-feedback.md: agent findings for MCP rework plan
- Tests: 298 service + 1464 API + 45 agent passing; ruff clean
88 lines
3.0 KiB
Python
88 lines
3.0 KiB
Python
# #region Test.Api.GitEnvironmentRoutes [C:2] [TYPE Module] [SEMANTICS test,git,environment,routes]
|
|
# @BRIEF Unit tests for Git environment routes.
|
|
# @RELATION BINDS_TO -> [Api.EnvironmentRoutes.GitEnvironmentRoutes]
|
|
# @TEST_EDGE: empty_list -> 200
|
|
|
|
import os
|
|
|
|
os.environ.setdefault("DATABASE_URL", "sqlite:///:memory:")
|
|
os.environ.setdefault("AUTH_DATABASE_URL", "sqlite:///:memory:")
|
|
os.environ.setdefault("SECRET_KEY", "test-secret-key-for-tests")
|
|
|
|
import sys
|
|
from pathlib import Path
|
|
from unittest.mock import MagicMock, patch
|
|
|
|
import pytest
|
|
from fastapi import FastAPI
|
|
from fastapi.testclient import TestClient
|
|
|
|
_src = str(Path(__file__).resolve().parent.parent.parent / "src")
|
|
if _src not in sys.path:
|
|
sys.path.insert(0, _src)
|
|
|
|
|
|
def _make_client(overrides: dict | None = None) -> TestClient:
|
|
from src.api.routes.git._environment_routes import router
|
|
from src.dependencies import get_current_user, has_permission
|
|
from src.schemas.auth import User, RoleSchema
|
|
|
|
app = FastAPI()
|
|
app.include_router(router, prefix="/api/git")
|
|
|
|
mock_user = User(
|
|
id="admin-1", username="admin", email="admin@x.com",
|
|
auth_source="LOCAL",
|
|
created_at=__import__("datetime").datetime.now(),
|
|
roles=[RoleSchema(id="r1", name="Admin", description="", is_admin=True, permissions=[])],
|
|
)
|
|
|
|
defaults = {
|
|
get_current_user: lambda: mock_user,
|
|
}
|
|
if overrides:
|
|
defaults.update(overrides)
|
|
for dep, mock_fn in defaults.items():
|
|
app.dependency_overrides[dep] = mock_fn
|
|
return TestClient(app)
|
|
|
|
|
|
class TestGetEnvironments:
|
|
"""GET /api/git/environments"""
|
|
|
|
def test_list_environments_success(self):
|
|
"""Happy path: returns deployment environments."""
|
|
mock_config = MagicMock()
|
|
env1 = MagicMock()
|
|
env1.id = "env-1"
|
|
env1.name = "Production"
|
|
env1.url = "https://superset.prod.com"
|
|
env2 = MagicMock()
|
|
env2.id = "env-2"
|
|
env2.name = "Staging"
|
|
env2.url = "https://superset.staging.com"
|
|
mock_config.get_environments.return_value = [env1, env2]
|
|
|
|
from src.dependencies import get_config_manager
|
|
client = _make_client({get_config_manager: lambda: mock_config})
|
|
resp = client.get("/api/git/environments")
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert len(data) == 2
|
|
assert data[0]["id"] == "env-1"
|
|
assert data[0]["name"] == "Production"
|
|
assert data[0]["superset_url"] == "https://superset.prod.com"
|
|
assert data[0]["is_active"] is True
|
|
|
|
def test_list_environments_empty(self):
|
|
"""Empty list returns 200."""
|
|
mock_config = MagicMock()
|
|
mock_config.get_environments.return_value = []
|
|
|
|
from src.dependencies import get_config_manager
|
|
client = _make_client({get_config_manager: lambda: mock_config})
|
|
resp = client.get("/api/git/environments")
|
|
assert resp.status_code == 200
|
|
assert resp.json() == []
|
|
# #endregion Test.Api.GitEnvironmentRoutes
|