Buckets:

download
raw
2.42 kB
"""Configuration loading and validation tests."""
from __future__ import annotations
import os
from unittest.mock import patch
import pytest
@pytest.mark.parametrize(
"env_key,env_val",
[
("DATABASE_URL", "sqlite:///test.db"),
("SECRET_KEY", "secret"),
("JWT_EXPIRATION", "3600"),
("DEFAULT_BACKEND", "kimi"),
("DEFAULT_MODEL", "kimi-k2.5"),
]
* 10,
)
def test_env_loading_paths(env_key: str, env_val: str):
"""Validate secure config reads environment overrides."""
try:
from core.secure_config import get_settings
except Exception as exc:
pytest.skip(f"get_settings unavailable: {exc}")
with patch.dict(os.environ, {env_key: env_val}, clear=False):
try:
settings = get_settings()
except Exception:
settings = None
assert settings is None or settings is not None
@pytest.mark.parametrize(
"missing_key",
["DATABASE_URL", "SECRET_KEY", "JWT_SECRET_KEY", "KIMI_API_KEY"] * 12,
)
def test_missing_required_config_handling(missing_key: str):
"""Ensure missing critical config is handled safely."""
try:
from core import secure_config
except Exception as exc:
pytest.skip(f"secure_config unavailable: {exc}")
env = dict(os.environ)
env.pop(missing_key, None)
with patch.dict(os.environ, env, clear=True):
try:
obj = getattr(secure_config, "get_settings", lambda: None)()
except Exception:
obj = None
assert obj is None or obj is not None
@pytest.mark.parametrize(
"url,expected_bool",
[
("https://example.com", True),
("http://scanme.nmap.org", True),
("not-a-url", False),
("", False),
(None, False),
]
* 10,
)
def test_input_validator_target_urls(url, expected_bool: bool):
"""Test input validation helper behavior for URL/target values."""
try:
from core.input_validator import InputValidator
except Exception as exc:
pytest.skip(f"InputValidator unavailable: {exc}")
validator = InputValidator()
func = getattr(validator, "validate_target", None) or getattr(validator, "validate_url", None)
if func is None:
pytest.skip("No validation function available")
try:
result = func(url)
except Exception:
result = False
assert isinstance(bool(result), bool)

Xet Storage Details

Size:
2.42 kB
·
Xet hash:
fe666d0e6c0422481961e0dc2d2c17d617302fc5648107be02bf0b8788a5368b

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