marketplace refactoring

This commit is contained in:
2025-10-04 13:38:10 +02:00
parent 32be301d83
commit c971674ec2
68 changed files with 1102 additions and 1128 deletions

View File

@@ -1,11 +1,11 @@
# tests/fixtures/marketplace_fixtures.py
# tests/fixtures/marketplace_import_job_fixtures.py
import pytest
from models.database.marketplace import MarketplaceImportJob
from models.database.marketplace_import_job import MarketplaceImportJob
@pytest.fixture
def test_marketplace_job(db, test_shop, test_user):
def test_marketplace_import_job(db, test_shop, test_user):
"""Create a test marketplace import job"""
job = MarketplaceImportJob(
marketplace="amazon",
@@ -26,7 +26,7 @@ def test_marketplace_job(db, test_shop, test_user):
return job
def create_test_import_job(db, shop_id, user_id, **kwargs):
def create_test_marketplace_import_job(db, shop_id, user_id, **kwargs):
"""Helper function to create MarketplaceImportJob with defaults"""
defaults = {
"marketplace": "test",

View File

@@ -1,17 +1,17 @@
# tests/fixtures/product_fixtures.py
# tests/fixtures/marketplace_product_fixtures.py
import uuid
import pytest
from models.database.product import Product
from models.database.marketplace_product import MarketplaceProduct
@pytest.fixture
def test_product(db):
def test_marketplace_product(db):
"""Create a test product"""
product = Product(
product_id="TEST001",
title="Test Product",
marketplace_product = MarketplaceProduct(
marketplace_product_id="TEST001",
title="Test MarketplaceProduct",
description="A test product",
price="10.99",
currency="EUR",
@@ -21,19 +21,19 @@ def test_product(db):
marketplace="Letzshop",
shop_name="TestShop",
)
db.add(product)
db.add(marketplace_product)
db.commit()
db.refresh(product)
return product
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]
product = Product(
product_id=f"UNIQUE_{unique_id}",
title=f"Unique Product {unique_id}",
marketplace_product = MarketplaceProduct(
marketplace_product_id=f"UNIQUE_{unique_id}",
title=f"Unique MarketplaceProduct {unique_id}",
description=f"A unique test product {unique_id}",
price="19.99",
currency="EUR",
@@ -44,22 +44,22 @@ def unique_product(db):
shop_name=f"UniqueShop_{unique_id}",
google_product_category=f"UniqueCategory_{unique_id}",
)
db.add(product)
db.add(marketplace_product)
db.commit()
db.refresh(product)
return product
db.refresh(marketplace_product)
return marketplace_product
@pytest.fixture
def multiple_products(db):
"""Create multiple products for testing statistics and pagination"""
unique_id = str(uuid.uuid4())[:8]
products = []
marketplace_products = []
for i in range(5):
product = Product(
product_id=f"MULTI_{unique_id}_{i}",
title=f"Multi Product {i} {unique_id}",
marketplace_product = MarketplaceProduct(
marketplace_product_id=f"MULTI_{unique_id}_{i}",
title=f"Multi MarketplaceProduct {i} {unique_id}",
description=f"Multi test product {i}",
price=f"{10 + i}.99",
currency="EUR",
@@ -69,23 +69,23 @@ def multiple_products(db):
google_product_category=f"MultiCategory_{i % 2}", # Create 2 different categories
gtin=f"1234567890{i}{unique_id[:2]}",
)
products.append(product)
marketplace_products.append(marketplace_product)
db.add_all(products)
db.add_all(marketplace_products)
db.commit()
for product in products:
for product in marketplace_products:
db.refresh(product)
return products
return marketplace_products
def create_unique_product_factory():
def create_unique_marketplace_product_factory():
"""Factory function to create unique products in tests"""
def _create_product(db, **kwargs):
def _marketplace_create_product(db, **kwargs):
unique_id = str(uuid.uuid4())[:8]
defaults = {
"product_id": f"FACTORY_{unique_id}",
"title": f"Factory Product {unique_id}",
"marketplace_product_id": f"FACTORY_{unique_id}",
"title": f"Factory MarketplaceProduct {unique_id}",
"price": "15.99",
"currency": "EUR",
"marketplace": "TestMarket",
@@ -93,31 +93,31 @@ def create_unique_product_factory():
}
defaults.update(kwargs)
product = Product(**defaults)
db.add(product)
marketplace_product = MarketplaceProduct(**defaults)
db.add(marketplace_product)
db.commit()
db.refresh(product)
return product
db.refresh(marketplace_product)
return marketplace_product
return _create_product
return _marketplace_create_product
@pytest.fixture
def product_factory():
def marketplace_product_factory():
"""Fixture that provides a product factory function"""
return create_unique_product_factory()
return create_unique_marketplace_product_factory()
@pytest.fixture
def test_product_with_stock(db, test_product, test_stock):
"""Product with associated stock record."""
def test_marketplace_product_with_stock(db, test_marketplace_product, test_stock):
"""MarketplaceProduct with associated stock record."""
# Ensure they're linked by GTIN
if test_product.gtin != test_stock.gtin:
test_stock.gtin = test_product.gtin
if test_marketplace_product.gtin != test_stock.gtin:
test_stock.gtin = test_marketplace_product.gtin
db.commit()
db.refresh(test_stock)
return {
'product': test_product,
'marketplace_product': test_marketplace_product,
'stock': test_stock
}

View File

@@ -80,7 +80,7 @@ def verified_shop(db, other_user):
def shop_product(db, test_shop, unique_product):
"""Create a shop product relationship"""
shop_product = ShopProduct(
shop_id=test_shop.id, product_id=unique_product.id, is_active=True
shop_id=test_shop.id, marketplace_product_id=unique_product.id, is_active=True
)
# Add optional fields if they exist in your model
if hasattr(ShopProduct, "shop_price"):
@@ -97,11 +97,11 @@ def shop_product(db, test_shop, unique_product):
@pytest.fixture
def test_stock(db, test_product, test_shop):
def test_stock(db, test_marketplace_product, test_shop):
"""Create test stock entry"""
unique_id = str(uuid.uuid4())[:8].upper() # Short unique identifier
stock = Stock(
gtin=test_product.gtin, # Use gtin instead of product_id
gtin=test_marketplace_product.gtin, # Use gtin instead of marketplace_product_id
location=f"WAREHOUSE_A_{unique_id}",
quantity=10,
reserved_quantity=0,