marketplace refactoring
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
# tests/unit/models/test_database_models.py
|
||||
import pytest
|
||||
|
||||
from models.database.product import Product
|
||||
from models.database.marketplace_product import MarketplaceProduct
|
||||
from models.database.shop import Shop
|
||||
from models.database.stock import Stock
|
||||
from models.database.user import User
|
||||
@@ -30,10 +30,10 @@ class TestDatabaseModels:
|
||||
assert user.updated_at is not None
|
||||
|
||||
def test_product_model(self, db):
|
||||
"""Test Product model creation"""
|
||||
product = Product(
|
||||
product_id="DB_TEST_001",
|
||||
title="Database Test Product",
|
||||
"""Test MarketplaceProduct model creation"""
|
||||
marketplace_product = MarketplaceProduct(
|
||||
marketplace_product_id="DB_TEST_001",
|
||||
title="Database Test MarketplaceProduct",
|
||||
description="Testing product model",
|
||||
price="25.99",
|
||||
currency="USD",
|
||||
@@ -44,13 +44,13 @@ class TestDatabaseModels:
|
||||
shop_name="DBTestShop",
|
||||
)
|
||||
|
||||
db.add(product)
|
||||
db.add(marketplace_product)
|
||||
db.commit()
|
||||
db.refresh(product)
|
||||
db.refresh(marketplace_product)
|
||||
|
||||
assert product.id is not None
|
||||
assert product.product_id == "DB_TEST_001"
|
||||
assert product.created_at is not None
|
||||
assert marketplace_product.id is not None
|
||||
assert marketplace_product.marketplace_product_id == "DB_TEST_001"
|
||||
assert marketplace_product.created_at is not None
|
||||
|
||||
def test_stock_model(self, db):
|
||||
"""Test Stock model creation"""
|
||||
@@ -87,13 +87,13 @@ class TestDatabaseModels:
|
||||
|
||||
def test_database_constraints(self, db):
|
||||
"""Test database constraints and unique indexes"""
|
||||
# Test unique product_id constraint
|
||||
product1 = Product(product_id="UNIQUE_001", title="Product 1")
|
||||
# Test unique marketplace_product_id constraint
|
||||
product1 = MarketplaceProduct(marketplace_product_id="UNIQUE_001", title="MarketplaceProduct 1")
|
||||
db.add(product1)
|
||||
db.commit()
|
||||
|
||||
# This should raise an integrity error
|
||||
with pytest.raises(Exception): # Could be IntegrityError or similar
|
||||
product2 = Product(product_id="UNIQUE_001", title="Product 2")
|
||||
product2 = MarketplaceProduct(marketplace_product_id="UNIQUE_001", title="MarketplaceProduct 2")
|
||||
db.add(product2)
|
||||
db.commit()
|
||||
|
||||
Reference in New Issue
Block a user