Tests restructuring
This commit is contained in:
108
tests/fixtures/product_fixtures.py
vendored
Normal file
108
tests/fixtures/product_fixtures.py
vendored
Normal file
@@ -0,0 +1,108 @@
|
||||
# tests/fixtures/product_fixtures.py
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from models.database_models import Product
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_product(db):
|
||||
"""Create a test product"""
|
||||
product = Product(
|
||||
product_id="TEST001",
|
||||
title="Test Product",
|
||||
description="A test product",
|
||||
price="10.99",
|
||||
currency="EUR",
|
||||
brand="TestBrand",
|
||||
gtin="1234567890123",
|
||||
availability="in stock",
|
||||
marketplace="Letzshop",
|
||||
shop_name="TestShop",
|
||||
)
|
||||
db.add(product)
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
return 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}",
|
||||
description=f"A unique test product {unique_id}",
|
||||
price="19.99",
|
||||
currency="EUR",
|
||||
brand=f"UniqueBrand_{unique_id}",
|
||||
gtin=f"123456789{unique_id[:4]}",
|
||||
availability="in stock",
|
||||
marketplace="Letzshop",
|
||||
shop_name=f"UniqueShop_{unique_id}",
|
||||
google_product_category=f"UniqueCategory_{unique_id}",
|
||||
)
|
||||
db.add(product)
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
return product
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def multiple_products(db):
|
||||
"""Create multiple products for testing statistics and pagination"""
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
products = []
|
||||
|
||||
for i in range(5):
|
||||
product = Product(
|
||||
product_id=f"MULTI_{unique_id}_{i}",
|
||||
title=f"Multi Product {i} {unique_id}",
|
||||
description=f"Multi test product {i}",
|
||||
price=f"{10 + i}.99",
|
||||
currency="EUR",
|
||||
brand=f"MultiBrand_{i % 3}", # Create 3 different brands
|
||||
marketplace=f"MultiMarket_{i % 2}", # Create 2 different marketplaces
|
||||
shop_name=f"MultiShop_{i}",
|
||||
google_product_category=f"MultiCategory_{i % 2}", # Create 2 different categories
|
||||
gtin=f"1234567890{i}{unique_id[:2]}",
|
||||
)
|
||||
products.append(product)
|
||||
|
||||
db.add_all(products)
|
||||
db.commit()
|
||||
for product in products:
|
||||
db.refresh(product)
|
||||
return products
|
||||
|
||||
|
||||
def create_unique_product_factory():
|
||||
"""Factory function to create unique products in tests"""
|
||||
|
||||
def _create_product(db, **kwargs):
|
||||
unique_id = str(uuid.uuid4())[:8]
|
||||
defaults = {
|
||||
"product_id": f"FACTORY_{unique_id}",
|
||||
"title": f"Factory Product {unique_id}",
|
||||
"price": "15.99",
|
||||
"currency": "EUR",
|
||||
"marketplace": "TestMarket",
|
||||
"shop_name": "TestShop",
|
||||
}
|
||||
defaults.update(kwargs)
|
||||
|
||||
product = Product(**defaults)
|
||||
db.add(product)
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
return product
|
||||
|
||||
return _create_product
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def product_factory():
|
||||
"""Fixture that provides a product factory function"""
|
||||
return create_unique_product_factory()
|
||||
Reference in New Issue
Block a user