From cb9a829684021617f8e9022382c002363c92cf6a Mon Sep 17 00:00:00 2001 From: Samir Boulahtit Date: Thu, 5 Mar 2026 17:28:46 +0100 Subject: [PATCH] fix(tests): add main platform fixture to store dashboard tests The store dashboard endpoint uses require_platform which needs the PlatformContextMiddleware to resolve a platform. TestClient uses 'testserver' as Host, which the middleware maps to the 'main' platform. Added _ensure_main_platform fixture to create it in the test DB. Co-Authored-By: Claude Opus 4.6 --- .../api/v1/store/test_dashboard.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/integration/api/v1/store/test_dashboard.py b/tests/integration/api/v1/store/test_dashboard.py index 72b281ab..34554d77 100644 --- a/tests/integration/api/v1/store/test_dashboard.py +++ b/tests/integration/api/v1/store/test_dashboard.py @@ -11,10 +11,36 @@ Tests cover: import pytest +from app.modules.tenancy.models import Platform + + +@pytest.fixture +def _ensure_main_platform(db): + """Ensure a 'main' platform exists for the PlatformContextMiddleware. + + The TestClient uses 'testserver' as Host, which the middleware treats as + localhost and resolves to the 'main' platform via path_prefix lookup. + """ + platform = db.query(Platform).filter(Platform.code == "main").first() + if not platform: + platform = Platform( + code="main", + name="Main Platform", + path_prefix="main", + is_active=True, + is_public=True, + default_language="en", + supported_languages=["en"], + ) + db.add(platform) + db.commit() + return platform + @pytest.mark.integration @pytest.mark.api @pytest.mark.store +@pytest.mark.usefixtures("_ensure_main_platform") class TestStoreDashboardAPI: """Test store dashboard stats endpoint"""