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:
@@ -16,7 +16,7 @@ class TestProductModel:
|
||||
product = Product(
|
||||
vendor_id=test_vendor.id,
|
||||
marketplace_product_id=test_marketplace_product.id,
|
||||
product_id="VENDOR_PROD_001",
|
||||
vendor_sku="VENDOR_PROD_001",
|
||||
price=89.99,
|
||||
currency="EUR",
|
||||
availability="in stock",
|
||||
@@ -34,7 +34,11 @@ class TestProductModel:
|
||||
assert product.price == 89.99
|
||||
assert product.is_featured is True
|
||||
assert product.vendor.vendor_code == test_vendor.vendor_code
|
||||
assert product.marketplace_product.title == test_marketplace_product.title
|
||||
# Use get_title() method instead of .title attribute
|
||||
assert (
|
||||
product.marketplace_product.get_title("en")
|
||||
== test_marketplace_product.get_title("en")
|
||||
)
|
||||
|
||||
def test_product_unique_per_vendor(self, db, test_vendor, test_marketplace_product):
|
||||
"""Test that same marketplace product can't be added twice to vendor catalog."""
|
||||
@@ -76,7 +80,7 @@ class TestProductModel:
|
||||
product = Product(
|
||||
vendor_id=test_vendor.id,
|
||||
marketplace_product_id=test_marketplace_product.id,
|
||||
product_id="CUSTOM_SKU_001",
|
||||
vendor_sku="CUSTOM_SKU_001",
|
||||
price=49.99,
|
||||
sale_price=39.99,
|
||||
currency="USD",
|
||||
@@ -87,7 +91,7 @@ class TestProductModel:
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
|
||||
assert product.product_id == "CUSTOM_SKU_001"
|
||||
assert product.vendor_sku == "CUSTOM_SKU_001"
|
||||
assert product.price == 49.99
|
||||
assert product.sale_price == 39.99
|
||||
assert product.currency == "USD"
|
||||
@@ -121,3 +125,99 @@ class TestProductModel:
|
||||
assert product.vendor is not None
|
||||
assert product.marketplace_product is not None
|
||||
assert product.inventory_entries == [] # No inventory yet
|
||||
|
||||
def test_product_effective_properties(self, db, test_vendor, test_marketplace_product):
|
||||
"""Test Product effective properties with override pattern."""
|
||||
# First, set some values on the marketplace product
|
||||
test_marketplace_product.price_numeric = 100.00
|
||||
test_marketplace_product.brand = "SourceBrand"
|
||||
db.commit()
|
||||
db.refresh(test_marketplace_product)
|
||||
|
||||
# Create product without overrides
|
||||
product = Product(
|
||||
vendor_id=test_vendor.id,
|
||||
marketplace_product_id=test_marketplace_product.id,
|
||||
)
|
||||
db.add(product)
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
|
||||
# Should inherit from marketplace product
|
||||
assert product.effective_price == 100.00
|
||||
assert product.effective_brand == "SourceBrand"
|
||||
|
||||
# Now override the price
|
||||
product.price = 89.99
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
|
||||
# Should use the override
|
||||
assert product.effective_price == 89.99
|
||||
# Brand still inherited
|
||||
assert product.effective_brand == "SourceBrand"
|
||||
|
||||
def test_product_reset_to_source(self, db, test_vendor, test_marketplace_product):
|
||||
"""Test reset_to_source methods."""
|
||||
# Set up marketplace product values
|
||||
test_marketplace_product.price_numeric = 100.00
|
||||
test_marketplace_product.brand = "SourceBrand"
|
||||
db.commit()
|
||||
|
||||
# Create product with overrides
|
||||
product = Product(
|
||||
vendor_id=test_vendor.id,
|
||||
marketplace_product_id=test_marketplace_product.id,
|
||||
price=89.99,
|
||||
brand="OverrideBrand",
|
||||
)
|
||||
db.add(product)
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
|
||||
assert product.effective_price == 89.99
|
||||
assert product.effective_brand == "OverrideBrand"
|
||||
|
||||
# Reset price to source
|
||||
product.reset_field_to_source("price")
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
|
||||
assert product.price is None
|
||||
assert product.effective_price == 100.00 # Now inherits
|
||||
|
||||
# Reset all fields
|
||||
product.reset_all_to_source()
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
|
||||
assert product.brand is None
|
||||
assert product.effective_brand == "SourceBrand" # Now inherits
|
||||
|
||||
def test_product_get_override_info(self, db, test_vendor, test_marketplace_product):
|
||||
"""Test get_override_info method."""
|
||||
test_marketplace_product.price_numeric = 100.00
|
||||
test_marketplace_product.brand = "SourceBrand"
|
||||
db.commit()
|
||||
|
||||
product = Product(
|
||||
vendor_id=test_vendor.id,
|
||||
marketplace_product_id=test_marketplace_product.id,
|
||||
price=89.99, # Override
|
||||
# brand not set - will inherit
|
||||
)
|
||||
db.add(product)
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
|
||||
info = product.get_override_info()
|
||||
|
||||
# Price is overridden
|
||||
assert info["price"] == 89.99
|
||||
assert info["price_overridden"] is True
|
||||
assert info["price_source"] == 100.00
|
||||
|
||||
# Brand is inherited
|
||||
assert info["brand"] == "SourceBrand"
|
||||
assert info["brand_overridden"] is False
|
||||
assert info["brand_source"] == "SourceBrand"
|
||||
|
||||
Reference in New Issue
Block a user