import pytest from health import HealthCheck, HealthReport, HealthStatus, run_checks class TestHealthStatus: def test_ok_less_than_warning(self): assert HealthStatus.OK.value == "ok" def test_warning_less_than_critical(self): assert HealthStatus.WARNING.value == "warning" class TestHealthReport: def test_all_ok_returns_ok(self): checks = [ HealthCheck("a", HealthStatus.OK, "fine", {}), HealthCheck("b", HealthStatus.OK, "fine", {}), ] report = run_checks(checks) assert report.status == HealthStatus.OK assert report.exit_code == 0 def test_one_warning_returns_warning(self): checks = [ HealthCheck("a", HealthStatus.OK, "fine", {}), HealthCheck("b", HealthStatus.WARNING, "hmm", {}), ] report = run_checks(checks) assert report.status == HealthStatus.WARNING assert report.exit_code == 1 def test_one_critical_returns_critical(self): checks = [ HealthCheck("a", HealthStatus.OK, "fine", {}), HealthCheck("b", HealthStatus.CRITICAL, "bad", {}), ] report = run_checks(checks) assert report.status == HealthStatus.CRITICAL assert report.exit_code == 2 def test_critical_trumps_warning(self): checks = [ HealthCheck("a", HealthStatus.WARNING, "hmm", {}), HealthCheck("b", HealthStatus.CRITICAL, "bad", {}), ] report = run_checks(checks) assert report.status == HealthStatus.CRITICAL assert report.exit_code == 2 def test_empty_checks_returns_ok(self): report = run_checks([]) assert report.status == HealthStatus.OK assert report.exit_code == 0