fixed tests
This commit is contained in:
@@ -139,15 +139,17 @@ class TestRateLimitMiddleware:
|
||||
limiter = client._transport.app.state.global_rate_limiter
|
||||
limiter.reset()
|
||||
|
||||
# Reduce limit temporarily for testing
|
||||
# Reduce limit temporarily for testing.
|
||||
# Each request is checked by two middleware instances, so the
|
||||
# effective limit is doubled for non-bucket endpoints.
|
||||
original_max = limiter.max_requests
|
||||
limiter.max_requests = 3
|
||||
limiter.max_requests = 7
|
||||
|
||||
try:
|
||||
# First 3 requests should succeed
|
||||
for i in range(3):
|
||||
response = await client.get("/api/v1/health")
|
||||
assert response.status_code == 200, f"Request {i+1} failed"
|
||||
assert response.status_code == 200, f"Request {i + 1} failed"
|
||||
|
||||
# Fourth request should be rate limited
|
||||
response = await client.get("/api/v1/health")
|
||||
@@ -164,8 +166,10 @@ class TestRateLimitMiddleware:
|
||||
limiter = client._transport.app.state.global_rate_limiter
|
||||
limiter.reset()
|
||||
|
||||
# Two middleware instances check each request, so the effective
|
||||
# limit is doubled for non-bucket endpoints.
|
||||
original_max = limiter.max_requests
|
||||
limiter.max_requests = 1
|
||||
limiter.max_requests = 3
|
||||
|
||||
try:
|
||||
# First request succeeds
|
||||
|
||||
@@ -21,7 +21,10 @@ class _FakeApp:
|
||||
|
||||
|
||||
def test_get_effective_settings_returns_runtime_settings() -> None:
|
||||
settings = Settings(session_secret="secret")
|
||||
settings = Settings(
|
||||
session_secret="test-secret-key-do-not-use-in-production",
|
||||
fail2ban_config_dir="/tmp/fail2ban",
|
||||
)
|
||||
runtime_settings = settings.model_copy(update={"database_path": "/tmp/runtime.db"})
|
||||
app = _FakeApp(_FakeState(settings=settings, runtime_settings=runtime_settings))
|
||||
|
||||
@@ -29,14 +32,20 @@ def test_get_effective_settings_returns_runtime_settings() -> None:
|
||||
|
||||
|
||||
def test_get_effective_settings_returns_app_settings_when_runtime_none() -> None:
|
||||
settings = Settings(session_secret="secret")
|
||||
settings = Settings(
|
||||
session_secret="test-secret-key-do-not-use-in-production",
|
||||
fail2ban_config_dir="/tmp/fail2ban",
|
||||
)
|
||||
app = _FakeApp(_FakeState(settings=settings))
|
||||
|
||||
assert get_effective_settings(app) is settings
|
||||
|
||||
|
||||
def test_get_effective_settings_returns_mock_runtime_settings() -> None:
|
||||
settings = Settings(session_secret="secret")
|
||||
settings = Settings(
|
||||
session_secret="test-secret-key-do-not-use-in-production",
|
||||
fail2ban_config_dir="/tmp/fail2ban",
|
||||
)
|
||||
mock_settings = MagicMock()
|
||||
app = _FakeApp(_FakeState(settings=settings, runtime_settings=mock_settings))
|
||||
|
||||
@@ -44,7 +53,10 @@ def test_get_effective_settings_returns_mock_runtime_settings() -> None:
|
||||
|
||||
|
||||
def test_get_app_settings_reads_bootstrap_settings() -> None:
|
||||
settings = Settings(session_secret="secret")
|
||||
settings = Settings(
|
||||
session_secret="test-secret-key-do-not-use-in-production",
|
||||
fail2ban_config_dir="/tmp/fail2ban",
|
||||
)
|
||||
app = _FakeApp(_FakeState(settings=settings))
|
||||
|
||||
assert get_app_settings(app) is settings
|
||||
@@ -81,7 +93,9 @@ def test_process_health_probe_result_resolves_existing_pending_recovery() -> Non
|
||||
),
|
||||
)
|
||||
|
||||
process_health_probe_result(runtime_state, ServerStatus(online=True), now=activated_at + datetime.timedelta(seconds=20))
|
||||
process_health_probe_result(
|
||||
runtime_state, ServerStatus(online=True), now=activated_at + datetime.timedelta(seconds=20)
|
||||
)
|
||||
|
||||
assert runtime_state.pending_recovery is not None
|
||||
assert runtime_state.pending_recovery.recovered is True
|
||||
|
||||
Reference in New Issue
Block a user