Bruno Charest ecefbc8611
Some checks failed
Tests / Backend Tests (Python) (3.10) (push) Has been cancelled
Tests / Backend Tests (Python) (3.11) (push) Has been cancelled
Tests / Backend Tests (Python) (3.12) (push) Has been cancelled
Tests / Frontend Tests (JS) (push) Has been cancelled
Tests / Integration Tests (push) Has been cancelled
Tests / All Tests Passed (push) Has been cancelled
Clean up test files and debug artifacts, add node_modules to gitignore, export DashboardManager for testing, and enhance pytest configuration with comprehensive test markers and settings
2025-12-15 08:15:49 -05:00

162 lines
4.1 KiB
Python

"""
Tests pour les modèles SQLAlchemy.
Couvre:
- Création d'instances
- Relations entre modèles
- Validations
"""
import pytest
from datetime import datetime, timezone
pytestmark = pytest.mark.unit
class TestHostModel:
"""Tests pour le modèle Host."""
def test_host_creation(self):
"""Création d'un hôte."""
from app.models.host import Host
host = Host(
id="host-1",
name="test-host.local",
ip_address="192.168.1.100",
ansible_group="env_prod"
)
assert host.name == "test-host.local"
assert host.ip_address == "192.168.1.100"
def test_host_default_status(self):
"""Statut par défaut."""
from app.models.host import Host
host = Host(id="h1", name="test.local", ip_address="10.0.0.1")
# Status has server_default, so it's None until persisted
assert host.status is None or host.status == "unknown"
class TestTaskModel:
"""Tests pour le modèle Task."""
def test_task_creation(self):
"""Création d'une tâche."""
from app.models.task import Task
task = Task(
action="health-check",
target="all",
status="pending"
)
assert task.action == "health-check"
assert task.target == "all"
assert task.status == "pending"
class TestScheduleModel:
"""Tests pour le modèle Schedule."""
def test_schedule_creation(self):
"""Création d'un schedule."""
from app.models.schedule import Schedule
schedule = Schedule(
name="Daily Backup",
playbook="backup.yml",
target="all",
schedule_type="recurring",
cron_expression="0 2 * * *"
)
assert schedule.name == "Daily Backup"
assert schedule.cron_expression == "0 2 * * *"
def test_schedule_default_enabled(self):
"""Enabled par défaut."""
from app.models.schedule import Schedule
schedule = Schedule(name="Test", playbook="test.yml", target="all")
assert schedule.enabled is True or schedule.enabled is None
class TestUserModel:
"""Tests pour le modèle User."""
def test_user_creation(self):
"""Création d'un utilisateur."""
from app.models.user import User
user = User(
username="testuser",
hashed_password="hashed123",
email="test@example.com",
role="admin"
)
assert user.username == "testuser"
assert user.role == "admin"
def test_user_default_active(self):
"""Actif par défaut."""
from app.models.user import User
user = User(username="test", hashed_password="hash")
assert user.is_active is True or user.is_active is None
class TestAlertModel:
"""Tests pour le modèle Alert."""
def test_alert_creation(self):
"""Création d'une alerte."""
from app.models.alert import Alert
alert = Alert(
category="system",
level="warning",
title="Test Alert",
message="This is a test"
)
assert alert.title == "Test Alert"
assert alert.level == "warning"
class TestLogModel:
"""Tests pour le modèle Log."""
def test_log_creation(self):
"""Création d'un log."""
from app.models.log import Log
log = Log(
level="INFO",
message="Test log message",
source="test"
)
assert log.level == "INFO"
assert log.message == "Test log message"
class TestScheduleRunModel:
"""Tests pour le modèle ScheduleRun."""
def test_schedule_run_creation(self):
"""Création d'une exécution."""
from app.models.schedule_run import ScheduleRun
run = ScheduleRun(
schedule_id=1,
status="running"
)
assert run.status == "running"