Files
orion/tests/fixtures/content_page_fixtures.py
Samir Boulahtit 592a4fd7c2 feat: add show_in_legal to admin content page editor
- Add "Show in Legal" checkbox to content page editor UI
- Update API schemas (ContentPageCreate, ContentPageUpdate, ContentPageResponse)
- Add show_in_legal parameter to service methods (create_page, update_page, etc.)
- Fix ContentPageNotFoundException to pass identifier correctly
- Fix UnauthorizedContentPageAccessException to use correct AuthorizationException API
- Add comprehensive unit tests for ContentPageService (35 tests)
- Add content page fixtures for testing
- Update CMS documentation with navigation categories diagram

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 20:27:20 +01:00

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 models.database.content_page 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