fix(tests): add main platform fixture to store dashboard tests
All checks were successful
All checks were successful
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:
@@ -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"""
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user