113 lines
3.3 KiB
Python
113 lines
3.3 KiB
Python
"""
|
|
Tests for Deployment Module - Homologation Validator.
|
|
|
|
Tests integration validation functionality.
|
|
"""
|
|
|
|
import pytest
|
|
from src.deployment.homologation import (
|
|
HomologationValidator,
|
|
HomologationResult,
|
|
ValidationCheck,
|
|
ValidationStatus
|
|
)
|
|
|
|
|
|
class TestValidationCheck:
|
|
"""Tests for ValidationCheck dataclass."""
|
|
|
|
def test_check_creation(self):
|
|
"""Test creating a validation check."""
|
|
check = ValidationCheck(
|
|
name="test_check",
|
|
description="Test validation"
|
|
)
|
|
|
|
assert check.status == ValidationStatus.PENDING
|
|
assert check.duration_ms == 0
|
|
|
|
def test_check_with_status(self):
|
|
"""Test check with status."""
|
|
check = ValidationCheck(
|
|
name="test_check",
|
|
description="Test",
|
|
status=ValidationStatus.PASSED,
|
|
message="All good"
|
|
)
|
|
|
|
assert check.status == ValidationStatus.PASSED
|
|
|
|
|
|
class TestHomologationResult:
|
|
"""Tests for HomologationResult dataclass."""
|
|
|
|
def test_result_counts(self):
|
|
"""Test result counting."""
|
|
from datetime import datetime, timezone
|
|
|
|
result = HomologationResult(
|
|
environment="test",
|
|
started_at=datetime.now(timezone.utc),
|
|
checks=[
|
|
ValidationCheck("c1", "d1", ValidationStatus.PASSED),
|
|
ValidationCheck("c2", "d2", ValidationStatus.PASSED),
|
|
ValidationCheck("c3", "d3", ValidationStatus.FAILED),
|
|
ValidationCheck("c4", "d4", ValidationStatus.WARNING),
|
|
]
|
|
)
|
|
|
|
assert result.passed == 2
|
|
assert result.failed == 1
|
|
assert result.warnings == 1
|
|
assert result.all_passed is False
|
|
|
|
def test_all_passed(self):
|
|
"""Test all_passed property."""
|
|
from datetime import datetime, timezone
|
|
|
|
result = HomologationResult(
|
|
environment="test",
|
|
started_at=datetime.now(timezone.utc),
|
|
checks=[
|
|
ValidationCheck("c1", "d1", ValidationStatus.PASSED),
|
|
ValidationCheck("c2", "d2", ValidationStatus.PASSED),
|
|
]
|
|
)
|
|
|
|
assert result.all_passed is True
|
|
|
|
|
|
class TestHomologationValidator:
|
|
"""Tests for HomologationValidator."""
|
|
|
|
@pytest.fixture
|
|
def validator(self):
|
|
"""Create validator."""
|
|
return HomologationValidator("test")
|
|
|
|
def test_format_report_empty(self, validator):
|
|
"""Test report with no result."""
|
|
report = validator.format_report()
|
|
|
|
assert "Nenhum resultado" in report
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_run_checks_returns_result(self, validator):
|
|
"""Test that run_all_checks returns a result."""
|
|
# This will fail or skip checks but should still return a result
|
|
result = await validator.run_all_checks()
|
|
|
|
assert result is not None
|
|
assert result.environment == "test"
|
|
assert len(result.checks) > 0
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_format_report_after_run(self, validator):
|
|
"""Test formatting report after running checks."""
|
|
await validator.run_all_checks()
|
|
|
|
report = validator.format_report()
|
|
|
|
assert "RELATÓRIO DE HOMOLOGAÇÃO" in report
|
|
assert "TEST" in report
|