test: update tests for multi-language translation support

- Update marketplace_product_fixtures to create translations
- Update test_marketplace_product.py for translation-based titles
- Update test_product.py for effective property tests
- Update test_order.py to use get_title() method
- Add comprehensive CSV processor tests for translations
- Update stats service tests for new flat response structure
- Fix product schema tests with required marketplace_product_id field
- Add helper function create_marketplace_product_with_translation()

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

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-11 17:29:50 +01:00
parent 22c4937779
commit 2ecc2a9785
8 changed files with 790 additions and 201 deletions

View File

@@ -2,7 +2,10 @@
"""
Marketplace product test fixtures.
Note: Fixtures should NOT use db.expunge() as it breaks lazy loading.
Note: Since title/description are now in translations table,
we create the translation alongside the marketplace product.
Fixtures should NOT use db.expunge() as it breaks lazy loading.
See tests/conftest.py for details on fixture best practices.
"""
import uuid
@@ -10,12 +13,42 @@ import uuid
import pytest
from models.database.marketplace_product import MarketplaceProduct
from models.database.marketplace_product_translation import MarketplaceProductTranslation
def _create_marketplace_product_with_translation(
db,
marketplace_product_id: str,
title: str,
description: str | None = None,
**kwargs,
) -> MarketplaceProduct:
"""Helper to create a MarketplaceProduct with its English translation."""
marketplace_product = MarketplaceProduct(
marketplace_product_id=marketplace_product_id,
**kwargs,
)
db.add(marketplace_product)
db.flush() # Get the ID
# Create the English translation
translation = MarketplaceProductTranslation(
marketplace_product_id=marketplace_product.id,
language="en",
title=title,
description=description,
)
db.add(translation)
db.commit()
db.refresh(marketplace_product)
return marketplace_product
@pytest.fixture
def test_marketplace_product(db):
"""Create a test product."""
marketplace_product = MarketplaceProduct(
"""Create a test product with translation."""
return _create_marketplace_product_with_translation(
db,
marketplace_product_id="TEST001",
title="Test MarketplaceProduct",
description="A test product",
@@ -27,17 +60,14 @@ def test_marketplace_product(db):
marketplace="Letzshop",
vendor_name="TestVendor",
)
db.add(marketplace_product)
db.commit()
db.refresh(marketplace_product)
return marketplace_product
@pytest.fixture
def unique_product(db):
"""Create a unique product for tests that need isolated product data."""
unique_id = str(uuid.uuid4())[:8]
marketplace_product = MarketplaceProduct(
return _create_marketplace_product_with_translation(
db,
marketplace_product_id=f"UNIQUE_{unique_id}",
title=f"Unique MarketplaceProduct {unique_id}",
description=f"A unique test product {unique_id}",
@@ -50,10 +80,6 @@ def unique_product(db):
vendor_name=f"UniqueVendor_{unique_id}",
google_product_category=f"UniqueCategory_{unique_id}",
)
db.add(marketplace_product)
db.commit()
db.refresh(marketplace_product)
return marketplace_product
@pytest.fixture
@@ -63,7 +89,8 @@ def multiple_products(db):
marketplace_products = []
for i in range(5):
marketplace_product = MarketplaceProduct(
marketplace_product = _create_marketplace_product_with_translation(
db,
marketplace_product_id=f"MULTI_{unique_id}_{i}",
title=f"Multi MarketplaceProduct {i} {unique_id}",
description=f"Multi test product {i}",
@@ -77,33 +104,30 @@ def multiple_products(db):
)
marketplace_products.append(marketplace_product)
db.add_all(marketplace_products)
db.commit()
for product in marketplace_products:
db.refresh(product)
return marketplace_products
def create_unique_marketplace_product_factory():
"""Factory function to create unique products in tests."""
def _marketplace_create_product(db, **kwargs):
def _marketplace_create_product(db, title: str | None = None, **kwargs):
unique_id = str(uuid.uuid4())[:8]
defaults = {
"marketplace_product_id": f"FACTORY_{unique_id}",
"title": f"Factory MarketplaceProduct {unique_id}",
"price": "15.99",
"currency": "EUR",
"marketplace": "TestMarket",
"name": "TestVendor",
"vendor_name": "TestVendor",
}
defaults.update(kwargs)
marketplace_product = MarketplaceProduct(**defaults)
db.add(marketplace_product)
db.commit()
db.refresh(marketplace_product)
return marketplace_product
title = title or f"Factory MarketplaceProduct {unique_id}"
return _create_marketplace_product_with_translation(
db,
title=title,
**defaults,
)
return _marketplace_create_product