fastmcp/tests/test_settings.py
asts a35b88bba3
fix(http): preserve the SDK's default session idle timeout (#5229)
Preserves the SDK session-expiry default while retaining explicit timeout and disable overrides; documented configuration and both supported SDK paths verified.

Fixes #5210

Co-authored-by: asts-top <1628948583@qq.com>
Co-authored-by: zzstoatzz <thrast36@gmail.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-04 21:08:54 -04:00

48 lines
1.5 KiB
Python

import pytest
from pydantic import ValidationError
from fastmcp.settings import Settings
def test_http_host_origin_protection_defaults_to_false():
assert Settings().http_host_origin_protection is False
@pytest.mark.parametrize(
("value", "expected"),
[
("auto", "auto"),
("true", True),
("false", False),
],
)
def test_http_host_origin_protection_env_var(value, expected, monkeypatch):
monkeypatch.setenv("FASTMCP_HTTP_HOST_ORIGIN_PROTECTION", value)
assert Settings().http_host_origin_protection == expected
def test_http_session_idle_timeout_defaults_to_auto():
assert Settings().http_session_idle_timeout == "auto"
@pytest.mark.parametrize("value", ["auto", "60", "0.5"])
def test_http_session_idle_timeout_env_var(value, monkeypatch):
monkeypatch.setenv("FASTMCP_HTTP_SESSION_IDLE_TIMEOUT", value)
expected = "auto" if value == "auto" else float(value)
assert Settings().http_session_idle_timeout == expected
def test_http_session_idle_timeout_can_be_disabled():
assert Settings(http_session_idle_timeout=None).http_session_idle_timeout is None
def test_http_session_idle_timeout_env_var_none_disables(monkeypatch):
monkeypatch.setenv("FASTMCP_HTTP_SESSION_IDLE_TIMEOUT", "none")
assert Settings().http_session_idle_timeout is None
@pytest.mark.parametrize("value", [0, -1, "invalid"])
def test_http_session_idle_timeout_rejects_invalid_values(value):
with pytest.raises(ValidationError):
Settings(http_session_idle_timeout=value)