From 4c73b00eb2710eb33f25690f749c061bb9bbfc49 Mon Sep 17 00:00:00 2001 From: "Gan, Jimmy" Date: Mon, 6 Apr 2026 21:47:34 +0800 Subject: [PATCH] fix: disable rate limiting in tests by mocking Limiter --- dashboard/backend/tests/conftest.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/dashboard/backend/tests/conftest.py b/dashboard/backend/tests/conftest.py index 06a0698..bff00c6 100644 --- a/dashboard/backend/tests/conftest.py +++ b/dashboard/backend/tests/conftest.py @@ -147,11 +147,14 @@ def test_app(mock_config, temp_auth_file, temp_rbac_file, mock_docker_client): """Create FastAPI test client with mocked dependencies.""" # Patch Docker client before importing main with patch("docker.DockerClient", return_value=mock_docker_client): - from main import app - # Disable rate limiting during tests to avoid 429 errors - app.state.limiter.enabled = False - client = TestClient(app) - yield client + # Mock the limiter to disable rate limiting during tests + mock_limiter = Mock() + mock_limiter.limit = lambda *args, **kwargs: lambda func: func + + with patch("slowapi.Limiter", return_value=mock_limiter): + from main import app + client = TestClient(app) + yield client @pytest.fixture