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

@@ -7,7 +7,7 @@ from app.exceptions import (
ShopAlreadyExistsException,
UnauthorizedShopAccessException,
InvalidShopDataException,
ProductNotFoundException,
MarketplaceProductNotFoundException,
ShopProductAlreadyExistsException,
MaxShopsReachedException,
ValidationException,
@@ -179,7 +179,7 @@ class TestShopService:
def test_add_product_to_shop_success(self, db, test_shop, unique_product):
"""Test successfully adding product to shop"""
shop_product_data = ShopProductCreate(
product_id=unique_product.product_id,
marketplace_product_id=unique_product.marketplace_product_id,
price="15.99",
is_featured=True,
stock_quantity=5,
@@ -191,25 +191,25 @@ class TestShopService:
assert shop_product is not None
assert shop_product.shop_id == test_shop.id
assert shop_product.product_id == unique_product.id
assert shop_product.marketplace_product_id == unique_product.id
def test_add_product_to_shop_product_not_found(self, db, test_shop):
"""Test adding non-existent product to shop fails"""
shop_product_data = ShopProductCreate(product_id="NONEXISTENT", price="15.99")
shop_product_data = ShopProductCreate(marketplace_product_id="NONEXISTENT", price="15.99")
with pytest.raises(ProductNotFoundException) as exc_info:
with pytest.raises(MarketplaceProductNotFoundException) as exc_info:
self.service.add_product_to_shop(db, test_shop, shop_product_data)
exception = exc_info.value
assert exception.status_code == 404
assert exception.error_code == "PRODUCT_NOT_FOUND"
assert exception.details["resource_type"] == "Product"
assert exception.details["resource_type"] == "MarketplaceProduct"
assert exception.details["identifier"] == "NONEXISTENT"
def test_add_product_to_shop_already_exists(self, db, test_shop, shop_product):
"""Test adding product that's already in shop fails"""
shop_product_data = ShopProductCreate(
product_id=shop_product.product.product_id, price="15.99"
marketplace_product_id=shop_product.product.marketplace_product_id, price="15.99"
)
with pytest.raises(ShopProductAlreadyExistsException) as exc_info:
@@ -219,7 +219,7 @@ class TestShopService:
assert exception.status_code == 409
assert exception.error_code == "SHOP_PRODUCT_ALREADY_EXISTS"
assert exception.details["shop_code"] == test_shop.shop_code
assert exception.details["product_id"] == shop_product.product.product_id
assert exception.details["marketplace_product_id"] == shop_product.product.marketplace_product_id
def test_get_shop_products_owner_access(
self, db, test_user, test_shop, shop_product
@@ -229,8 +229,8 @@ class TestShopService:
assert total >= 1
assert len(products) >= 1
product_ids = [p.product_id for p in products]
assert shop_product.product_id in product_ids
product_ids = [p.marketplace_product_id for p in products]
assert shop_product.marketplace_product_id in product_ids
def test_get_shop_products_access_denied(self, db, test_user, inactive_shop):
"""Test non-owner cannot access unverified shop products"""
@@ -300,7 +300,7 @@ class TestShopService:
monkeypatch.setattr(db, "commit", mock_commit)
shop_product_data = ShopProductCreate(
product_id=unique_product.product_id, price="15.99"
marketplace_product_id=unique_product.marketplace_product_id, price="15.99"
)
with pytest.raises(ValidationException) as exc_info: