feature/integracion-cpanel-asrecovery
This commit is contained in:
79
tests/test_bootstrap.py
Normal file
79
tests/test_bootstrap.py
Normal file
@@ -0,0 +1,79 @@
|
||||
"""Pruebas de bootstrap y carga de .env."""
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
from app.config.bootstrap import ensure_runtime_layout
|
||||
from app.config.env_loader import (
|
||||
apply_env_overrides,
|
||||
get_launch_options,
|
||||
is_panel_configured,
|
||||
render_env_template,
|
||||
)
|
||||
from app.constants import CONFIG_DIR, DEFAULT_CONFIG, DIR_ENTRADA, ENV_PATH
|
||||
|
||||
|
||||
def test_render_env_template_contains_app_dir(tmp_path: Path):
|
||||
text = render_env_template(tmp_path)
|
||||
assert str(tmp_path) in text
|
||||
assert "CLOUDRESTORE_PANEL_API_URL" in text
|
||||
|
||||
|
||||
def test_ensure_runtime_layout_creates_structure(tmp_path: Path, monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setattr("app.config.bootstrap.APP_DIR", tmp_path)
|
||||
monkeypatch.setattr("app.config.bootstrap.CONFIG_DIR", tmp_path / "config")
|
||||
monkeypatch.setattr("app.config.bootstrap.DATA_DIR", tmp_path / "config" / "data")
|
||||
monkeypatch.setattr("app.config.bootstrap.LOGS_DIR", tmp_path / "config" / "logs")
|
||||
monkeypatch.setattr("app.config.bootstrap.ODBC_DIR", tmp_path / "config" / "odbc")
|
||||
monkeypatch.setattr("app.config.bootstrap.SEVEN_ZIP_DIR", tmp_path / "config" / "7zip")
|
||||
monkeypatch.setattr("app.config.bootstrap.ENV_PATH", tmp_path / "config" / ".env")
|
||||
monkeypatch.setattr("app.config.bootstrap.DIR_ENTRADA", tmp_path / "Entrada")
|
||||
monkeypatch.setattr("app.config.bootstrap.DIR_PROCESADOS", tmp_path / "Procesados")
|
||||
monkeypatch.setattr("app.config.bootstrap.DIR_FALLADOS", tmp_path / "Fallados")
|
||||
monkeypatch.setattr("app.config.bootstrap.DIR_TEMP", tmp_path / "Temp")
|
||||
monkeypatch.setattr("app.constants.DB_PATH", tmp_path / "config" / "data" / "app.db")
|
||||
|
||||
ensure_runtime_layout()
|
||||
|
||||
assert (tmp_path / "config" / ".env").is_file()
|
||||
assert (tmp_path / "Entrada").is_dir()
|
||||
assert (tmp_path / "config" / "data" / "app.db").is_file()
|
||||
|
||||
|
||||
def test_is_panel_configured(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.delenv("CLOUDRESTORE_PANEL_API_URL", raising=False)
|
||||
monkeypatch.delenv("CLOUDRESTORE_PANEL_API_TOKEN", raising=False)
|
||||
monkeypatch.delenv("CLOUDRESTORE_PANEL_INSTANCE_KEY", raising=False)
|
||||
assert not is_panel_configured()
|
||||
|
||||
monkeypatch.setenv("CLOUDRESTORE_PANEL_API_URL", "https://panel:3000")
|
||||
monkeypatch.setenv("CLOUDRESTORE_PANEL_API_TOKEN", "secret")
|
||||
monkeypatch.setenv("CLOUDRESTORE_PANEL_INSTANCE_KEY", "srv1")
|
||||
assert is_panel_configured()
|
||||
|
||||
|
||||
def test_get_launch_options_auto_start_does_not_minimize(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setenv("CLOUDRESTORE_AUTO_START", "true")
|
||||
monkeypatch.delenv("CLOUDRESTORE_START_MINIMIZED", raising=False)
|
||||
opts = get_launch_options()
|
||||
assert opts.start_engine is True
|
||||
assert opts.minimized is False
|
||||
|
||||
|
||||
def test_get_launch_options_start_minimized(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setenv("CLOUDRESTORE_START_MINIMIZED", "true")
|
||||
opts = get_launch_options()
|
||||
assert opts.minimized is True
|
||||
|
||||
|
||||
def test_render_env_template_documents_start_minimized(tmp_path: Path):
|
||||
text = render_env_template(tmp_path)
|
||||
assert "CLOUDRESTORE_START_MINIMIZED=false" in text
|
||||
|
||||
|
||||
def test_apply_env_overrides_paths(monkeypatch: pytest.MonkeyPatch):
|
||||
monkeypatch.setenv("CLOUDRESTORE_INPUT_FOLDER", "/tmp/in")
|
||||
cfg = apply_env_overrides(DEFAULT_CONFIG.copy())
|
||||
assert cfg["paths"]["input_folder"] == "/tmp/in"
|
||||
Reference in New Issue
Block a user