Transform CMS from a thin wrapper into a fully self-contained module with all code living within app/modules/cms/: Module Structure: - models/: ContentPage model (canonical location with dynamic discovery) - schemas/: Pydantic schemas for API validation - services/: ContentPageService business logic - exceptions/: Module-specific exceptions - routes/api/: REST API endpoints (admin, vendor, shop) - routes/pages/: HTML page routes (admin, vendor) - templates/cms/: Jinja2 templates (namespaced) - static/: JavaScript files (admin/vendor) - locales/: i18n translations (en, fr, de, lb) Key Changes: - Move ContentPage model to module with dynamic model discovery - Create Pydantic schemas package for request/response validation - Extract API routes from app/api/v1/*/ to module - Extract page routes from admin_pages.py/vendor_pages.py to module - Move static JS files to module with dedicated mount point - Update templates to use cms_static for module assets - Add module static file mounting in main.py - Delete old scattered files (no shims - hard errors on old imports) This establishes the pattern for migrating other modules to be fully autonomous and independently deployable. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
237 lines
6.0 KiB
Python
237 lines
6.0 KiB
Python
# tests/fixtures/content_page_fixtures.py
|
|
"""
|
|
Content page test fixtures.
|
|
|
|
Note: Fixtures should NOT use db.expunge() as it breaks lazy loading.
|
|
See tests/conftest.py for details on fixture best practices.
|
|
"""
|
|
|
|
import uuid
|
|
|
|
import pytest
|
|
|
|
from app.modules.cms.models import ContentPage
|
|
|
|
|
|
@pytest.fixture
|
|
def platform_about_page(db):
|
|
"""Create a platform-level About page (vendor_id=NULL)."""
|
|
page = ContentPage(
|
|
vendor_id=None,
|
|
slug="about",
|
|
title="About Us",
|
|
content="<h1>About Our Platform</h1><p>Welcome to our platform.</p>",
|
|
content_format="html",
|
|
meta_description="Learn about our platform",
|
|
is_published=True,
|
|
show_in_footer=True,
|
|
show_in_header=True,
|
|
show_in_legal=False,
|
|
display_order=1,
|
|
)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def platform_faq_page(db):
|
|
"""Create a platform-level FAQ page (vendor_id=NULL)."""
|
|
page = ContentPage(
|
|
vendor_id=None,
|
|
slug="faq",
|
|
title="Frequently Asked Questions",
|
|
content="<h1>FAQ</h1><p>Common questions answered.</p>",
|
|
content_format="html",
|
|
meta_description="Frequently asked questions",
|
|
is_published=True,
|
|
show_in_footer=True,
|
|
show_in_header=False,
|
|
show_in_legal=False,
|
|
display_order=2,
|
|
)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def platform_privacy_page(db):
|
|
"""Create a platform-level Privacy Policy page for legal section."""
|
|
page = ContentPage(
|
|
vendor_id=None,
|
|
slug="privacy",
|
|
title="Privacy Policy",
|
|
content="<h1>Privacy Policy</h1><p>Your data is important to us.</p>",
|
|
content_format="html",
|
|
meta_description="Our privacy policy",
|
|
is_published=True,
|
|
show_in_footer=False,
|
|
show_in_header=False,
|
|
show_in_legal=True,
|
|
display_order=1,
|
|
)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def platform_terms_page(db):
|
|
"""Create a platform-level Terms of Service page for legal section."""
|
|
page = ContentPage(
|
|
vendor_id=None,
|
|
slug="terms",
|
|
title="Terms of Service",
|
|
content="<h1>Terms of Service</h1><p>By using our platform...</p>",
|
|
content_format="html",
|
|
meta_description="Our terms of service",
|
|
is_published=True,
|
|
show_in_footer=False,
|
|
show_in_header=False,
|
|
show_in_legal=True,
|
|
display_order=2,
|
|
)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def platform_contact_page(db):
|
|
"""Create a platform-level Contact page."""
|
|
page = ContentPage(
|
|
vendor_id=None,
|
|
slug="contact",
|
|
title="Contact Us",
|
|
content="<h1>Contact</h1><p>Get in touch.</p>",
|
|
content_format="html",
|
|
meta_description="Contact us",
|
|
is_published=True,
|
|
show_in_footer=True,
|
|
show_in_header=True,
|
|
show_in_legal=False,
|
|
display_order=3,
|
|
)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def platform_draft_page(db):
|
|
"""Create an unpublished platform page (draft)."""
|
|
page = ContentPage(
|
|
vendor_id=None,
|
|
slug="draft-page",
|
|
title="Draft Page",
|
|
content="<h1>Draft</h1><p>This is a draft.</p>",
|
|
content_format="html",
|
|
is_published=False,
|
|
show_in_footer=True,
|
|
show_in_header=False,
|
|
show_in_legal=False,
|
|
display_order=99,
|
|
)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def vendor_about_page(db, test_vendor):
|
|
"""Create a vendor-specific About page override."""
|
|
page = ContentPage(
|
|
vendor_id=test_vendor.id,
|
|
slug="about",
|
|
title="About Our Shop",
|
|
content="<h1>About Our Shop</h1><p>Welcome to our shop.</p>",
|
|
content_format="html",
|
|
meta_description="Learn about our shop",
|
|
is_published=True,
|
|
show_in_footer=True,
|
|
show_in_header=True,
|
|
show_in_legal=False,
|
|
display_order=1,
|
|
)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def vendor_shipping_page(db, test_vendor):
|
|
"""Create a vendor-specific Shipping page (no platform default)."""
|
|
page = ContentPage(
|
|
vendor_id=test_vendor.id,
|
|
slug="shipping",
|
|
title="Shipping Information",
|
|
content="<h1>Shipping</h1><p>We ship to Luxembourg.</p>",
|
|
content_format="html",
|
|
meta_description="Shipping info",
|
|
is_published=True,
|
|
show_in_footer=True,
|
|
show_in_header=False,
|
|
show_in_legal=False,
|
|
display_order=4,
|
|
)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
|
|
@pytest.fixture
|
|
def all_platform_pages(
|
|
db,
|
|
platform_about_page,
|
|
platform_faq_page,
|
|
platform_privacy_page,
|
|
platform_terms_page,
|
|
platform_contact_page,
|
|
):
|
|
"""Create all platform pages for comprehensive testing."""
|
|
return [
|
|
platform_about_page,
|
|
platform_faq_page,
|
|
platform_privacy_page,
|
|
platform_terms_page,
|
|
platform_contact_page,
|
|
]
|
|
|
|
|
|
@pytest.fixture
|
|
def content_page_factory():
|
|
"""Factory function to create content pages in tests."""
|
|
|
|
def _create_page(db, vendor_id=None, **kwargs):
|
|
unique_id = str(uuid.uuid4())[:8]
|
|
defaults = {
|
|
"vendor_id": vendor_id,
|
|
"slug": f"page-{unique_id}",
|
|
"title": f"Test Page {unique_id}",
|
|
"content": f"<p>Content for {unique_id}</p>",
|
|
"content_format": "html",
|
|
"is_published": True,
|
|
"show_in_footer": True,
|
|
"show_in_header": False,
|
|
"show_in_legal": False,
|
|
"display_order": 0,
|
|
}
|
|
defaults.update(kwargs)
|
|
|
|
page = ContentPage(**defaults)
|
|
db.add(page)
|
|
db.commit()
|
|
db.refresh(page)
|
|
return page
|
|
|
|
return _create_page
|