refactor: move letzshop endpoints to marketplace module and add vendor service tests

Move letzshop-related functionality from tenancy to marketplace module:
- Move admin letzshop routes to marketplace/routes/api/admin_letzshop.py
- Move letzshop schemas to marketplace/schemas/letzshop.py
- Remove letzshop code from tenancy module (admin_vendors, vendor_service)
- Update model exports and imports

Add comprehensive unit tests for vendor services:
- test_company_service.py: Company management operations
- test_platform_service.py: Platform management operations
- test_vendor_domain_service.py: Vendor domain operations
- test_vendor_team_service.py: Vendor team management

Update module definitions:
- billing, messaging, payments: Minor definition updates

Add architecture proposals documentation:
- Module dependency redesign session notes
- Decouple modules implementation plan
- Module decoupling proposal

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 19:25:00 +01:00
parent 37942ae02b
commit 0583dd2cc4
29 changed files with 3643 additions and 650 deletions

View File

@@ -1,5 +1,9 @@
# tests/unit/services/test_vendor_service.py
"""Unit tests for VendorService following the application's exception patterns."""
"""Unit tests for VendorService following the application's exception patterns.
Note: Product catalog operations (add_product_to_catalog, get_products) have been
moved to app.modules.catalog.services. See test_product_service.py for those tests.
"""
import uuid
@@ -12,12 +16,9 @@ from app.modules.tenancy.exceptions import (
VendorAlreadyExistsException,
VendorNotFoundException,
)
from app.modules.marketplace.exceptions import MarketplaceProductNotFoundException
from app.modules.catalog.exceptions import ProductAlreadyExistsException
from app.modules.tenancy.services.vendor_service import VendorService
from app.modules.tenancy.models import Company
from app.modules.tenancy.models import Vendor
from app.modules.catalog.schemas import ProductCreate
from app.modules.tenancy.schemas.vendor import VendorCreate
@@ -354,98 +355,8 @@ class TestVendorService:
assert vendor.is_active is False
# ==================== add_product_to_catalog Tests ====================
def test_add_product_to_vendor_success(self, db, test_vendor, unique_product):
"""Test successfully adding product to vendor."""
from app.modules.marketplace.models import MarketplaceProduct
# Re-query objects to avoid session issues
vendor = db.query(Vendor).filter(Vendor.id == test_vendor.id).first()
mp = (
db.query(MarketplaceProduct)
.filter(MarketplaceProduct.id == unique_product.id)
.first()
)
product_data = ProductCreate(
marketplace_product_id=mp.id,
price=15.99,
is_featured=True,
)
product = self.service.add_product_to_catalog(db, vendor, product_data)
db.commit()
assert product is not None
assert product.vendor_id == vendor.id
assert product.marketplace_product_id == mp.id
def test_add_product_to_vendor_product_not_found(self, db, test_vendor):
"""Test adding non-existent product to vendor fails."""
product_data = ProductCreate(
marketplace_product_id=99999, # Non-existent ID
price=15.99,
)
with pytest.raises(MarketplaceProductNotFoundException) as exc_info:
self.service.add_product_to_catalog(db, test_vendor, product_data)
exception = exc_info.value
assert exception.status_code == 404
assert exception.error_code == "PRODUCT_NOT_FOUND"
def test_add_product_to_vendor_already_exists(self, db, test_vendor, test_product):
"""Test adding product that's already in vendor fails."""
# Re-query to get fresh instances
from app.modules.catalog.models import Product
vendor = db.query(Vendor).filter(Vendor.id == test_vendor.id).first()
product = db.query(Product).filter(Product.id == test_product.id).first()
product_data = ProductCreate(
marketplace_product_id=product.marketplace_product_id,
price=15.99,
)
with pytest.raises(ProductAlreadyExistsException) as exc_info:
self.service.add_product_to_catalog(db, vendor, product_data)
exception = exc_info.value
assert exception.status_code == 409
assert exception.error_code == "PRODUCT_ALREADY_EXISTS"
# ==================== get_products Tests ====================
def test_get_products_owner_access(self, db, test_user, test_vendor, test_product):
"""Test vendor owner can get vendor products."""
# Re-query vendor to get fresh instance
vendor = db.query(Vendor).filter(Vendor.id == test_vendor.id).first()
products, total = self.service.get_products(db, vendor, test_user)
assert total >= 1
assert len(products) >= 1
def test_get_products_access_denied(self, db, test_user, inactive_vendor):
"""Test non-owner cannot access unverified vendor products."""
# Re-query vendor to get fresh instance
vendor = db.query(Vendor).filter(Vendor.id == inactive_vendor.id).first()
with pytest.raises(UnauthorizedVendorAccessException) as exc_info:
self.service.get_products(db, vendor, test_user)
exception = exc_info.value
assert exception.status_code == 403
assert exception.error_code == "UNAUTHORIZED_VENDOR_ACCESS"
def test_get_products_with_filters(self, db, test_user, test_vendor, test_product):
"""Test getting vendor products with various filters."""
# Re-query vendor to get fresh instance
vendor = db.query(Vendor).filter(Vendor.id == test_vendor.id).first()
# Test active only filter
products, total = self.service.get_products(
db, vendor, test_user, active_only=True
)
assert all(p.is_active for p in products)
# NOTE: add_product_to_catalog and get_products tests have been moved to
# test_product_service.py since those methods are now in the catalog module.
# ==================== Helper Method Tests ====================