Spaces:
Sleeping
Sleeping
File size: 1,692 Bytes
36ee2f7 75c7c56 36ee2f7 23dfad0 36ee2f7 23dfad0 36ee2f7 23dfad0 36ee2f7 75c7c56 36ee2f7 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | import pytest
from unittest.mock import MagicMock, patch
from fastapi.testclient import TestClient
from app.main import app
from app.db.session import get_db
TEST_API_KEY = "test-secret-key"
VALID_PAYLOAD = {
"age": 35, "genre": "M", "statut_marital": "Marié(e)",
"poste": "Consultant", "domaine_etude": "Infra & Cloud",
"niveau_education": 3, "departement": "Ventes", "niveau_hierarchique_poste": 2,
"nombre_experiences_precedentes": 2,
"annee_experience_totale": 10, "annees_dans_l_entreprise": 5,
"annees_dans_le_poste_actuel": 2, "annees_sous_responsable_actuel": 3,
"annees_depuis_la_derniere_promotion": 1,
"note_evaluation_actuelle": 3, "note_evaluation_precedente": 3,
"augmentation_salaire_precedente": 15, "nb_formations_suivies": 2,
"nombre_participation_pee": 1,
"satisfaction_employee_environnement": 3,
"satisfaction_employee_nature_travail": 4,
"satisfaction_employee_equipe": 3,
"satisfaction_employee_equilibre_pro_perso": 2,
"heure_supplementaires": "Non", "frequence_deplacement": "Occasionnel",
"distance_domicile_travail": 10, "revenu_mensuel": 5000,
}
def override_get_db():
yield MagicMock()
app.dependency_overrides[get_db] = override_get_db
@pytest.fixture(scope="module")
def client():
mock_pipeline = MagicMock()
# Simule predict_proba → [[proba_reste, proba_quitte]]
# 0.3 < seuil 0.40 → prédiction "Reste"
mock_pipeline.predict_proba.return_value = [[0.70, 0.30]]
with patch("app.main.load_pipeline", return_value=(mock_pipeline, 0.40)), \
patch.dict("os.environ", {"API_KEY": TEST_API_KEY}):
with TestClient(app) as c:
yield c
|