fixed tests
This commit is contained in:
@@ -2,9 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import Any
|
||||
from unittest.mock import AsyncMock, MagicMock, Mock, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
@@ -222,27 +221,31 @@ class TestCreateExternalLogHandler:
|
||||
class TestExternalLoggingConfiguration:
|
||||
"""Test external logging configuration via Settings."""
|
||||
|
||||
def test_external_logging_disabled_by_default(self) -> None:
|
||||
def test_external_logging_disabled_by_default(self, tmp_path: Path) -> None:
|
||||
"""External logging is disabled by default."""
|
||||
from app.config import Settings
|
||||
|
||||
config_dir = tmp_path / "fail2ban"
|
||||
config_dir.mkdir()
|
||||
settings = Settings(
|
||||
session_secret="a" * 64,
|
||||
fail2ban_socket="/tmp/test.sock",
|
||||
fail2ban_config_dir="/tmp/fail2ban",
|
||||
fail2ban_config_dir=str(config_dir),
|
||||
)
|
||||
|
||||
assert settings.external_logging_enabled is False
|
||||
assert settings.external_logging_provider is None
|
||||
|
||||
def test_datadog_settings(self) -> None:
|
||||
def test_datadog_settings(self, tmp_path: Path) -> None:
|
||||
"""Datadog settings can be configured."""
|
||||
from app.config import Settings
|
||||
|
||||
config_dir = tmp_path / "fail2ban"
|
||||
config_dir.mkdir()
|
||||
settings = Settings(
|
||||
session_secret="a" * 64,
|
||||
fail2ban_socket="/tmp/test.sock",
|
||||
fail2ban_config_dir="/tmp/fail2ban",
|
||||
fail2ban_config_dir=str(config_dir),
|
||||
external_logging_enabled=True,
|
||||
external_logging_provider="datadog",
|
||||
datadog_api_key="test-key",
|
||||
@@ -254,15 +257,18 @@ class TestExternalLoggingConfiguration:
|
||||
assert settings.datadog_api_key == "test-key"
|
||||
assert settings.datadog_site == "datadoghq.eu"
|
||||
|
||||
def test_elasticsearch_hosts_normalization(self) -> None:
|
||||
def test_elasticsearch_hosts_normalization(self, tmp_path: Path) -> None:
|
||||
"""Elasticsearch hosts can be provided as string or list."""
|
||||
from app.config import Settings
|
||||
|
||||
config_dir = tmp_path / "fail2ban"
|
||||
config_dir.mkdir()
|
||||
|
||||
# Test as comma-separated string
|
||||
settings1 = Settings(
|
||||
session_secret="a" * 64,
|
||||
fail2ban_socket="/tmp/test.sock",
|
||||
fail2ban_config_dir="/tmp/fail2ban",
|
||||
fail2ban_config_dir=str(config_dir),
|
||||
elasticsearch_hosts="http://es1:9200,http://es2:9200",
|
||||
)
|
||||
|
||||
@@ -272,7 +278,7 @@ class TestExternalLoggingConfiguration:
|
||||
settings2 = Settings(
|
||||
session_secret="a" * 64,
|
||||
fail2ban_socket="/tmp/test.sock",
|
||||
fail2ban_config_dir="/tmp/fail2ban",
|
||||
fail2ban_config_dir=str(config_dir),
|
||||
elasticsearch_hosts=["http://es1:9200", "http://es2:9200"],
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user