|
| 1 | +""" |
| 2 | +Pytest configuration for Content Generation backend tests. |
| 3 | +
|
| 4 | +Adds content-gen/src/backend to sys.path so that imports like |
| 5 | +``from services.title_service import TitleService`` resolve correctly |
| 6 | +when pytest is invoked by the CI workflow from the repo root: |
| 7 | +
|
| 8 | + pytest ./content-gen/src/tests |
| 9 | +""" |
| 10 | + |
| 11 | +import sys |
| 12 | +import os |
| 13 | +import asyncio |
| 14 | + |
| 15 | +# ---- environment setup (BEFORE any backend imports) ----------------------- |
| 16 | +# The settings module reads env-vars at import time via pydantic-settings. |
| 17 | +# Set minimal dummy values so that the module can be imported in CI where |
| 18 | +# no .env file or Azure resources exist. |
| 19 | +os.environ.setdefault("AZURE_OPENAI_ENDPOINT", "https://test.openai.azure.com") |
| 20 | +os.environ.setdefault("AZURE_OPENAI_RESOURCE", "test-resource") |
| 21 | +os.environ.setdefault("AZURE_COSMOS_ENDPOINT", "https://test.documents.azure.com:443/") |
| 22 | +os.environ.setdefault("AZURE_COSMOSDB_DATABASE", "test-db") |
| 23 | +os.environ.setdefault("AZURE_COSMOSDB_ACCOUNT", "test-account") |
| 24 | +os.environ.setdefault("AZURE_COSMOSDB_CONVERSATIONS_CONTAINER", "conversations") |
| 25 | +os.environ.setdefault("DOTENV_PATH", "") # prevent reading a real .env file |
| 26 | + |
| 27 | +import pytest # noqa: E402 (must come after env setup) |
| 28 | + |
| 29 | +# ---- path setup ---------------------------------------------------------- |
| 30 | +# The backend package lives at <repo>/content-gen/src/backend. |
| 31 | +# We add <repo>/content-gen/src/backend so that ``import settings``, |
| 32 | +# ``import services.…``, ``import models``, etc. resolve correctly. |
| 33 | +_THIS_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 34 | +_SRC_DIR = os.path.dirname(_THIS_DIR) # content-gen/src |
| 35 | +_BACKEND_DIR = os.path.join(_SRC_DIR, "backend") # content-gen/src/backend |
| 36 | + |
| 37 | +for _p in (_SRC_DIR, _BACKEND_DIR): |
| 38 | + if _p not in sys.path: |
| 39 | + sys.path.insert(0, _p) |
| 40 | + |
| 41 | + |
| 42 | +# ---- fixtures ------------------------------------------------------------- |
| 43 | + |
| 44 | +@pytest.fixture(scope="session") |
| 45 | +def event_loop(): |
| 46 | + """Create an instance of the default event loop for each test session.""" |
| 47 | + loop = asyncio.get_event_loop_policy().new_event_loop() |
| 48 | + yield loop |
| 49 | + loop.close() |
| 50 | + |
| 51 | + |
| 52 | +@pytest.fixture |
| 53 | +def sample_creative_brief(): |
| 54 | + """Sample creative brief for testing.""" |
| 55 | + return { |
| 56 | + "overview": "Summer Sale 2024 Campaign", |
| 57 | + "objectives": "Increase online sales by 25% during the summer season", |
| 58 | + "target_audience": "Young professionals aged 25-40 interested in premium electronics", |
| 59 | + "key_message": "Experience premium quality at unbeatable summer prices", |
| 60 | + "tone_and_style": "Upbeat, modern, and aspirational", |
| 61 | + "deliverable": "Social media carousel posts and email banners", |
| 62 | + "timelines": "Campaign runs June 1 - August 31, 2024", |
| 63 | + "visual_guidelines": "Use bright summer colors, outdoor settings, lifestyle imagery", |
| 64 | + "cta": "Shop Now", |
| 65 | + } |
| 66 | + |
| 67 | + |
| 68 | +@pytest.fixture |
| 69 | +def sample_product(): |
| 70 | + """Sample product for testing.""" |
| 71 | + return { |
| 72 | + "product_name": "ProMax Wireless Headphones", |
| 73 | + "category": "Electronics", |
| 74 | + "sub_category": "Audio", |
| 75 | + "marketing_description": "Immerse yourself in crystal-clear sound with our flagship wireless headphones.", |
| 76 | + "detailed_spec_description": "40mm custom drivers, Active Noise Cancellation, 30-hour battery life, Bluetooth 5.2, USB-C fast charging", |
| 77 | + "sku": "PM-WH-001", |
| 78 | + "model": "ProMax-2024", |
| 79 | + "image_url": "https://example.com/images/headphones.jpg", |
| 80 | + "image_description": "Sleek over-ear headphones in matte black with silver accents", |
| 81 | + } |
0 commit comments