# 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 (store_id=NULL).""" page = ContentPage( store_id=None, slug="about", title="About Us", content="

About Our Platform

Welcome to our platform.

", 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 (store_id=NULL).""" page = ContentPage( store_id=None, slug="faq", title="Frequently Asked Questions", content="

FAQ

Common questions answered.

", 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( store_id=None, slug="privacy", title="Privacy Policy", content="

Privacy Policy

Your data is important to us.

", 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( store_id=None, slug="terms", title="Terms of Service", content="

Terms of Service

By using our platform...

", 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( store_id=None, slug="contact", title="Contact Us", content="

Contact

Get in touch.

", 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( store_id=None, slug="draft-page", title="Draft Page", content="

Draft

This is a draft.

", 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 store_about_page(db, test_store): """Create a store-specific About page override.""" page = ContentPage( store_id=test_store.id, slug="about", title="About Our Shop", content="

About Our Shop

Welcome to our shop.

", 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 store_shipping_page(db, test_store): """Create a store-specific Shipping page (no platform default).""" page = ContentPage( store_id=test_store.id, slug="shipping", title="Shipping Information", content="

Shipping

We ship to Luxembourg.

", 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, store_id=None, **kwargs): unique_id = str(uuid.uuid4())[:8] defaults = { "store_id": store_id, "slug": f"page-{unique_id}", "title": f"Test Page {unique_id}", "content": f"

Content for {unique_id}

", "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