Add description field to Product model

Issue: The landing page template supported displaying product descriptions,
but the Product model didn't load the description field from config.yaml files.

Changes:
- Added optional 'description' parameter to Product.__init__()
- Updated Product.to_dict() to include description (if present)
- Updated Product.from_dict() to load description from config
- Added test to verify descriptions are displayed on landing page

All 9 landing page tests passing.

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-17 15:32:20 +02:00
co-authored by Claude
parent bbeacb0748
commit 13051200a6
2 changed files with 40 additions and 3 deletions
+9 -3
View File
@@ -14,16 +14,18 @@ class Product:
owner_language: Preferred language for product owner owner_language: Preferred language for product owner
assigned_owner_ids: List of product owner user IDs assigned_owner_ids: List of product owner user IDs
status: Product status ('active' or 'archived') status: Product status ('active' or 'archived')
description: Optional product description for landing page
""" """
def __init__(self, product_id, name, submission_url_slug, owner_language, def __init__(self, product_id, name, submission_url_slug, owner_language,
assigned_owner_ids, status='active'): assigned_owner_ids, status='active', description=None):
self.product_id = product_id self.product_id = product_id
self.name = name self.name = name
self.submission_url_slug = submission_url_slug self.submission_url_slug = submission_url_slug
self.owner_language = owner_language self.owner_language = owner_language
self.assigned_owner_ids = assigned_owner_ids or [] self.assigned_owner_ids = assigned_owner_ids or []
self.status = status self.status = status
self.description = description
def to_dict(self): def to_dict(self):
"""Convert product to dictionary """Convert product to dictionary
@@ -31,7 +33,7 @@ class Product:
Returns: Returns:
dict: Product data dict: Product data
""" """
return { data = {
'product_id': self.product_id, 'product_id': self.product_id,
'name': self.name, 'name': self.name,
'submission_url_slug': self.submission_url_slug, 'submission_url_slug': self.submission_url_slug,
@@ -39,6 +41,9 @@ class Product:
'assigned_owner_ids': self.assigned_owner_ids, 'assigned_owner_ids': self.assigned_owner_ids,
'status': self.status 'status': self.status
} }
if self.description:
data['description'] = self.description
return data
@classmethod @classmethod
def from_dict(cls, data): def from_dict(cls, data):
@@ -56,7 +61,8 @@ class Product:
submission_url_slug=data['submission_url_slug'], submission_url_slug=data['submission_url_slug'],
owner_language=data['owner_language'], owner_language=data['owner_language'],
assigned_owner_ids=data.get('assigned_owner_ids', []), assigned_owner_ids=data.get('assigned_owner_ids', []),
status=data.get('status', 'active') status=data.get('status', 'active'),
description=data.get('description')
) )
@staticmethod @staticmethod
+31
View File
@@ -180,3 +180,34 @@ def test_landing_page_with_authenticated_user_renders_correctly(client, test_pro
# Should contain products (proving the page rendered successfully) # Should contain products (proving the page rendered successfully)
assert b'Apple Product' in response.data assert b'Apple Product' in response.data
assert b'Zebra Product' in response.data assert b'Zebra Product' in response.data
@pytest.mark.contract
def test_landing_page_displays_product_descriptions(client, test_products):
"""Test that product descriptions from config.yaml are displayed on landing page
This test verifies that when a product has a description field in its config.yaml,
that description is properly loaded by the Product model and displayed on the landing page.
"""
response = client.get('/')
assert response.status_code == 200
# Zebra Product has a description in the fixture
assert b'Zebra Product' in response.data
assert b'A product for testing' in response.data
# Apple Product has no description - should not show any placeholder
assert b'Apple Product' in response.data
# No description text should appear for Apple Product
html = response.data.decode('utf-8')
# Verify Zebra description is present
assert 'A product for testing' in html
# Verify the description appears between the product name and the submit button
zebra_section_start = html.find('Zebra Product')
zebra_section_end = html.find('Submit Feedback', zebra_section_start)
zebra_section = html[zebra_section_start:zebra_section_end]
assert 'A product for testing' in zebra_section