major refactoring adding vendor and customer features

This commit is contained in:
2025-10-11 09:09:25 +02:00
parent f569995883
commit dd16198276
126 changed files with 15109 additions and 3747 deletions

View File

@@ -1,28 +1,28 @@
# tests/fixtures/vendor_fixtures.py
import uuid
import pytest
from models.database.vendor import Vendor
from models.database.product import Product
from models.database.stock import Stock
from models.database.inventory import Inventory
@pytest.fixture
def test_vendor(db, test_user):
"""Create a test vendor with unique vendor code"""
unique_id = str(uuid.uuid4())[:8].upper() # Make unique ID uppercase
unique_id = str(uuid.uuid4())[:8].upper()
vendor = Vendor(
vendor_code=f"TESTVENDOR_{unique_id}", # Will be all uppercase
vendor_name=f"Test Vendor {unique_id.lower()}", # Keep display name readable
owner_id=test_user.id,
vendor_code=f"TESTVENDOR_{unique_id}",
subdomain=f"testvendor{unique_id.lower()}", # ADDED
name=f"Test Vendor {unique_id.lower()}", # FIXED
owner_user_id=test_user.id,
is_active=True,
is_verified=True,
)
db.add(vendor)
db.commit()
db.refresh(vendor)
return vendor
return vendor
@pytest.fixture
@@ -30,17 +30,18 @@ def unique_vendor(db, test_user):
"""Create a unique vendor for tests that need isolated vendor data"""
unique_id = str(uuid.uuid4())[:8]
vendor = Vendor(
vendor_code=f"UNIQUEVENDOR_{unique_id}",
vendor_name=f"Unique Test Vendor {unique_id}",
vendor_code=f"UNIQUEVENDOR_{unique_id.upper()}",
subdomain=f"uniquevendor{unique_id.lower()}", # ADDED
name=f"Unique Test Vendor {unique_id}", # FIXED
description=f"A unique test vendor {unique_id}",
owner_id=test_user.id,
owner_user_id=test_user.id,
is_active=True,
is_verified=True,
)
db.add(vendor)
db.commit()
db.refresh(vendor)
return vendor
return vendor
@pytest.fixture
@@ -48,16 +49,17 @@ def inactive_vendor(db, other_user):
"""Create an inactive vendor owned by other_user"""
unique_id = str(uuid.uuid4())[:8]
vendor = Vendor(
vendor_code=f"INACTIVE_{unique_id}",
vendor_name=f"Inactive Vendor {unique_id}",
owner_id=other_user.id,
vendor_code=f"INACTIVE_{unique_id.upper()}",
subdomain=f"inactive{unique_id.lower()}", # ADDED
name=f"Inactive Vendor {unique_id}", # FIXED
owner_user_id=other_user.id,
is_active=False,
is_verified=False,
)
db.add(vendor)
db.commit()
db.refresh(vendor)
return vendor
return vendor
@pytest.fixture
@@ -65,32 +67,30 @@ def verified_vendor(db, other_user):
"""Create a verified vendor owned by other_user"""
unique_id = str(uuid.uuid4())[:8]
vendor = Vendor(
vendor_code=f"VERIFIED_{unique_id}",
vendor_name=f"Verified Vendor {unique_id}",
owner_id=other_user.id,
vendor_code=f"VERIFIED_{unique_id.upper()}",
subdomain=f"verified{unique_id.lower()}", # ADDED
name=f"Verified Vendor {unique_id}", # FIXED
owner_user_id=other_user.id,
is_active=True,
is_verified=True,
)
db.add(vendor)
db.commit()
db.refresh(vendor)
return vendor
return vendor
@pytest.fixture
def test_product(db, test_vendor, unique_product):
"""Create a vendor product relationship"""
product = Product(
vendor_id=test_vendor.id, marketplace_product_id=unique_product.id, is_active=True
vendor_id=test_vendor.id,
marketplace_product_id=unique_product.id,
is_active=True,
price=24.99,
is_featured=False,
min_quantity=1,
)
# Add optional fields if they exist in your model
if hasattr(Product, "price"):
product.price = 24.99
if hasattr(Product, "is_featured"):
product.is_featured = False
if hasattr(Product, "min_quantity"):
product.min_quantity = 1
db.add(product)
db.commit()
db.refresh(product)
@@ -98,53 +98,54 @@ def test_product(db, test_vendor, unique_product):
@pytest.fixture
def test_stock(db, test_marketplace_product, test_vendor):
"""Create test stock entry"""
unique_id = str(uuid.uuid4())[:8].upper() # Short unique identifier
stock = Stock(
gtin=test_marketplace_product.gtin, # Use gtin instead of marketplace_product_id
@pytest.fixture
def test_inventory(db, test_product):
"""Create test inventory entry linked to product."""
unique_id = str(uuid.uuid4())[:8].upper()
inventory = Inventory(
product_id=test_product.id,
vendor_id=test_product.vendor_id,
location=f"WAREHOUSE_A_{unique_id}",
quantity=10,
reserved_quantity=0,
vendor_id=test_vendor.id, # Add vendor_id reference
quantity=100,
reserved_quantity=10,
gtin=test_product.marketplace_product.gtin, # Optional reference
)
db.add(stock)
db.add(inventory)
db.commit()
db.refresh(stock)
return stock
db.refresh(inventory)
return inventory
@pytest.fixture
def multiple_stocks(db, multiple_products, test_vendor):
"""Create multiple stock entries for testing"""
stocks = []
def multiple_inventory_entries(db, multiple_products, test_vendor):
"""Create multiple inventory entries for testing"""
inventory_entries = []
for i, product in enumerate(multiple_products):
stock = Stock(
inventory = Inventory(
gtin=product.gtin,
location=f"LOC_{i}",
quantity=10 + (i * 5), # Different quantities
quantity=10 + (i * 5),
reserved_quantity=i,
vendor_id=test_vendor.id,
)
stocks.append(stock)
inventory_entries.append(inventory)
db.add_all(stocks)
db.add_all(inventory_entries)
db.commit()
for stock in stocks:
db.refresh(stock)
return stocks
for inventory in inventory_entries:
db.refresh(inventory)
return inventory_entries
def create_unique_vendor_factory():
"""Factory function to create unique vendors in tests"""
def _create_vendor(db, owner_id, **kwargs):
def _create_vendor(db, owner_user_id, **kwargs):
unique_id = str(uuid.uuid4())[:8]
defaults = {
"vendor_code": f"FACTORY_{unique_id}",
"vendor_name": f"Factory Vendor {unique_id}",
"owner_id": owner_id,
"vendor_code": f"FACTORY_{unique_id.upper()}",
"subdomain": f"factory{unique_id.lower()}", # ADDED
"name": f"Factory Vendor {unique_id}", # FIXED
"owner_user_id": owner_user_id,
"is_active": True,
"is_verified": False,
}
@@ -154,7 +155,7 @@ def create_unique_vendor_factory():
db.add(vendor)
db.commit()
db.refresh(vendor)
return vendor
return vendor
return _create_vendor