Buckets:

download
raw
2.59 kB
"""Tests for WatcherConfig."""
import os
from unittest.mock import patch
from airflow_watcher.config import WatcherConfig
class TestWatcherConfig:
"""Test cases for WatcherConfig."""
def test_default_config(self):
"""Test default configuration values."""
config = WatcherConfig()
assert config.slack_webhook_url is None
assert config.slack_channel == "#airflow-alerts"
assert config.smtp_port == 587
assert config.failure_lookback_hours == 24
assert config.sla_check_interval_minutes == 5
def test_custom_config(self):
"""Test custom configuration values."""
config = WatcherConfig(
slack_webhook_url="https://hooks.slack.com/test",
slack_channel="#test-channel",
failure_lookback_hours=48,
)
assert config.slack_webhook_url == "https://hooks.slack.com/test"
assert config.slack_channel == "#test-channel"
assert config.failure_lookback_hours == 48
def test_email_recipients_list(self):
"""Test email recipients as list."""
config = WatcherConfig(email_recipients=["user1@example.com", "user2@example.com"])
assert len(config.email_recipients) == 2
assert "user1@example.com" in config.email_recipients
@patch.dict(
os.environ,
{
"AIRFLOW_WATCHER_SLACK_WEBHOOK_URL": "https://env-webhook.com",
"AIRFLOW_WATCHER_SLACK_CHANNEL": "#env-channel",
},
)
def test_load_from_env(self):
"""Test loading config from environment variables."""
config = WatcherConfig()
config._load_from_env()
assert config.slack_webhook_url == "https://env-webhook.com"
assert config.slack_channel == "#env-channel"
@patch.dict(
os.environ,
{
"AIRFLOW_WATCHER_SMTP_PORT": "465",
},
)
def test_load_from_env_int_value(self):
"""Test loading integer config from environment."""
config = WatcherConfig()
config._load_from_env()
assert config.smtp_port == 465
@patch.dict(
os.environ,
{
"AIRFLOW_WATCHER_EMAIL_RECIPIENTS": "user1@test.com, user2@test.com",
},
)
def test_load_from_env_list_value(self):
"""Test loading list config from environment."""
config = WatcherConfig()
config._load_from_env()
assert len(config.email_recipients) == 2
assert "user1@test.com" in config.email_recipients
assert "user2@test.com" in config.email_recipients

Xet Storage Details

Size:
2.59 kB
·
Xet hash:
d9abb4da39e0b17e8394c6652d5e1e9d57643b593b870cfe33b1cfe921dff415

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.