Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
23132c6219 | ||
|
|
514f417c15 |
No files matched your search
+21
@@ -64,6 +64,7 @@ async def lifespan(_: FastAPI):
|
||||
# Don't fail app startup for a best-effort migration.
|
||||
pass
|
||||
auth.bootstrap_setup()
|
||||
_log_config_summary()
|
||||
worker_task = asyncio.create_task(conversion_worker())
|
||||
try:
|
||||
yield
|
||||
@@ -278,6 +279,26 @@ def get_file(file_id: int, db: DbSession) -> IsoMovie:
|
||||
return item
|
||||
|
||||
|
||||
def _log_config_summary() -> None:
|
||||
"""Rend visible au lancement le chargement de conf.json."""
|
||||
cfg = read_config()
|
||||
configured = [
|
||||
name
|
||||
for name in ("radarr", "sonarr", "prowlarr", "jellyfin", "seerr")
|
||||
if getattr(cfg, name).url
|
||||
]
|
||||
if cfg.qbittorrent.url:
|
||||
mode = "identifiants" if cfg.qbittorrent.username else "bypass d'authentification"
|
||||
configured.append(f"qbittorrent ({mode})")
|
||||
if configured:
|
||||
print(f"conf.json charge: {', '.join(configured)}", flush=True)
|
||||
else:
|
||||
print(
|
||||
"conf.json: aucune connexion configuree — a renseigner dans la page Configuration.",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
|
||||
def _poster_url(movie: dict) -> str | None:
|
||||
for image in movie.get("images") or []:
|
||||
if image.get("coverType") == "poster":
|
||||
|
||||
@@ -4,8 +4,11 @@ import respx
|
||||
from fastapi.testclient import TestClient
|
||||
from httpx import Response
|
||||
|
||||
from app import auth as auth_module
|
||||
from app.conf_store import config_path
|
||||
from app.database import SessionLocal
|
||||
from app.main import app
|
||||
from app.models import User
|
||||
|
||||
|
||||
def configure_radarr(client: TestClient) -> None:
|
||||
@@ -145,3 +148,54 @@ def test_settings_persist_to_conf_json() -> None:
|
||||
assert raw["qbittorrent"]["port"] == 8080
|
||||
assert raw["qbittorrent"]["username"] == "admin"
|
||||
assert raw["qbittorrent"]["password"] == "pass"
|
||||
|
||||
|
||||
def test_setup_link_only_without_existing_account() -> None:
|
||||
"""Le lien de premier lancement ne doit pas apparaitre si un compte existe.
|
||||
|
||||
Verifie aussi que l'endpoint de setup refuse tout second compte, meme avec
|
||||
un jeton valide.
|
||||
"""
|
||||
with TestClient(app) as client:
|
||||
client.post("/api/auth/setup", json={"token": "invalide", "username": "x", "password": "y"})
|
||||
# Nettoyage: la base de test est partagee entre les tests.
|
||||
with SessionLocal() as db:
|
||||
db.query(User).delete()
|
||||
db.commit()
|
||||
# Simule un redemarrage: le lifespan relance bootstrap_setup.
|
||||
with TestClient(app):
|
||||
assert auth_module.setup_token is not None
|
||||
with TestClient(app) as client:
|
||||
response = client.post(
|
||||
"/api/auth/setup",
|
||||
json={
|
||||
"token": auth_module.setup_token,
|
||||
"username": "admin",
|
||||
"password": "pass",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
# Le jeton est consomme apres creation du compte.
|
||||
assert auth_module.setup_token is None
|
||||
# Nouveau demarrage: un compte existe -> plus aucun jeton genere,
|
||||
# et la creation d'un second compte est refusee.
|
||||
with TestClient(app) as client:
|
||||
assert auth_module.setup_token is None
|
||||
response = client.post(
|
||||
"/api/auth/setup",
|
||||
json={"token": "peu-importe", "username": "autre", "password": "z"},
|
||||
)
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
def test_startup_logs_conf_json_summary(capsys) -> None:
|
||||
"""Au lancement, le log indique si conf.json est charge et ce qu'il contient."""
|
||||
with TestClient(app) as client:
|
||||
client.put(
|
||||
"/api/settings/qbittorrent",
|
||||
json={"url": "192.168.1.50", "port": 8555},
|
||||
)
|
||||
with TestClient(app):
|
||||
captured = capsys.readouterr()
|
||||
assert "conf.json charge" in captured.out
|
||||
assert "qbittorrent (bypass d'authentification)" in captured.out
|
||||
Reference in new issue
Block a user