diff --git a/tests/loadtest/locustfile_rate_limiter_scale.py b/tests/loadtest/locustfile_rate_limiter_scale.py index 086f4dbfa1..1ad33d0309 100644 --- a/tests/loadtest/locustfile_rate_limiter_scale.py +++ b/tests/loadtest/locustfile_rate_limiter_scale.py @@ -287,7 +287,7 @@ def _scan_redis_pattern(pattern: str, timeout: int = 20) -> int: ["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "--scan", "--pattern", pattern], capture_output=True, text=True, - timeout=timeout, + timeout=timeout, check=False, ) if r.returncode != 0: return 0 @@ -322,7 +322,7 @@ def _scan_rl_sample_keys(dimension: str, timeout: int = 15) -> list[str]: ["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "--scan", "--pattern", pattern], capture_output=True, text=True, - timeout=timeout, + timeout=timeout, check=False, ) if r.returncode == 0: keys.extend(line.strip() for line in r.stdout.splitlines() if line.strip()) @@ -344,7 +344,7 @@ def _poll_redis_once() -> dict[str, Any] | None: ["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "DBSIZE"], capture_output=True, text=True, - timeout=5, + timeout=5, check=False, ) total_keys = int(r_dbsize.stdout.strip()) if r_dbsize.returncode == 0 else 0 @@ -358,7 +358,7 @@ def _poll_redis_once() -> dict[str, Any] | None: ["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "INFO", "memory"], capture_output=True, text=True, - timeout=5, + timeout=5, check=False, ) mem_bytes = 0 for line in r_mem.stdout.splitlines(): @@ -397,7 +397,7 @@ def _detect_algorithm_from_redis() -> str: ["docker", "exec", DOCKER_REDIS_CONTAINER, "redis-cli", "TYPE", sample_keys[0]], capture_output=True, text=True, - timeout=5, + timeout=5, check=False, ) key_type = r_type.stdout.strip().lower() @@ -831,10 +831,10 @@ def on_test_stop(environment, **kwargs): print(f" RL key delta: {delta_rl_keys:,} (baseline-subtracted)") if delta_rl_keys > 0: print(f" Mem per RL key: {per_key:.2f} KiB (delta_mem / delta_keys — same sample)") - print(f"\n Expected per-key cost by algorithm:") - print(f" fixed_window: ~0.1–0.3 KiB (single integer + TTL)") + print("\n Expected per-key cost by algorithm:") + print(" fixed_window: ~0.1–0.3 KiB (single integer + TTL)") print(f" sliding_window: ~1–3 KiB (sorted set, {RL_LIMIT_PER_MIN} float entries)") - print(f" token_bucket: ~0.2 KiB (hash: tokens + last_refill)") + print(" token_bucket: ~0.2 KiB (hash: tokens + last_refill)") if per_key < 0.5: verdict = "✅ consistent with fixed_window" elif per_key <= 5.0: @@ -845,7 +845,7 @@ def on_test_stop(environment, **kwargs): # Latency if total_http > 0: - print(f"\n Response Times (ms):") + print("\n Response Times (ms):") print(f" Average: {stats.total.avg_response_time:>8.1f}") print(f" p50: {stats.total.get_response_time_percentile(0.50):>8.1f}") print(f" p90: {stats.total.get_response_time_percentile(0.90):>8.1f}") diff --git a/tests/unit/mcpgateway/middleware/test_auth_middleware.py b/tests/unit/mcpgateway/middleware/test_auth_middleware.py index 1d68bd00fe..36cafa5f2b 100644 --- a/tests/unit/mcpgateway/middleware/test_auth_middleware.py +++ b/tests/unit/mcpgateway/middleware/test_auth_middleware.py @@ -74,6 +74,7 @@ async def test_invalid_referer_url_treated_as_api_request(): assert response.status_code == 401 assert "Token has been revoked" in response.body.decode() + @pytest.mark.asyncio async def test_oauth_callback_referer_allows_browser_continuation(): """OAuth callback referer should be treated as same-origin and allow browser request to continue.""" diff --git a/tests/unit/mcpgateway/middleware/test_password_change_enforcement.py b/tests/unit/mcpgateway/middleware/test_password_change_enforcement.py index 6b03a6cbb2..a0c82fc43d 100644 --- a/tests/unit/mcpgateway/middleware/test_password_change_enforcement.py +++ b/tests/unit/mcpgateway/middleware/test_password_change_enforcement.py @@ -7,13 +7,11 @@ """ # Standard -from unittest.mock import AsyncMock, MagicMock, patch +from unittest.mock import MagicMock, patch # Third-Party import pytest from fastapi import FastAPI, Request -from fastapi.responses import JSONResponse, RedirectResponse -from starlette.middleware.base import BaseHTTPMiddleware # First-Party from mcpgateway.db import EmailUser diff --git a/tests/unit/mcpgateway/test_db.py b/tests/unit/mcpgateway/test_db.py index f04cda946c..74ee698095 100644 --- a/tests/unit/mcpgateway/test_db.py +++ b/tests/unit/mcpgateway/test_db.py @@ -14,7 +14,7 @@ from sqlalchemy.exc import SQLAlchemyError # First-Party -import mcpgateway.db as db +from mcpgateway import db # --- utc_now --- @@ -2114,7 +2114,6 @@ def __exit__(self, exc_type, exc, tb): def test_refresh_slugs_on_startup_outer_sqlalchemy_error(monkeypatch, caplog): # Third-Party - from sqlalchemy.exc import SQLAlchemyError class DummySession: def __enter__(self): @@ -2985,7 +2984,7 @@ def test_email_api_token_is_expired_none(): def test_db_tool_title_property(test_db): - import mcpgateway.db as db + from mcpgateway import db tool = db.Tool( id="tool-1", @@ -3007,7 +3006,7 @@ def test_db_tool_title_property(test_db): def test_db_resource_title_property(test_db): - import mcpgateway.db as db + from mcpgateway import db resource = db.Resource( id="resource-1", @@ -3026,7 +3025,7 @@ def test_db_resource_title_property(test_db): def test_db_prompt_title_property(test_db): - import mcpgateway.db as db + from mcpgateway import db prompt = db.Prompt( id="prompt-1", diff --git a/tests/unit/mcpgateway/test_observability.py b/tests/unit/mcpgateway/test_observability.py index fdddea924a..417c4957f1 100644 --- a/tests/unit/mcpgateway/test_observability.py +++ b/tests/unit/mcpgateway/test_observability.py @@ -7,8 +7,6 @@ """ # Standard -import importlib -import inspect import os from unittest.mock import MagicMock, patch @@ -19,18 +17,12 @@ from mcpgateway import observability from mcpgateway.config import get_settings from mcpgateway.observability import ( - BaggageSpanAttributePolicy, configure_baggage_span_attribute_policy, - OpenTelemetryRequestMiddleware, - create_span, - extract_baggage_span_attribute_policy, inject_trace_context_headers, init_telemetry, otel_context_active, otel_tracing_enabled, - trace_operation, ) -from mcpgateway.utils.trace_context import clear_trace_context, set_trace_context_from_teams, set_trace_session_id class TestObservability: diff --git a/tests/unit/mcpgateway/test_translate_helpers.py b/tests/unit/mcpgateway/test_translate_helpers.py index f6f3428990..601a62b0fe 100644 --- a/tests/unit/mcpgateway/test_translate_helpers.py +++ b/tests/unit/mcpgateway/test_translate_helpers.py @@ -7,11 +7,9 @@ """ # Standard -from types import SimpleNamespace # Third-Party from fastapi import FastAPI -from fastapi.responses import HTMLResponse import pytest from unittest.mock import AsyncMock, MagicMock diff --git a/tests/unit/mcpgateway/utils/test_check_schema_at_head.py b/tests/unit/mcpgateway/utils/test_check_schema_at_head.py index 3ff21ab9d3..75c3a5d068 100644 --- a/tests/unit/mcpgateway/utils/test_check_schema_at_head.py +++ b/tests/unit/mcpgateway/utils/test_check_schema_at_head.py @@ -29,7 +29,7 @@ from unittest.mock import MagicMock, Mock, patch # First-Party -import mcpgateway.utils.check_schema_at_head as check_schema_at_head +from mcpgateway.utils import check_schema_at_head def _build_mock_engine_with_connect(): diff --git a/tests/unit/plugins/test_unified_pdp.py b/tests/unit/plugins/test_unified_pdp.py index 9cb97cc04b..8bcf63198f 100644 --- a/tests/unit/plugins/test_unified_pdp.py +++ b/tests/unit/plugins/test_unified_pdp.py @@ -17,8 +17,6 @@ from __future__ import annotations import pytest -import httpx -from unittest.mock import AsyncMock, patch # --------------------------------------------------------------------------- # Adjust imports – works whether you run from repo root or this directory @@ -46,8 +44,8 @@ from plugins.unified_pdp.engines.cedar_engine import CedarEngineAdapter from plugins.unified_pdp.engines.native_engine import NativeRBACAdapter from plugins.unified_pdp.engines.mac_engine import MACEngineAdapter -from plugins.unified_pdp.cache import DecisionCache, _build_cache_key -from plugins.unified_pdp.adapter import PolicyEvaluationError, PolicyEngineUnavailableError +from plugins.unified_pdp.cache import DecisionCache +from plugins.unified_pdp.adapter import PolicyEvaluationError # =========================================================================== # Fixtures