fix(tests): add main platform fixture to store dashboard tests
All checks were successful
CI / ruff (push) Successful in 11s
CI / pytest (push) Successful in 49m59s
CI / validate (push) Successful in 24s
CI / dependency-scanning (push) Successful in 30s
CI / docs (push) Successful in 44s
CI / deploy (push) Successful in 1m2s

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 <noreply@anthropic.com>
This commit is contained in:
2026-03-05 17:28:46 +01:00
parent c4e9e4e646
commit cb9a829684

View File

@@ -11,10 +11,36 @@ Tests cover:
import pytest 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.integration
@pytest.mark.api @pytest.mark.api
@pytest.mark.store @pytest.mark.store
@pytest.mark.usefixtures("_ensure_main_platform")
class TestStoreDashboardAPI: class TestStoreDashboardAPI:
"""Test store dashboard stats endpoint""" """Test store dashboard stats endpoint"""