feat: complete modular platform architecture (Phases 1-5)
Phase 1 - Vendor Router Integration: - Wire up vendor module routers in app/api/v1/vendor/__init__.py - Use lazy imports via __getattr__ to avoid circular dependencies Phase 2 - Extract Remaining Modules: - Create 6 new module directories: customers, cms, analytics, messaging, dev_tools, monitoring - Each module has definition.py and route wrappers - Update registry to import from extracted modules Phase 3 - Database Table Migration: - Add PlatformModule junction table for auditable module tracking - Add migration zc2m3n4o5p6q7_add_platform_modules_table.py - Add modules relationship to Platform model - Update ModuleService with JSON-to-junction-table migration Phase 4 - Module-Specific Configuration UI: - Add /api/v1/admin/module-config/* endpoints - Add module-config.html template and JS Phase 5 - Integration Tests: - Add tests/fixtures/module_fixtures.py - Add tests/integration/api/v1/admin/test_modules.py - Add tests/integration/api/v1/modules/test_module_access.py Architecture fixes: - Fix JS-003 errors: use ...data() directly in Alpine components - Fix JS-005 warnings: add init() guards to prevent duplicate init - Fix API-001 errors: add MenuActionResponse Pydantic model - Add FE-008 noqa for dynamic number input in template Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
159
tests/fixtures/module_fixtures.py
vendored
Normal file
159
tests/fixtures/module_fixtures.py
vendored
Normal file
@@ -0,0 +1,159 @@
|
||||
# tests/fixtures/module_fixtures.py
|
||||
"""
|
||||
Module system test fixtures.
|
||||
|
||||
Provides fixtures for testing platform module enablement, configuration,
|
||||
and access control.
|
||||
"""
|
||||
|
||||
import uuid
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import pytest
|
||||
|
||||
from models.database.platform import Platform
|
||||
from models.database.platform_module import PlatformModule
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platform_with_modules(db, test_super_admin):
|
||||
"""Create a test platform with specific modules enabled."""
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
platform = Platform(
|
||||
code=f"modtest_{unique_id}",
|
||||
name=f"Module Test Platform {unique_id}",
|
||||
description="A test platform with module configuration",
|
||||
path_prefix=f"modtest{unique_id}",
|
||||
is_active=True,
|
||||
is_public=True,
|
||||
default_language="en",
|
||||
supported_languages=["en", "fr"],
|
||||
)
|
||||
db.add(platform)
|
||||
db.flush()
|
||||
|
||||
# Enable specific modules via junction table
|
||||
enabled_modules = ["billing", "inventory", "orders"]
|
||||
for module_code in enabled_modules:
|
||||
pm = PlatformModule(
|
||||
platform_id=platform.id,
|
||||
module_code=module_code,
|
||||
is_enabled=True,
|
||||
enabled_at=datetime.now(timezone.utc),
|
||||
enabled_by_user_id=test_super_admin.id,
|
||||
config={},
|
||||
)
|
||||
db.add(pm)
|
||||
|
||||
# Add a disabled module
|
||||
pm_disabled = PlatformModule(
|
||||
platform_id=platform.id,
|
||||
module_code="marketplace",
|
||||
is_enabled=False,
|
||||
disabled_at=datetime.now(timezone.utc),
|
||||
disabled_by_user_id=test_super_admin.id,
|
||||
config={},
|
||||
)
|
||||
db.add(pm_disabled)
|
||||
|
||||
db.commit()
|
||||
db.refresh(platform)
|
||||
return platform
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platform_with_config(db, test_super_admin):
|
||||
"""Create a test platform with module configuration."""
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
platform = Platform(
|
||||
code=f"cfgtest_{unique_id}",
|
||||
name=f"Config Test Platform {unique_id}",
|
||||
description="A test platform with module config",
|
||||
path_prefix=f"cfgtest{unique_id}",
|
||||
is_active=True,
|
||||
is_public=True,
|
||||
default_language="en",
|
||||
supported_languages=["en"],
|
||||
)
|
||||
db.add(platform)
|
||||
db.flush()
|
||||
|
||||
# Add module with configuration
|
||||
pm = PlatformModule(
|
||||
platform_id=platform.id,
|
||||
module_code="billing",
|
||||
is_enabled=True,
|
||||
enabled_at=datetime.now(timezone.utc),
|
||||
enabled_by_user_id=test_super_admin.id,
|
||||
config={
|
||||
"stripe_mode": "test",
|
||||
"default_trial_days": 30,
|
||||
"allow_free_tier": True,
|
||||
},
|
||||
)
|
||||
db.add(pm)
|
||||
|
||||
# Add inventory module with config
|
||||
pm_inv = PlatformModule(
|
||||
platform_id=platform.id,
|
||||
module_code="inventory",
|
||||
is_enabled=True,
|
||||
enabled_at=datetime.now(timezone.utc),
|
||||
enabled_by_user_id=test_super_admin.id,
|
||||
config={
|
||||
"low_stock_threshold": 5,
|
||||
"enable_locations": True,
|
||||
},
|
||||
)
|
||||
db.add(pm_inv)
|
||||
|
||||
db.commit()
|
||||
db.refresh(platform)
|
||||
return platform
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def platform_all_modules_disabled(db, test_super_admin):
|
||||
"""Create a test platform with all optional modules disabled."""
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
platform = Platform(
|
||||
code=f"nomod_{unique_id}",
|
||||
name=f"No Modules Platform {unique_id}",
|
||||
description="A test platform with minimal modules",
|
||||
path_prefix=f"nomod{unique_id}",
|
||||
is_active=True,
|
||||
is_public=True,
|
||||
default_language="en",
|
||||
supported_languages=["en"],
|
||||
settings={"enabled_modules": []}, # Legacy format for testing
|
||||
)
|
||||
db.add(platform)
|
||||
db.commit()
|
||||
db.refresh(platform)
|
||||
return platform
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def module_factory(db, test_super_admin):
|
||||
"""Factory for creating PlatformModule records."""
|
||||
def _create_module(
|
||||
platform_id: int,
|
||||
module_code: str,
|
||||
is_enabled: bool = True,
|
||||
config: dict | None = None,
|
||||
):
|
||||
pm = PlatformModule(
|
||||
platform_id=platform_id,
|
||||
module_code=module_code,
|
||||
is_enabled=is_enabled,
|
||||
enabled_at=datetime.now(timezone.utc) if is_enabled else None,
|
||||
enabled_by_user_id=test_super_admin.id if is_enabled else None,
|
||||
disabled_at=None if is_enabled else datetime.now(timezone.utc),
|
||||
disabled_by_user_id=None if is_enabled else test_super_admin.id,
|
||||
config=config or {},
|
||||
)
|
||||
db.add(pm)
|
||||
db.commit()
|
||||
db.refresh(pm)
|
||||
return pm
|
||||
return _create_module
|
||||
Reference in New Issue
Block a user