refactor: migrate templates and static files to self-contained modules
Templates Migration: - Migrate admin templates to modules (tenancy, billing, monitoring, marketplace, etc.) - Migrate vendor templates to modules (tenancy, billing, orders, messaging, etc.) - Migrate storefront templates to modules (catalog, customers, orders, cart, checkout, cms) - Migrate public templates to modules (billing, marketplace, cms) - Keep shared templates in app/templates/ (base.html, errors/, partials/, macros/) - Migrate letzshop partials to marketplace module Static Files Migration: - Migrate admin JS to modules: tenancy (23 files), core (5 files), monitoring (1 file) - Migrate vendor JS to modules: tenancy (4 files), core (2 files) - Migrate shared JS: vendor-selector.js to core, media-picker.js to cms - Migrate storefront JS: storefront-layout.js to core - Keep framework JS in static/ (api-client, utils, money, icons, log-config, lib/) - Update all template references to use module_static paths Naming Consistency: - Rename static/platform/ to static/public/ - Rename app/templates/platform/ to app/templates/public/ - Update all extends and static references Documentation: - Update module-system.md with shared templates documentation - Update frontend-structure.md with new module JS organization Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -19,7 +19,7 @@ import pytest
|
||||
from fastapi import HTTPException
|
||||
from jose import jwt
|
||||
|
||||
from app.exceptions import (
|
||||
from app.modules.tenancy.exceptions import (
|
||||
AdminRequiredException,
|
||||
InsufficientPermissionsException,
|
||||
InvalidCredentialsException,
|
||||
|
||||
@@ -17,7 +17,7 @@ import pytest
|
||||
from fastapi import Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.exceptions.vendor import VendorNotFoundException
|
||||
from app.modules.tenancy.exceptions import VendorNotFoundException
|
||||
from middleware.vendor_context import (
|
||||
VendorContextManager,
|
||||
VendorContextMiddleware,
|
||||
|
||||
@@ -7,8 +7,8 @@ from decimal import Decimal
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions.customer import CustomerNotFoundException
|
||||
from app.services.admin_customer_service import AdminCustomerService
|
||||
from app.modules.customers.exceptions import CustomerNotFoundException
|
||||
from app.modules.customers.services.admin_customer_service import AdminCustomerService
|
||||
from app.modules.customers.models.customer import Customer
|
||||
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ from datetime import datetime, timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.admin_notification_service import (
|
||||
from app.modules.messaging.services.admin_notification_service import (
|
||||
AdminNotificationService,
|
||||
AlertType,
|
||||
NotificationType,
|
||||
|
||||
@@ -7,8 +7,9 @@ Tests the admin platform assignment service operations.
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import AdminOperationException, CannotModifySelfException, ValidationException
|
||||
from app.services.admin_platform_service import AdminPlatformService
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.exceptions import AdminOperationException, CannotModifySelfException
|
||||
from app.modules.tenancy.services.admin_platform_service import AdminPlatformService
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
# tests/unit/services/test_admin_service.py
|
||||
import pytest
|
||||
|
||||
from app.exceptions import (
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.exceptions import (
|
||||
AdminOperationException,
|
||||
CannotModifySelfException,
|
||||
UserNotFoundException,
|
||||
UserStatusChangeException,
|
||||
ValidationException,
|
||||
VendorAlreadyExistsException,
|
||||
VendorNotFoundException,
|
||||
)
|
||||
from app.services.admin_service import AdminService
|
||||
from app.services.stats_service import stats_service
|
||||
from app.modules.tenancy.services.admin_service import AdminService
|
||||
from app.modules.analytics.services.stats_service import stats_service
|
||||
from models.schema.vendor import VendorCreate
|
||||
|
||||
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions.auth import (
|
||||
from app.modules.tenancy.exceptions import (
|
||||
InvalidCredentialsException,
|
||||
UserNotActiveException,
|
||||
)
|
||||
from app.services.auth_service import AuthService
|
||||
from app.modules.core.services.auth_service import AuthService
|
||||
from models.schema.auth import UserLogin
|
||||
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import VendorNotFoundException
|
||||
from app.services.billing_service import (
|
||||
from app.modules.tenancy.exceptions import VendorNotFoundException
|
||||
from app.modules.billing.services.billing_service import (
|
||||
BillingService,
|
||||
NoActiveSubscriptionError,
|
||||
PaymentSystemNotConfiguredError,
|
||||
@@ -107,7 +107,7 @@ class TestBillingServiceCheckout:
|
||||
"""Initialize service instance before each test."""
|
||||
self.service = BillingService()
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_create_checkout_session_stripe_not_configured(
|
||||
self, mock_stripe, db, test_vendor, test_subscription_tier
|
||||
):
|
||||
@@ -124,7 +124,7 @@ class TestBillingServiceCheckout:
|
||||
cancel_url="https://example.com/cancel",
|
||||
)
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_create_checkout_session_success(
|
||||
self, mock_stripe, db, test_vendor, test_subscription_tier_with_stripe
|
||||
):
|
||||
@@ -147,7 +147,7 @@ class TestBillingServiceCheckout:
|
||||
assert result["checkout_url"] == "https://checkout.stripe.com/test"
|
||||
assert result["session_id"] == "cs_test_123"
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_create_checkout_session_tier_not_found(
|
||||
self, mock_stripe, db, test_vendor
|
||||
):
|
||||
@@ -164,7 +164,7 @@ class TestBillingServiceCheckout:
|
||||
cancel_url="https://example.com/cancel",
|
||||
)
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_create_checkout_session_no_price(
|
||||
self, mock_stripe, db, test_vendor, test_subscription_tier
|
||||
):
|
||||
@@ -191,7 +191,7 @@ class TestBillingServicePortal:
|
||||
"""Initialize service instance before each test."""
|
||||
self.service = BillingService()
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_create_portal_session_stripe_not_configured(self, mock_stripe, db, test_vendor):
|
||||
"""Test portal fails when Stripe not configured."""
|
||||
mock_stripe.is_configured = False
|
||||
@@ -203,7 +203,7 @@ class TestBillingServicePortal:
|
||||
return_url="https://example.com/billing",
|
||||
)
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_create_portal_session_no_subscription(self, mock_stripe, db, test_vendor):
|
||||
"""Test portal fails when no subscription exists."""
|
||||
mock_stripe.is_configured = True
|
||||
@@ -215,7 +215,7 @@ class TestBillingServicePortal:
|
||||
return_url="https://example.com/billing",
|
||||
)
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_create_portal_session_success(
|
||||
self, mock_stripe, db, test_vendor, test_active_subscription
|
||||
):
|
||||
@@ -313,7 +313,7 @@ class TestBillingServiceCancellation:
|
||||
"""Initialize service instance before each test."""
|
||||
self.service = BillingService()
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_cancel_subscription_no_subscription(
|
||||
self, mock_stripe, db, test_vendor
|
||||
):
|
||||
@@ -328,7 +328,7 @@ class TestBillingServiceCancellation:
|
||||
immediately=False,
|
||||
)
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_cancel_subscription_success(
|
||||
self, mock_stripe, db, test_vendor, test_active_subscription
|
||||
):
|
||||
@@ -346,7 +346,7 @@ class TestBillingServiceCancellation:
|
||||
assert test_active_subscription.cancelled_at is not None
|
||||
assert test_active_subscription.cancellation_reason == "Too expensive"
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_reactivate_subscription_not_cancelled(
|
||||
self, mock_stripe, db, test_vendor, test_active_subscription
|
||||
):
|
||||
@@ -356,7 +356,7 @@ class TestBillingServiceCancellation:
|
||||
with pytest.raises(SubscriptionNotCancelledError):
|
||||
self.service.reactivate_subscription(db, test_vendor.id)
|
||||
|
||||
@patch("app.services.billing_service.stripe_service")
|
||||
@patch("app.modules.billing.services.billing_service.stripe_service")
|
||||
def test_reactivate_subscription_success(
|
||||
self, mock_stripe, db, test_vendor, test_cancelled_subscription
|
||||
):
|
||||
|
||||
@@ -15,7 +15,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.capacity_forecast_service import (
|
||||
from app.modules.billing.services.capacity_forecast_service import (
|
||||
INFRASTRUCTURE_SCALING,
|
||||
CapacityForecastService,
|
||||
capacity_forecast_service,
|
||||
|
||||
@@ -5,8 +5,8 @@ Unit tests for CustomerAddressService.
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import AddressLimitExceededException, AddressNotFoundException
|
||||
from app.services.customer_address_service import CustomerAddressService
|
||||
from app.modules.customers.exceptions import AddressLimitExceededException, AddressNotFoundException
|
||||
from app.modules.customers.services.customer_address_service import CustomerAddressService
|
||||
from app.modules.customers.models.customer import CustomerAddress
|
||||
from app.modules.customers.schemas import CustomerAddressCreate, CustomerAddressUpdate
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.email_service import (
|
||||
from app.modules.messaging.services.email_service import (
|
||||
DebugProvider,
|
||||
EmailProvider,
|
||||
EmailService,
|
||||
@@ -56,7 +56,7 @@ class TestEmailProviders:
|
||||
|
||||
assert success is True
|
||||
|
||||
@patch("app.services.email_service.settings")
|
||||
@patch("app.modules.messaging.services.email_service.settings")
|
||||
def test_get_provider_debug_mode(self, mock_settings):
|
||||
"""Test get_provider returns DebugProvider in debug mode."""
|
||||
mock_settings.email_debug = True
|
||||
@@ -65,7 +65,7 @@ class TestEmailProviders:
|
||||
|
||||
assert isinstance(provider, DebugProvider)
|
||||
|
||||
@patch("app.services.email_service.settings")
|
||||
@patch("app.modules.messaging.services.email_service.settings")
|
||||
def test_get_provider_smtp(self, mock_settings):
|
||||
"""Test get_provider returns SMTPProvider for smtp config."""
|
||||
mock_settings.email_debug = False
|
||||
@@ -75,7 +75,7 @@ class TestEmailProviders:
|
||||
|
||||
assert isinstance(provider, SMTPProvider)
|
||||
|
||||
@patch("app.services.email_service.settings")
|
||||
@patch("app.modules.messaging.services.email_service.settings")
|
||||
def test_get_provider_unknown_defaults_to_smtp(self, mock_settings):
|
||||
"""Test get_provider defaults to SMTP for unknown providers."""
|
||||
mock_settings.email_debug = False
|
||||
@@ -211,8 +211,8 @@ class TestEmailService:
|
||||
class TestEmailSending:
|
||||
"""Test suite for email sending functionality."""
|
||||
|
||||
@patch("app.services.email_service.get_platform_provider")
|
||||
@patch("app.services.email_service.get_platform_email_config")
|
||||
@patch("app.modules.messaging.services.email_service.get_platform_provider")
|
||||
@patch("app.modules.messaging.services.email_service.get_platform_email_config")
|
||||
def test_send_raw_success(self, mock_get_config, mock_get_platform_provider, db):
|
||||
"""Test successful raw email sending."""
|
||||
# Setup mocks
|
||||
@@ -243,8 +243,8 @@ class TestEmailSending:
|
||||
assert log.subject == "Test Subject"
|
||||
assert log.provider_message_id == "msg-123"
|
||||
|
||||
@patch("app.services.email_service.get_platform_provider")
|
||||
@patch("app.services.email_service.get_platform_email_config")
|
||||
@patch("app.modules.messaging.services.email_service.get_platform_provider")
|
||||
@patch("app.modules.messaging.services.email_service.get_platform_email_config")
|
||||
def test_send_raw_failure(self, mock_get_config, mock_get_platform_provider, db):
|
||||
"""Test failed raw email sending."""
|
||||
# Setup mocks
|
||||
@@ -272,7 +272,7 @@ class TestEmailSending:
|
||||
assert log.status == EmailStatus.FAILED.value
|
||||
assert log.error_message == "Connection refused"
|
||||
|
||||
@patch("app.services.email_service.settings")
|
||||
@patch("app.modules.messaging.services.email_service.settings")
|
||||
def test_send_raw_email_disabled(self, mock_settings, db):
|
||||
"""Test email sending when disabled."""
|
||||
mock_settings.email_enabled = False
|
||||
@@ -293,8 +293,8 @@ class TestEmailSending:
|
||||
assert log.status == EmailStatus.FAILED.value
|
||||
assert "disabled" in log.error_message.lower()
|
||||
|
||||
@patch("app.services.email_service.get_platform_provider")
|
||||
@patch("app.services.email_service.get_platform_email_config")
|
||||
@patch("app.modules.messaging.services.email_service.get_platform_provider")
|
||||
@patch("app.modules.messaging.services.email_service.get_platform_email_config")
|
||||
def test_send_template_success(self, mock_get_config, mock_get_platform_provider, db):
|
||||
"""Test successful template email sending."""
|
||||
# Create test template
|
||||
@@ -586,8 +586,8 @@ class TestSignupWelcomeEmail:
|
||||
for var in required_vars:
|
||||
assert var in template.variables_list, f"Missing variable: {var}"
|
||||
|
||||
@patch("app.services.email_service.get_platform_provider")
|
||||
@patch("app.services.email_service.get_platform_email_config")
|
||||
@patch("app.modules.messaging.services.email_service.get_platform_provider")
|
||||
@patch("app.modules.messaging.services.email_service.get_platform_email_config")
|
||||
def test_welcome_email_send(self, mock_get_config, mock_get_platform_provider, db, welcome_template, test_vendor, test_user):
|
||||
"""Test sending welcome email."""
|
||||
# Setup mocks
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import FeatureNotFoundError, InvalidFeatureCodesError, TierNotFoundError
|
||||
from app.services.feature_service import FeatureService, feature_service
|
||||
from app.modules.billing.exceptions import FeatureNotFoundError, InvalidFeatureCodesError, TierNotFoundError
|
||||
from app.modules.billing.services.feature_service import FeatureService, feature_service
|
||||
from app.modules.billing.models import Feature
|
||||
from app.modules.billing.models import SubscriptionTier, VendorSubscription
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import (
|
||||
from app.modules.inventory.exceptions import (
|
||||
InsufficientInventoryException,
|
||||
InvalidQuantityException,
|
||||
InventoryNotFoundException,
|
||||
InventoryValidationException,
|
||||
ProductNotFoundException,
|
||||
)
|
||||
from app.services.inventory_service import InventoryService
|
||||
from app.modules.catalog.exceptions import ProductNotFoundException
|
||||
from app.modules.inventory.services.inventory_service import InventoryService
|
||||
from app.modules.inventory.models import Inventory
|
||||
from app.modules.inventory.schemas import (
|
||||
InventoryAdjust,
|
||||
@@ -126,7 +126,7 @@ class TestInventoryService:
|
||||
|
||||
def test_set_inventory_product_not_found(self, db, test_vendor):
|
||||
"""Test setting inventory for non-existent product raises exception."""
|
||||
from app.exceptions.base import ValidationException
|
||||
from app.exceptions import ValidationException
|
||||
|
||||
unique_id = str(uuid.uuid4())[:8].upper()
|
||||
inventory_data = InventoryCreate(
|
||||
@@ -203,7 +203,7 @@ class TestInventoryService:
|
||||
self, db, test_inventory, test_product, test_vendor
|
||||
):
|
||||
"""Test removing more than available raises exception."""
|
||||
from app.exceptions.base import ValidationException
|
||||
from app.exceptions import ValidationException
|
||||
|
||||
inventory_data = InventoryAdjust(
|
||||
product_id=test_product.id,
|
||||
@@ -251,7 +251,7 @@ class TestInventoryService:
|
||||
self, db, test_inventory, test_product, test_vendor
|
||||
):
|
||||
"""Test reserving more than available raises exception."""
|
||||
from app.exceptions.base import ValidationException
|
||||
from app.exceptions import ValidationException
|
||||
|
||||
available = test_inventory.quantity - test_inventory.reserved_quantity
|
||||
|
||||
@@ -335,7 +335,7 @@ class TestInventoryService:
|
||||
self, db, test_inventory, test_product, test_vendor
|
||||
):
|
||||
"""Test fulfilling more than quantity raises exception."""
|
||||
from app.exceptions.base import ValidationException
|
||||
from app.exceptions import ValidationException
|
||||
|
||||
reserve_data = InventoryReserve(
|
||||
product_id=test_product.id,
|
||||
@@ -401,7 +401,7 @@ class TestInventoryService:
|
||||
|
||||
def test_get_product_inventory_not_found(self, db, test_vendor):
|
||||
"""Test getting inventory for non-existent product raises exception."""
|
||||
from app.exceptions.base import ValidationException
|
||||
from app.exceptions import ValidationException
|
||||
|
||||
# Service wraps ProductNotFoundException in ValidationException
|
||||
with pytest.raises((ProductNotFoundException, ValidationException)):
|
||||
@@ -675,7 +675,7 @@ class TestInventoryService:
|
||||
|
||||
def test_get_vendor_inventory_admin_vendor_not_found(self, db):
|
||||
"""Test get_vendor_inventory_admin raises for non-existent vendor."""
|
||||
from app.exceptions import VendorNotFoundException
|
||||
from app.modules.tenancy.exceptions import VendorNotFoundException
|
||||
|
||||
with pytest.raises(VendorNotFoundException):
|
||||
self.service.get_vendor_inventory_admin(db, vendor_id=99999)
|
||||
@@ -700,7 +700,7 @@ class TestInventoryService:
|
||||
|
||||
def test_verify_vendor_exists_not_found(self, db):
|
||||
"""Test verify_vendor_exists raises for non-existent vendor."""
|
||||
from app.exceptions import VendorNotFoundException
|
||||
from app.modules.tenancy.exceptions import VendorNotFoundException
|
||||
|
||||
with pytest.raises(VendorNotFoundException):
|
||||
self.service.verify_vendor_exists(db, 99999)
|
||||
|
||||
@@ -7,11 +7,11 @@ from decimal import Decimal
|
||||
import pytest
|
||||
|
||||
from app.exceptions import ValidationException
|
||||
from app.exceptions.invoice import (
|
||||
from app.modules.orders.exceptions import (
|
||||
InvoiceNotFoundException,
|
||||
InvoiceSettingsNotFoundException,
|
||||
)
|
||||
from app.services.invoice_service import (
|
||||
from app.modules.orders.services.invoice_service import (
|
||||
EU_VAT_RATES,
|
||||
InvoiceService,
|
||||
LU_VAT_RATES,
|
||||
|
||||
@@ -12,7 +12,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.letzshop import (
|
||||
from app.modules.marketplace.services.letzshop import (
|
||||
CredentialsNotFoundError,
|
||||
LetzshopAPIError,
|
||||
LetzshopClient,
|
||||
@@ -570,7 +570,7 @@ class TestLetzshopOrderService:
|
||||
|
||||
def test_create_order_extracts_locale(self, db, test_vendor):
|
||||
"""Test that create_order extracts customer locale."""
|
||||
from app.services.letzshop.order_service import LetzshopOrderService
|
||||
from app.modules.marketplace.services.letzshop.order_service import LetzshopOrderService
|
||||
|
||||
service = LetzshopOrderService(db)
|
||||
|
||||
@@ -603,7 +603,7 @@ class TestLetzshopOrderService:
|
||||
|
||||
def test_create_order_extracts_ean(self, db, test_vendor):
|
||||
"""Test that create_order extracts EAN from tradeId."""
|
||||
from app.services.letzshop.order_service import LetzshopOrderService
|
||||
from app.modules.marketplace.services.letzshop.order_service import LetzshopOrderService
|
||||
|
||||
service = LetzshopOrderService(db)
|
||||
|
||||
@@ -652,7 +652,7 @@ class TestLetzshopOrderService:
|
||||
|
||||
def test_import_historical_shipments_deduplication(self, db, test_vendor):
|
||||
"""Test that historical import deduplicates existing orders."""
|
||||
from app.services.letzshop.order_service import LetzshopOrderService
|
||||
from app.modules.marketplace.services.letzshop.order_service import LetzshopOrderService
|
||||
|
||||
service = LetzshopOrderService(db)
|
||||
|
||||
@@ -686,7 +686,7 @@ class TestLetzshopOrderService:
|
||||
|
||||
def test_import_historical_shipments_new_orders(self, db, test_vendor):
|
||||
"""Test that historical import creates new orders."""
|
||||
from app.services.letzshop.order_service import LetzshopOrderService
|
||||
from app.modules.marketplace.services.letzshop.order_service import LetzshopOrderService
|
||||
|
||||
service = LetzshopOrderService(db)
|
||||
|
||||
@@ -718,7 +718,7 @@ class TestLetzshopOrderService:
|
||||
|
||||
def test_get_historical_import_summary(self, db, test_vendor):
|
||||
"""Test historical import summary statistics."""
|
||||
from app.services.letzshop.order_service import LetzshopOrderService
|
||||
from app.modules.marketplace.services.letzshop.order_service import LetzshopOrderService
|
||||
|
||||
service = LetzshopOrderService(db)
|
||||
|
||||
|
||||
@@ -16,13 +16,13 @@ import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import (
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.marketplace.exceptions import (
|
||||
InvalidMarketplaceProductDataException,
|
||||
MarketplaceProductNotFoundException,
|
||||
MarketplaceProductValidationException,
|
||||
ValidationException,
|
||||
)
|
||||
from app.services.marketplace_product_service import (
|
||||
from app.modules.marketplace.services.marketplace_product_service import (
|
||||
MarketplaceProductService,
|
||||
marketplace_product_service,
|
||||
)
|
||||
@@ -502,7 +502,7 @@ class TestMarketplaceProductServiceCopyToCatalog:
|
||||
mock_subscription.products_limit = 100
|
||||
|
||||
with patch(
|
||||
"app.services.subscription_service.subscription_service"
|
||||
"app.modules.billing.services.subscription_service.subscription_service"
|
||||
) as mock_sub:
|
||||
mock_sub.get_or_create_subscription.return_value = mock_subscription
|
||||
|
||||
@@ -519,7 +519,7 @@ class TestMarketplaceProductServiceCopyToCatalog:
|
||||
|
||||
def test_copy_to_vendor_catalog_vendor_not_found(self, db, test_marketplace_product):
|
||||
"""Test copy fails for non-existent vendor"""
|
||||
from app.exceptions import VendorNotFoundException
|
||||
from app.modules.tenancy.exceptions import VendorNotFoundException
|
||||
|
||||
with pytest.raises(VendorNotFoundException):
|
||||
self.service.copy_to_vendor_catalog(
|
||||
|
||||
@@ -5,13 +5,13 @@ import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions.base import ValidationException
|
||||
from app.exceptions.marketplace_import_job import (
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.marketplace.exceptions import (
|
||||
ImportJobNotFoundException,
|
||||
ImportJobNotOwnedException,
|
||||
)
|
||||
from app.exceptions.vendor import UnauthorizedVendorAccessException
|
||||
from app.services.marketplace_import_job_service import MarketplaceImportJobService
|
||||
from app.modules.tenancy.exceptions import UnauthorizedVendorAccessException
|
||||
from app.modules.marketplace.services.marketplace_import_job_service import MarketplaceImportJobService
|
||||
from app.modules.marketplace.models import MarketplaceImportJob
|
||||
from app.modules.marketplace.schemas import MarketplaceImportJobRequest
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ from unittest.mock import AsyncMock, MagicMock, patch
|
||||
import pytest
|
||||
from fastapi import UploadFile
|
||||
|
||||
from app.services.message_attachment_service import (
|
||||
from app.modules.messaging.services.message_attachment_service import (
|
||||
ALLOWED_MIME_TYPES,
|
||||
DEFAULT_MAX_FILE_SIZE_MB,
|
||||
IMAGE_MIME_TYPES,
|
||||
@@ -101,7 +101,7 @@ class TestMessageAttachmentServiceMaxFileSize:
|
||||
def test_get_max_file_size_from_settings(self, db, attachment_service):
|
||||
"""Test retrieving max file size from platform settings."""
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = 15
|
||||
max_size = attachment_service.get_max_file_size_bytes(db)
|
||||
@@ -110,7 +110,7 @@ class TestMessageAttachmentServiceMaxFileSize:
|
||||
def test_get_max_file_size_default(self, db, attachment_service):
|
||||
"""Test default max file size when setting not found."""
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = DEFAULT_MAX_FILE_SIZE_MB
|
||||
max_size = attachment_service.get_max_file_size_bytes(db)
|
||||
@@ -119,7 +119,7 @@ class TestMessageAttachmentServiceMaxFileSize:
|
||||
def test_get_max_file_size_invalid_value(self, db, attachment_service):
|
||||
"""Test handling of invalid setting value."""
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = "invalid"
|
||||
max_size = attachment_service.get_max_file_size_bytes(db)
|
||||
@@ -142,7 +142,7 @@ class TestMessageAttachmentServiceValidateAndStore:
|
||||
)
|
||||
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = 10
|
||||
|
||||
@@ -181,7 +181,7 @@ class TestMessageAttachmentServiceValidateAndStore:
|
||||
)
|
||||
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = 10
|
||||
|
||||
@@ -208,7 +208,7 @@ class TestMessageAttachmentServiceValidateAndStore:
|
||||
)
|
||||
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = 10
|
||||
|
||||
@@ -233,7 +233,7 @@ class TestMessageAttachmentServiceValidateAndStore:
|
||||
)
|
||||
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = 10 # 10 MB limit
|
||||
|
||||
@@ -257,7 +257,7 @@ class TestMessageAttachmentServiceValidateAndStore:
|
||||
file.filename = None # Ensure it's None
|
||||
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = 10
|
||||
|
||||
@@ -282,7 +282,7 @@ class TestMessageAttachmentServiceValidateAndStore:
|
||||
file.content_type = None
|
||||
|
||||
with patch(
|
||||
"app.services.message_attachment_service.admin_settings_service"
|
||||
"app.modules.messaging.services.message_attachment_service.admin_settings_service"
|
||||
) as mock_settings:
|
||||
mock_settings.get_setting_value.return_value = 10
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.messaging_service import MessagingService
|
||||
from app.modules.messaging.services.messaging_service import MessagingService
|
||||
from app.modules.messaging.models import (
|
||||
Conversation,
|
||||
ConversationParticipant,
|
||||
|
||||
@@ -15,7 +15,7 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.onboarding_service import OnboardingService
|
||||
from app.modules.marketplace.services.onboarding_service import OnboardingService
|
||||
from app.modules.marketplace.models import OnboardingStatus, OnboardingStep, VendorOnboarding
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ class TestOnboardingServiceCRUD:
|
||||
|
||||
def test_get_onboarding_or_raise_raises_exception(self, db):
|
||||
"""Test get_onboarding_or_raise raises OnboardingNotFoundException"""
|
||||
from app.exceptions import OnboardingNotFoundException
|
||||
from app.modules.marketplace.exceptions import OnboardingNotFoundException
|
||||
|
||||
service = OnboardingService(db)
|
||||
with pytest.raises(OnboardingNotFoundException):
|
||||
@@ -214,7 +214,7 @@ class TestOnboardingServiceStep1:
|
||||
|
||||
def test_complete_company_profile_raises_for_missing_vendor(self, db):
|
||||
"""Test complete_company_profile raises for non-existent vendor"""
|
||||
from app.exceptions import VendorNotFoundException
|
||||
from app.modules.tenancy.exceptions import VendorNotFoundException
|
||||
|
||||
service = OnboardingService(db)
|
||||
|
||||
@@ -238,7 +238,7 @@ class TestOnboardingServiceStep2:
|
||||
def test_test_letzshop_api_returns_result(self, db, test_vendor):
|
||||
"""Test test_letzshop_api returns connection test result"""
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopCredentialsService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopCredentialsService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
mock_instance.test_api_key.return_value = (True, 150.0, None)
|
||||
@@ -256,7 +256,7 @@ class TestOnboardingServiceStep2:
|
||||
def test_test_letzshop_api_returns_error(self, db, test_vendor):
|
||||
"""Test test_letzshop_api returns error on failure"""
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopCredentialsService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopCredentialsService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
mock_instance.test_api_key.return_value = (False, None, "Invalid API key")
|
||||
@@ -273,7 +273,7 @@ class TestOnboardingServiceStep2:
|
||||
|
||||
def test_complete_letzshop_api_requires_step1(self, db, test_vendor):
|
||||
"""Test complete_letzshop_api requires step 1 complete"""
|
||||
from app.exceptions import OnboardingStepOrderException
|
||||
from app.modules.marketplace.exceptions import OnboardingStepOrderException
|
||||
|
||||
# Create onboarding with step 1 not complete
|
||||
onboarding = VendorOnboarding(
|
||||
@@ -319,7 +319,7 @@ class TestOnboardingServiceStep3:
|
||||
|
||||
def test_complete_product_import_requires_csv_url(self, db, test_vendor):
|
||||
"""Test complete_product_import requires at least one CSV URL"""
|
||||
from app.exceptions import OnboardingCsvUrlRequiredException
|
||||
from app.modules.marketplace.exceptions import OnboardingCsvUrlRequiredException
|
||||
|
||||
# Create onboarding with steps 1 and 2 complete
|
||||
onboarding = VendorOnboarding(
|
||||
@@ -391,7 +391,7 @@ class TestOnboardingServiceStep4:
|
||||
db.commit()
|
||||
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopOrderService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopOrderService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
mock_instance.get_running_historical_import_job.return_value = None
|
||||
@@ -425,7 +425,7 @@ class TestOnboardingServiceStep4:
|
||||
db.commit()
|
||||
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopOrderService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopOrderService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
existing_job = MagicMock()
|
||||
@@ -446,7 +446,7 @@ class TestOnboardingServiceStep4:
|
||||
def test_get_order_sync_progress_not_found(self, db, test_vendor):
|
||||
"""Test get_order_sync_progress for non-existent job"""
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopOrderService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopOrderService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
mock_instance.get_historical_import_job_by_id.return_value = None
|
||||
@@ -464,7 +464,7 @@ class TestOnboardingServiceStep4:
|
||||
def test_get_order_sync_progress_completed(self, db, test_vendor):
|
||||
"""Test get_order_sync_progress for completed job"""
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopOrderService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopOrderService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
mock_job = MagicMock()
|
||||
@@ -494,7 +494,7 @@ class TestOnboardingServiceStep4:
|
||||
def test_get_order_sync_progress_processing(self, db, test_vendor):
|
||||
"""Test get_order_sync_progress for processing job"""
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopOrderService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopOrderService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
mock_job = MagicMock()
|
||||
@@ -525,7 +525,7 @@ class TestOnboardingServiceStep4:
|
||||
|
||||
def test_complete_order_sync_raises_for_missing_job(self, db, test_vendor):
|
||||
"""Test complete_order_sync raises for non-existent job"""
|
||||
from app.exceptions import OnboardingSyncJobNotFoundException
|
||||
from app.modules.marketplace.exceptions import OnboardingSyncJobNotFoundException
|
||||
|
||||
onboarding = VendorOnboarding(
|
||||
vendor_id=test_vendor.id,
|
||||
@@ -535,7 +535,7 @@ class TestOnboardingServiceStep4:
|
||||
db.commit()
|
||||
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopOrderService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopOrderService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
mock_instance.get_historical_import_job_by_id.return_value = None
|
||||
@@ -550,7 +550,7 @@ class TestOnboardingServiceStep4:
|
||||
|
||||
def test_complete_order_sync_raises_if_not_complete(self, db, test_vendor):
|
||||
"""Test complete_order_sync raises if job still running"""
|
||||
from app.exceptions import OnboardingSyncNotCompleteException
|
||||
from app.modules.marketplace.exceptions import OnboardingSyncNotCompleteException
|
||||
|
||||
onboarding = VendorOnboarding(
|
||||
vendor_id=test_vendor.id,
|
||||
@@ -560,7 +560,7 @@ class TestOnboardingServiceStep4:
|
||||
db.commit()
|
||||
|
||||
with patch(
|
||||
"app.services.onboarding_service.LetzshopOrderService"
|
||||
"app.modules.marketplace.services.onboarding_service.LetzshopOrderService"
|
||||
) as mock_service:
|
||||
mock_instance = MagicMock()
|
||||
mock_job = MagicMock()
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import (
|
||||
from app.modules.orders.exceptions import (
|
||||
ExceptionAlreadyResolvedException,
|
||||
InvalidProductForExceptionException,
|
||||
OrderItemExceptionNotFoundException,
|
||||
ProductNotFoundException,
|
||||
)
|
||||
from app.services.order_item_exception_service import OrderItemExceptionService
|
||||
from app.modules.catalog.exceptions import ProductNotFoundException
|
||||
from app.modules.orders.services.order_item_exception_service import OrderItemExceptionService
|
||||
from app.modules.orders.models import OrderItem
|
||||
from app.modules.orders.models import OrderItemException
|
||||
|
||||
|
||||
@@ -16,12 +16,10 @@ from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import (
|
||||
CustomerNotFoundException,
|
||||
OrderNotFoundException,
|
||||
ValidationException,
|
||||
)
|
||||
from app.services.order_service import (
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.customers.exceptions import CustomerNotFoundException
|
||||
from app.modules.orders.exceptions import OrderNotFoundException
|
||||
from app.modules.orders.services.order_service import (
|
||||
PLACEHOLDER_GTIN,
|
||||
PLACEHOLDER_MARKETPLACE_ID,
|
||||
OrderService,
|
||||
@@ -518,7 +516,7 @@ class TestOrderServiceLetzshop:
|
||||
}
|
||||
|
||||
with patch(
|
||||
"app.services.order_service.subscription_service"
|
||||
"app.modules.orders.services.order_service.subscription_service"
|
||||
) as mock_sub:
|
||||
mock_sub.can_create_order.return_value = (True, None)
|
||||
mock_sub.increment_order_count.return_value = None
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
# tests/test_product_service.py
|
||||
import pytest
|
||||
|
||||
from app.exceptions import (
|
||||
from app.modules.marketplace.exceptions import (
|
||||
InvalidMarketplaceProductDataException,
|
||||
MarketplaceProductAlreadyExistsException,
|
||||
MarketplaceProductNotFoundException,
|
||||
MarketplaceProductValidationException,
|
||||
)
|
||||
from app.services.marketplace_product_service import MarketplaceProductService
|
||||
from app.modules.marketplace.services.marketplace_product_service import MarketplaceProductService
|
||||
from app.modules.marketplace.schemas import (
|
||||
MarketplaceProductCreate,
|
||||
MarketplaceProductUpdate,
|
||||
@@ -488,7 +488,7 @@ class TestMarketplaceProductServiceAdmin:
|
||||
|
||||
def test_copy_to_vendor_catalog_invalid_vendor(self, db, test_marketplace_product):
|
||||
"""Test copying to non-existent vendor raises exception."""
|
||||
from app.exceptions import VendorNotFoundException
|
||||
from app.modules.tenancy.exceptions import VendorNotFoundException
|
||||
|
||||
with pytest.raises(VendorNotFoundException):
|
||||
self.service.copy_to_vendor_catalog(
|
||||
|
||||
@@ -7,8 +7,8 @@ from unittest.mock import patch
|
||||
import pytest
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
|
||||
from app.exceptions import AdminOperationException, VendorNotFoundException
|
||||
from app.services.stats_service import StatsService
|
||||
from app.modules.tenancy.exceptions import AdminOperationException, VendorNotFoundException
|
||||
from app.modules.analytics.services.stats_service import StatsService
|
||||
from app.modules.inventory.models import Inventory
|
||||
from app.modules.marketplace.models import (
|
||||
MarketplaceProduct,
|
||||
|
||||
@@ -16,7 +16,7 @@ from unittest.mock import MagicMock
|
||||
import pytest
|
||||
|
||||
from app.exceptions import ValidationException
|
||||
from app.services.team_service import TeamService, team_service
|
||||
from app.modules.tenancy.services.team_service import TeamService, team_service
|
||||
from models.database.vendor import Role, VendorUser
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from app.services.usage_service import UsageService, usage_service
|
||||
from app.modules.analytics.services.usage_service import UsageService, usage_service
|
||||
from app.modules.catalog.models import Product
|
||||
from app.modules.billing.models import SubscriptionTier, VendorSubscription
|
||||
from models.database.vendor import VendorUser
|
||||
|
||||
@@ -10,7 +10,7 @@ from app.exceptions import (
|
||||
ResourceNotFoundException,
|
||||
ValidationException,
|
||||
)
|
||||
from app.services.vendor_email_settings_service import VendorEmailSettingsService
|
||||
from app.modules.cms.services.vendor_email_settings_service import VendorEmailSettingsService
|
||||
from models.database import VendorEmailSettings, TierCode
|
||||
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ Tests the vendor product catalog service operations.
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import ProductNotFoundException
|
||||
from app.services.vendor_product_service import VendorProductService
|
||||
from app.modules.catalog.exceptions import ProductNotFoundException
|
||||
from app.modules.catalog.services.vendor_product_service import VendorProductService
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
@@ -5,16 +5,16 @@ import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import (
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.exceptions import (
|
||||
InvalidVendorDataException,
|
||||
MarketplaceProductNotFoundException,
|
||||
ProductAlreadyExistsException,
|
||||
UnauthorizedVendorAccessException,
|
||||
ValidationException,
|
||||
VendorAlreadyExistsException,
|
||||
VendorNotFoundException,
|
||||
)
|
||||
from app.services.vendor_service import VendorService
|
||||
from app.modules.marketplace.exceptions import MarketplaceProductNotFoundException
|
||||
from app.modules.catalog.exceptions import ProductAlreadyExistsException
|
||||
from app.modules.tenancy.services.vendor_service import VendorService
|
||||
from models.database.company import Company
|
||||
from models.database.vendor import Vendor
|
||||
from app.modules.catalog.schemas import ProductCreate
|
||||
@@ -642,7 +642,7 @@ class TestVendorServiceUpdate:
|
||||
"""Test update fails for unauthorized user."""
|
||||
from pydantic import BaseModel
|
||||
|
||||
from app.exceptions import InsufficientPermissionsException
|
||||
from app.modules.tenancy.exceptions import InsufficientPermissionsException
|
||||
from models.database.user import User
|
||||
|
||||
class VendorUpdate(BaseModel):
|
||||
@@ -694,7 +694,7 @@ class TestVendorServiceUpdate:
|
||||
self, db, other_company, test_vendor
|
||||
):
|
||||
"""Test marketplace settings update fails for unauthorized user."""
|
||||
from app.exceptions import InsufficientPermissionsException
|
||||
from app.modules.tenancy.exceptions import InsufficientPermissionsException
|
||||
from models.database.user import User
|
||||
|
||||
other_user = db.query(User).filter(User.id == other_company.owner_user_id).first()
|
||||
@@ -722,7 +722,7 @@ class TestVendorServiceSingleton:
|
||||
|
||||
def test_singleton_exists(self):
|
||||
"""Test vendor_service singleton exists."""
|
||||
from app.services.vendor_service import vendor_service
|
||||
from app.modules.tenancy.services.vendor_service import vendor_service
|
||||
|
||||
assert vendor_service is not None
|
||||
assert isinstance(vendor_service, VendorService)
|
||||
|
||||
Reference in New Issue
Block a user