fix(lint): auto-fix ruff violations and tune lint rules
- Auto-fixed 4,496 lint issues (import sorting, modern syntax, etc.) - Added ignore rules for patterns intentional in this codebase: E402 (late imports), E712 (SQLAlchemy filters), B904 (raise from), SIM108/SIM105/SIM117 (readability preferences) - Added per-file ignores for tests and scripts - Excluded broken scripts/rename_terminology.py (has curly quotes) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,6 @@ from app.exceptions.base import (
|
||||
WizamartException,
|
||||
)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Authentication Exceptions
|
||||
# =============================================================================
|
||||
|
||||
@@ -4,9 +4,10 @@ Revision ID: tenancy_001
|
||||
Revises: dev_tools_001
|
||||
Create Date: 2026-02-09
|
||||
"""
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
from alembic import op
|
||||
|
||||
revision = "tenancy_001"
|
||||
down_revision = "dev_tools_001"
|
||||
branch_labels = None
|
||||
|
||||
@@ -20,7 +20,6 @@ This is the canonical location for tenancy module models including:
|
||||
# NOTE: MarketplaceImportJob relationships have been moved to the marketplace module.
|
||||
# Optional modules own their relationships to core models, not vice versa.
|
||||
from app.modules.core.models import AdminMenuConfig # noqa: F401
|
||||
|
||||
from app.modules.tenancy.models.admin import (
|
||||
AdminAuditLog,
|
||||
AdminSession,
|
||||
@@ -30,13 +29,13 @@ from app.modules.tenancy.models.admin import (
|
||||
)
|
||||
from app.modules.tenancy.models.admin_platform import AdminPlatform
|
||||
from app.modules.tenancy.models.merchant import Merchant
|
||||
from app.modules.tenancy.models.merchant_domain import MerchantDomain
|
||||
from app.modules.tenancy.models.platform import Platform
|
||||
from app.modules.tenancy.models.platform_module import PlatformModule
|
||||
from app.modules.tenancy.models.user import User, UserRole
|
||||
from app.modules.tenancy.models.store import Role, Store, StoreUser, StoreUserType
|
||||
from app.modules.tenancy.models.merchant_domain import MerchantDomain
|
||||
from app.modules.tenancy.models.store_domain import StoreDomain
|
||||
from app.modules.tenancy.models.store_platform import StorePlatform
|
||||
from app.modules.tenancy.models.user import User, UserRole
|
||||
|
||||
__all__ = [
|
||||
# Admin models
|
||||
|
||||
@@ -19,15 +19,15 @@ The tenancy module owns identity and organizational hierarchy.
|
||||
from fastapi import APIRouter
|
||||
|
||||
from .admin_auth import admin_auth_router
|
||||
from .admin_users import admin_users_router
|
||||
from .admin_platform_users import admin_platform_users_router
|
||||
from .admin_merchants import admin_merchants_router
|
||||
from .admin_platforms import admin_platforms_router
|
||||
from .admin_stores import admin_stores_router
|
||||
from .admin_store_domains import admin_store_domains_router
|
||||
from .admin_merchant_domains import admin_merchant_domains_router
|
||||
from .admin_modules import router as admin_modules_router
|
||||
from .admin_merchants import admin_merchants_router
|
||||
from .admin_module_config import router as admin_module_config_router
|
||||
from .admin_modules import router as admin_modules_router
|
||||
from .admin_platform_users import admin_platform_users_router
|
||||
from .admin_platforms import admin_platforms_router
|
||||
from .admin_store_domains import admin_store_domains_router
|
||||
from .admin_stores import admin_stores_router
|
||||
from .admin_users import admin_users_router
|
||||
|
||||
admin_router = APIRouter()
|
||||
|
||||
|
||||
@@ -17,13 +17,20 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_admin_api, get_current_admin_from_cookie_or_header
|
||||
from app.core.database import get_db
|
||||
from app.core.environment import should_use_secure_cookies
|
||||
from app.modules.tenancy.exceptions import InsufficientPermissionsException, InvalidCredentialsException
|
||||
from app.modules.tenancy.services.admin_platform_service import admin_platform_service
|
||||
from app.modules.core.services.auth_service import auth_service
|
||||
from app.modules.tenancy.exceptions import (
|
||||
InvalidCredentialsException,
|
||||
)
|
||||
from app.modules.tenancy.services.admin_platform_service import admin_platform_service
|
||||
from middleware.auth import AuthManager
|
||||
from app.modules.tenancy.models import Platform # noqa: API-007 - Admin needs to query platforms
|
||||
from models.schema.auth import UserContext
|
||||
from models.schema.auth import LoginResponse, LogoutResponse, PlatformSelectResponse, UserLogin, UserResponse
|
||||
from models.schema.auth import (
|
||||
LoginResponse,
|
||||
LogoutResponse,
|
||||
PlatformSelectResponse,
|
||||
UserContext,
|
||||
UserLogin,
|
||||
UserResponse,
|
||||
)
|
||||
|
||||
admin_auth_router = APIRouter(prefix="/auth")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,10 +16,6 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.tenancy.services.merchant_domain_service import (
|
||||
merchant_domain_service,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.schemas.merchant_domain import (
|
||||
MerchantDomainCreate,
|
||||
MerchantDomainDeletionResponse,
|
||||
@@ -31,6 +27,10 @@ from app.modules.tenancy.schemas.store_domain import (
|
||||
DomainVerificationInstructions,
|
||||
DomainVerificationResponse,
|
||||
)
|
||||
from app.modules.tenancy.services.merchant_domain_service import (
|
||||
merchant_domain_service,
|
||||
)
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_merchant_domains_router = APIRouter(prefix="/merchants")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -11,9 +11,10 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.tenancy.exceptions import MerchantHasStoresException, ConfirmationRequiredException
|
||||
from app.modules.tenancy.services.merchant_service import merchant_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.exceptions import (
|
||||
ConfirmationRequiredException,
|
||||
MerchantHasStoresException,
|
||||
)
|
||||
from app.modules.tenancy.schemas.merchant import (
|
||||
MerchantCreate,
|
||||
MerchantCreateResponse,
|
||||
@@ -24,6 +25,8 @@ from app.modules.tenancy.schemas.merchant import (
|
||||
MerchantTransferOwnershipResponse,
|
||||
MerchantUpdate,
|
||||
)
|
||||
from app.modules.tenancy.services.merchant_service import merchant_service
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_merchants_router = APIRouter(prefix="/merchants")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -136,7 +136,7 @@ async def list_all_modules(
|
||||
Super admin only.
|
||||
"""
|
||||
modules = []
|
||||
for code in MODULES.keys():
|
||||
for code in MODULES:
|
||||
# All modules shown as enabled in the global list
|
||||
modules.append(_build_module_response(code, is_enabled=True))
|
||||
|
||||
@@ -172,7 +172,7 @@ async def get_platform_modules(
|
||||
enabled_codes = module_service.get_enabled_module_codes(db, platform_id)
|
||||
|
||||
modules = []
|
||||
for code in MODULES.keys():
|
||||
for code in MODULES:
|
||||
is_enabled = code in enabled_codes
|
||||
modules.append(_build_module_response(code, is_enabled))
|
||||
|
||||
@@ -222,7 +222,7 @@ async def update_platform_modules(
|
||||
enabled_codes = module_service.get_enabled_module_codes(db, platform_id)
|
||||
|
||||
modules = []
|
||||
for code in MODULES.keys():
|
||||
for code in MODULES:
|
||||
is_enabled = code in enabled_codes
|
||||
modules.append(_build_module_response(code, is_enabled))
|
||||
|
||||
|
||||
@@ -16,10 +16,10 @@ from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.core.services.stats_aggregator import stats_aggregator
|
||||
from app.modules.tenancy.services.admin_service import admin_service
|
||||
from models.schema.auth import UserContext
|
||||
from models.schema.auth import (
|
||||
OwnedMerchantSummary,
|
||||
StoreMembershipSummary,
|
||||
UserContext,
|
||||
UserCreate,
|
||||
UserDeleteResponse,
|
||||
UserDetailResponse,
|
||||
|
||||
@@ -16,9 +16,6 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.tenancy.services.store_domain_service import store_domain_service
|
||||
from app.modules.tenancy.services.store_service import store_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.schemas.store_domain import (
|
||||
DomainDeletionResponse,
|
||||
DomainVerificationInstructions,
|
||||
@@ -28,6 +25,9 @@ from app.modules.tenancy.schemas.store_domain import (
|
||||
StoreDomainResponse,
|
||||
StoreDomainUpdate,
|
||||
)
|
||||
from app.modules.tenancy.services.store_domain_service import store_domain_service
|
||||
from app.modules.tenancy.services.store_service import store_service
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_store_domains_router = APIRouter(prefix="/stores")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -16,9 +16,6 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.tenancy.exceptions import ConfirmationRequiredException
|
||||
from app.modules.tenancy.services.admin_service import admin_service
|
||||
from app.modules.tenancy.services.store_service import store_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.schemas.store import (
|
||||
StoreCreate,
|
||||
StoreCreateResponse,
|
||||
@@ -27,6 +24,9 @@ from app.modules.tenancy.schemas.store import (
|
||||
StoreStatsResponse,
|
||||
StoreUpdate,
|
||||
)
|
||||
from app.modules.tenancy.services.admin_service import admin_service
|
||||
from app.modules.tenancy.services.store_service import store_service
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_stores_router = APIRouter(prefix="/stores")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -13,7 +13,6 @@ This module provides endpoints for:
|
||||
|
||||
import logging
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Body, Depends, Path, Query
|
||||
from pydantic import BaseModel, EmailStr
|
||||
@@ -22,8 +21,10 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_super_admin, get_current_super_admin_api
|
||||
from app.core.database import get_db
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.models import (
|
||||
User, # noqa: API-007 - Internal helper uses User model
|
||||
)
|
||||
from app.modules.tenancy.services.admin_platform_service import admin_platform_service
|
||||
from app.modules.tenancy.models import User # noqa: API-007 - Internal helper uses User model
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
admin_users_router = APIRouter(prefix="/admin-users")
|
||||
@@ -53,14 +54,14 @@ class AdminUserResponse(BaseModel):
|
||||
id: int
|
||||
email: str
|
||||
username: str
|
||||
first_name: Optional[str] = None
|
||||
last_name: Optional[str] = None
|
||||
first_name: str | None = None
|
||||
last_name: str | None = None
|
||||
is_active: bool
|
||||
is_super_admin: bool
|
||||
platform_assignments: list[PlatformAssignmentResponse] = []
|
||||
created_at: datetime
|
||||
updated_at: datetime
|
||||
last_login: Optional[datetime] = None
|
||||
last_login: datetime | None = None
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
@@ -79,8 +80,8 @@ class CreateAdminUserRequest(BaseModel):
|
||||
email: EmailStr
|
||||
username: str
|
||||
password: str
|
||||
first_name: Optional[str] = None
|
||||
last_name: Optional[str] = None
|
||||
first_name: str | None = None
|
||||
last_name: str | None = None
|
||||
is_super_admin: bool = False
|
||||
platform_ids: list[int] = []
|
||||
|
||||
@@ -204,22 +205,21 @@ def create_admin_user(
|
||||
is_super_admin=user.is_super_admin,
|
||||
platform_assignments=[],
|
||||
)
|
||||
else:
|
||||
# Create platform admin with assignments using service
|
||||
user, assignments = admin_platform_service.create_platform_admin(
|
||||
db=db,
|
||||
email=request.email,
|
||||
username=request.username,
|
||||
password=request.password,
|
||||
platform_ids=request.platform_ids,
|
||||
created_by_user_id=current_admin.id,
|
||||
first_name=request.first_name,
|
||||
last_name=request.last_name,
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
# Create platform admin with assignments using service
|
||||
user, assignments = admin_platform_service.create_platform_admin(
|
||||
db=db,
|
||||
email=request.email,
|
||||
username=request.username,
|
||||
password=request.password,
|
||||
platform_ids=request.platform_ids,
|
||||
created_by_user_id=current_admin.id,
|
||||
first_name=request.first_name,
|
||||
last_name=request.last_name,
|
||||
)
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
|
||||
return _build_admin_response(user)
|
||||
return _build_admin_response(user)
|
||||
|
||||
|
||||
@admin_users_router.get("/{user_id}", response_model=AdminUserResponse)
|
||||
|
||||
@@ -10,15 +10,18 @@ Auto-discovered by the route system (merchant.py in routes/api/).
|
||||
"""
|
||||
|
||||
import logging
|
||||
from typing import Optional
|
||||
|
||||
from fastapi import APIRouter, Depends, HTTPException, Request
|
||||
from pydantic import BaseModel, EmailStr
|
||||
from fastapi import APIRouter, Depends, Query, Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_merchant_from_cookie_or_header
|
||||
from app.api.deps import get_current_merchant_api, get_merchant_for_current_user
|
||||
from app.core.database import get_db
|
||||
from app.modules.tenancy.models import Merchant
|
||||
from app.modules.tenancy.schemas import (
|
||||
MerchantPortalProfileResponse,
|
||||
MerchantPortalProfileUpdate,
|
||||
MerchantPortalStoreListResponse,
|
||||
)
|
||||
from app.modules.tenancy.services.merchant_service import merchant_service
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
from .merchant_auth import merchant_auth_router
|
||||
@@ -34,95 +37,40 @@ router.include_router(merchant_auth_router, tags=["merchant-auth"])
|
||||
_account_router = APIRouter(prefix="/account")
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# SCHEMAS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class MerchantProfileUpdate(BaseModel):
|
||||
"""Schema for updating merchant profile information."""
|
||||
|
||||
name: str | None = None
|
||||
contact_email: EmailStr | None = None
|
||||
contact_phone: str | None = None
|
||||
website: str | None = None
|
||||
business_address: str | None = None
|
||||
tax_number: str | None = None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# HELPERS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
def _get_user_merchant(db: Session, user_context: UserContext) -> Merchant:
|
||||
"""
|
||||
Get the first active merchant owned by the authenticated user.
|
||||
|
||||
Args:
|
||||
db: Database session
|
||||
user_context: Authenticated user context
|
||||
|
||||
Returns:
|
||||
Merchant: The user's active merchant
|
||||
|
||||
Raises:
|
||||
HTTPException: 404 if user does not own any active merchant
|
||||
"""
|
||||
merchant = (
|
||||
db.query(Merchant)
|
||||
.filter(
|
||||
Merchant.owner_user_id == user_context.id,
|
||||
Merchant.is_active == True, # noqa: E712
|
||||
)
|
||||
.first()
|
||||
)
|
||||
|
||||
if not merchant:
|
||||
raise HTTPException(status_code=404, detail="Merchant not found")
|
||||
|
||||
return merchant
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# ACCOUNT ENDPOINTS
|
||||
# ============================================================================
|
||||
|
||||
|
||||
@_account_router.get("/stores")
|
||||
@_account_router.get("/stores", response_model=MerchantPortalStoreListResponse)
|
||||
async def merchant_stores(
|
||||
request: Request,
|
||||
current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header),
|
||||
skip: int = Query(0, ge=0, description="Number of records to skip"),
|
||||
limit: int = Query(100, ge=1, le=200, description="Max records to return"),
|
||||
merchant=Depends(get_merchant_for_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
List all stores belonging to the merchant.
|
||||
|
||||
Returns a list of store summary dicts with basic info for each store
|
||||
owned by the authenticated merchant.
|
||||
Returns a paginated list of store summaries for the authenticated merchant.
|
||||
"""
|
||||
merchant = _get_user_merchant(db, current_user)
|
||||
stores, total = merchant_service.get_merchant_stores(
|
||||
db, merchant.id, skip=skip, limit=limit
|
||||
)
|
||||
|
||||
stores = []
|
||||
for store in merchant.stores:
|
||||
stores.append(
|
||||
{
|
||||
"id": store.id,
|
||||
"name": store.name,
|
||||
"store_code": store.store_code,
|
||||
"is_active": store.is_active,
|
||||
"created_at": store.created_at.isoformat() if store.created_at else None,
|
||||
}
|
||||
)
|
||||
|
||||
return {"stores": stores}
|
||||
return MerchantPortalStoreListResponse(
|
||||
stores=stores,
|
||||
total=total,
|
||||
skip=skip,
|
||||
limit=limit,
|
||||
)
|
||||
|
||||
|
||||
@_account_router.get("/profile")
|
||||
@_account_router.get("/profile", response_model=MerchantPortalProfileResponse)
|
||||
async def merchant_profile(
|
||||
request: Request,
|
||||
current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header),
|
||||
db: Session = Depends(get_db),
|
||||
merchant=Depends(get_merchant_for_current_user),
|
||||
):
|
||||
"""
|
||||
Get the authenticated merchant's profile information.
|
||||
@@ -130,25 +78,15 @@ async def merchant_profile(
|
||||
Returns merchant details including contact info, business details,
|
||||
and verification status.
|
||||
"""
|
||||
merchant = _get_user_merchant(db, current_user)
|
||||
|
||||
return {
|
||||
"id": merchant.id,
|
||||
"name": merchant.name,
|
||||
"contact_email": merchant.contact_email,
|
||||
"contact_phone": merchant.contact_phone,
|
||||
"website": merchant.website,
|
||||
"business_address": merchant.business_address,
|
||||
"tax_number": merchant.tax_number,
|
||||
"is_verified": merchant.is_verified,
|
||||
}
|
||||
return merchant
|
||||
|
||||
|
||||
@_account_router.put("/profile")
|
||||
@_account_router.put("/profile", response_model=MerchantPortalProfileResponse)
|
||||
async def update_merchant_profile(
|
||||
request: Request,
|
||||
profile_data: MerchantProfileUpdate,
|
||||
current_user: UserContext = Depends(get_current_merchant_from_cookie_or_header),
|
||||
profile_data: MerchantPortalProfileUpdate,
|
||||
current_user: UserContext = Depends(get_current_merchant_api),
|
||||
merchant=Depends(get_merchant_for_current_user),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""
|
||||
@@ -156,8 +94,6 @@ async def update_merchant_profile(
|
||||
|
||||
Accepts partial updates - only provided fields are changed.
|
||||
"""
|
||||
merchant = _get_user_merchant(db, current_user)
|
||||
|
||||
# Apply only the fields that were explicitly provided
|
||||
update_data = profile_data.model_dump(exclude_unset=True)
|
||||
for field_name, value in update_data.items():
|
||||
@@ -171,16 +107,7 @@ async def update_merchant_profile(
|
||||
f"user={current_user.username}, fields={list(update_data.keys())}"
|
||||
)
|
||||
|
||||
return {
|
||||
"id": merchant.id,
|
||||
"name": merchant.name,
|
||||
"contact_email": merchant.contact_email,
|
||||
"contact_phone": merchant.contact_phone,
|
||||
"website": merchant.website,
|
||||
"business_address": merchant.business_address,
|
||||
"tax_number": merchant.tax_number,
|
||||
"is_verified": merchant.is_verified,
|
||||
}
|
||||
return merchant
|
||||
|
||||
|
||||
# Include account routes in main router
|
||||
|
||||
@@ -18,7 +18,13 @@ from app.api.deps import get_current_merchant_from_cookie_or_header
|
||||
from app.core.database import get_db
|
||||
from app.core.environment import should_use_secure_cookies
|
||||
from app.modules.core.services.auth_service import auth_service
|
||||
from models.schema.auth import LoginResponse, LogoutResponse, UserLogin, UserResponse, UserContext
|
||||
from models.schema.auth import (
|
||||
LoginResponse,
|
||||
LogoutResponse,
|
||||
UserContext,
|
||||
UserLogin,
|
||||
UserResponse,
|
||||
)
|
||||
|
||||
merchant_auth_router = APIRouter(prefix="/auth")
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -106,12 +112,6 @@ def merchant_logout(response: Response):
|
||||
path="/merchants",
|
||||
)
|
||||
|
||||
# Also clear legacy cookie with path=/ (from before path isolation was added)
|
||||
response.delete_cookie(
|
||||
key="merchant_token",
|
||||
path="/",
|
||||
)
|
||||
|
||||
logger.debug("Deleted merchant_token cookies (both /merchants and / paths)")
|
||||
logger.debug("Deleted merchant_token cookie (path=/merchants)")
|
||||
|
||||
return LogoutResponse(message="Logged out successfully")
|
||||
|
||||
@@ -17,8 +17,8 @@ from fastapi import APIRouter, Depends, Path
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.core.database import get_db
|
||||
from app.modules.tenancy.services.store_service import store_service # noqa: mod-004
|
||||
from app.modules.tenancy.schemas.store import StoreDetailResponse
|
||||
from app.modules.tenancy.services.store_service import store_service # noqa: mod-004
|
||||
|
||||
store_router = APIRouter()
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -21,11 +21,10 @@ from sqlalchemy.orm import Session
|
||||
from app.api.deps import get_current_store_api
|
||||
from app.core.database import get_db
|
||||
from app.core.environment import should_use_secure_cookies
|
||||
from app.modules.tenancy.exceptions import InvalidCredentialsException
|
||||
from app.modules.core.services.auth_service import auth_service
|
||||
from app.modules.tenancy.exceptions import InvalidCredentialsException
|
||||
from middleware.store_context import get_current_store
|
||||
from models.schema.auth import UserContext
|
||||
from models.schema.auth import LogoutResponse, UserLogin, StoreUserResponse
|
||||
from models.schema.auth import LogoutResponse, StoreUserResponse, UserContext, UserLogin
|
||||
|
||||
store_auth_router = APIRouter(prefix="/auth")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -13,9 +13,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_current_store_api
|
||||
from app.core.database import get_db
|
||||
from app.modules.tenancy.schemas.store import StoreResponse, StoreUpdate
|
||||
from app.modules.tenancy.services.store_service import store_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.schemas.store import StoreResponse, StoreUpdate
|
||||
|
||||
store_profile_router = APIRouter(prefix="/profile")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -22,10 +22,6 @@ from app.api.deps import (
|
||||
require_store_permission,
|
||||
)
|
||||
from app.core.database import get_db
|
||||
# Permission IDs are now defined in module definition.py files
|
||||
# and discovered by PermissionDiscoveryService
|
||||
from app.modules.tenancy.services.store_team_service import store_team_service
|
||||
from models.schema.auth import UserContext
|
||||
from app.modules.tenancy.schemas.team import (
|
||||
BulkRemoveRequest,
|
||||
BulkRemoveResponse,
|
||||
@@ -41,6 +37,11 @@ from app.modules.tenancy.schemas.team import (
|
||||
UserPermissionsResponse,
|
||||
)
|
||||
|
||||
# Permission IDs are now defined in module definition.py files
|
||||
# and discovered by PermissionDiscoveryService
|
||||
from app.modules.tenancy.services.store_team_service import store_team_service
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
store_team_router = APIRouter(prefix="/team")
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -268,7 +269,7 @@ def update_team_member(
|
||||
"""
|
||||
store = request.state.store
|
||||
|
||||
store_user = store_team_service.update_member_role(
|
||||
store_team_service.update_member_role(
|
||||
db=db,
|
||||
store=store,
|
||||
user_id=user_id,
|
||||
|
||||
@@ -17,9 +17,9 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.api.deps import get_db, require_menu_access
|
||||
from app.modules.core.utils.page_context import get_admin_context
|
||||
from app.templates_config import templates
|
||||
from app.modules.enums import FrontendType
|
||||
from app.modules.tenancy.models import User
|
||||
from app.templates_config import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -20,8 +20,8 @@ from app.api.deps import (
|
||||
get_db,
|
||||
)
|
||||
from app.modules.core.utils.page_context import get_store_context
|
||||
from app.templates_config import templates
|
||||
from app.modules.tenancy.models import User
|
||||
from app.templates_config import templates
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -6,30 +6,6 @@ Request/response schemas for platform, merchant, store, admin user, and team man
|
||||
"""
|
||||
|
||||
# Merchant schemas
|
||||
from app.modules.tenancy.schemas.merchant import (
|
||||
MerchantBase,
|
||||
MerchantCreate,
|
||||
MerchantCreateResponse,
|
||||
MerchantDetailResponse,
|
||||
MerchantListResponse,
|
||||
MerchantResponse,
|
||||
MerchantSummary,
|
||||
MerchantTransferOwnership,
|
||||
MerchantTransferOwnershipResponse,
|
||||
MerchantUpdate,
|
||||
)
|
||||
|
||||
# Store schemas
|
||||
from app.modules.tenancy.schemas.store import (
|
||||
StoreCreate,
|
||||
StoreCreateResponse,
|
||||
StoreDetailResponse,
|
||||
StoreListResponse,
|
||||
StoreResponse,
|
||||
StoreSummary,
|
||||
StoreUpdate,
|
||||
)
|
||||
|
||||
# Admin schemas
|
||||
from app.modules.tenancy.schemas.admin import (
|
||||
AdminAuditLogFilters,
|
||||
@@ -50,10 +26,10 @@ from app.modules.tenancy.schemas.admin import (
|
||||
ApplicationLogFilters,
|
||||
ApplicationLogListResponse,
|
||||
ApplicationLogResponse,
|
||||
BulkUserAction,
|
||||
BulkUserActionResponse,
|
||||
BulkStoreAction,
|
||||
BulkStoreActionResponse,
|
||||
BulkUserAction,
|
||||
BulkUserActionResponse,
|
||||
ComponentHealthStatus,
|
||||
FileLogResponse,
|
||||
LogCleanupResponse,
|
||||
@@ -73,6 +49,43 @@ from app.modules.tenancy.schemas.admin import (
|
||||
RowsPerPageUpdateResponse,
|
||||
SystemHealthResponse,
|
||||
)
|
||||
from app.modules.tenancy.schemas.merchant import (
|
||||
MerchantBase,
|
||||
MerchantCreate,
|
||||
MerchantCreateResponse,
|
||||
MerchantDetailResponse,
|
||||
MerchantListResponse,
|
||||
MerchantPortalProfileResponse,
|
||||
MerchantPortalProfileUpdate,
|
||||
MerchantPortalStoreListResponse,
|
||||
MerchantResponse,
|
||||
MerchantSummary,
|
||||
MerchantTransferOwnership,
|
||||
MerchantTransferOwnershipResponse,
|
||||
MerchantUpdate,
|
||||
)
|
||||
|
||||
# Store schemas
|
||||
from app.modules.tenancy.schemas.store import (
|
||||
StoreCreate,
|
||||
StoreCreateResponse,
|
||||
StoreDetailResponse,
|
||||
StoreListResponse,
|
||||
StoreResponse,
|
||||
StoreSummary,
|
||||
StoreUpdate,
|
||||
)
|
||||
|
||||
# Store domain schemas
|
||||
from app.modules.tenancy.schemas.store_domain import (
|
||||
DomainDeletionResponse,
|
||||
DomainVerificationInstructions,
|
||||
DomainVerificationResponse,
|
||||
StoreDomainCreate,
|
||||
StoreDomainListResponse,
|
||||
StoreDomainResponse,
|
||||
StoreDomainUpdate,
|
||||
)
|
||||
|
||||
# Team schemas
|
||||
from app.modules.tenancy.schemas.team import (
|
||||
@@ -98,17 +111,6 @@ from app.modules.tenancy.schemas.team import (
|
||||
UserPermissionsResponse,
|
||||
)
|
||||
|
||||
# Store domain schemas
|
||||
from app.modules.tenancy.schemas.store_domain import (
|
||||
DomainDeletionResponse,
|
||||
DomainVerificationInstructions,
|
||||
DomainVerificationResponse,
|
||||
StoreDomainCreate,
|
||||
StoreDomainListResponse,
|
||||
StoreDomainResponse,
|
||||
StoreDomainUpdate,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# Merchant
|
||||
"MerchantBase",
|
||||
@@ -116,6 +118,9 @@ __all__ = [
|
||||
"MerchantCreateResponse",
|
||||
"MerchantDetailResponse",
|
||||
"MerchantListResponse",
|
||||
"MerchantPortalProfileResponse",
|
||||
"MerchantPortalProfileUpdate",
|
||||
"MerchantPortalStoreListResponse",
|
||||
"MerchantResponse",
|
||||
"MerchantSummary",
|
||||
"MerchantTransferOwnership",
|
||||
|
||||
@@ -10,6 +10,8 @@ from typing import Any
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
|
||||
|
||||
from app.modules.tenancy.schemas.store import StoreSummary
|
||||
|
||||
|
||||
class MerchantBase(BaseModel):
|
||||
"""Base schema for merchant with common fields."""
|
||||
@@ -214,3 +216,46 @@ class MerchantTransferOwnershipResponse(BaseModel):
|
||||
|
||||
transferred_at: datetime
|
||||
transfer_reason: str | None
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Merchant Portal Schemas (for merchant-facing routes)
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class MerchantPortalProfileResponse(BaseModel):
|
||||
"""Merchant profile as seen by the merchant owner."""
|
||||
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
id: int
|
||||
name: str
|
||||
description: str | None
|
||||
contact_email: str
|
||||
contact_phone: str | None
|
||||
website: str | None
|
||||
business_address: str | None
|
||||
tax_number: str | None
|
||||
is_verified: bool
|
||||
|
||||
|
||||
class MerchantPortalProfileUpdate(BaseModel):
|
||||
"""Merchant profile update from the merchant portal.
|
||||
Excludes admin-only fields (is_active, is_verified)."""
|
||||
|
||||
name: str | None = Field(None, min_length=2, max_length=200)
|
||||
description: str | None = None
|
||||
contact_email: EmailStr | None = None
|
||||
contact_phone: str | None = None
|
||||
website: str | None = None
|
||||
business_address: str | None = None
|
||||
tax_number: str | None = None
|
||||
|
||||
|
||||
class MerchantPortalStoreListResponse(BaseModel):
|
||||
"""Paginated store list for the merchant portal."""
|
||||
|
||||
stores: list[StoreSummary]
|
||||
total: int
|
||||
skip: int
|
||||
limit: int
|
||||
|
||||
@@ -84,7 +84,7 @@ class TeamMemberInvite(TeamMemberBase):
|
||||
)
|
||||
|
||||
@field_validator("role_name")
|
||||
def validate_role_name(cls, v):
|
||||
def validate_role_name(self, v):
|
||||
"""Validate role name is in allowed presets."""
|
||||
if v is not None:
|
||||
allowed_roles = ["manager", "staff", "support", "viewer", "marketing"]
|
||||
@@ -95,7 +95,7 @@ class TeamMemberInvite(TeamMemberBase):
|
||||
return v.lower() if v else v
|
||||
|
||||
@field_validator("custom_permissions")
|
||||
def validate_custom_permissions(cls, v, values):
|
||||
def validate_custom_permissions(self, v, values):
|
||||
"""Ensure either role_id/role_name OR custom_permissions is provided."""
|
||||
if v is not None and len(v) > 0:
|
||||
# If custom permissions provided, role_name should be provided too
|
||||
@@ -170,7 +170,7 @@ class InvitationAccept(BaseModel):
|
||||
last_name: str = Field(..., min_length=1, max_length=100)
|
||||
|
||||
@field_validator("password")
|
||||
def validate_password_strength(cls, v):
|
||||
def validate_password_strength(self, v):
|
||||
"""Validate password meets minimum requirements."""
|
||||
if len(v) < 8:
|
||||
raise ValueError("Password must be at least 8 characters long")
|
||||
|
||||
@@ -20,13 +20,15 @@ from app.modules.tenancy.services.admin_platform_service import (
|
||||
admin_platform_service,
|
||||
)
|
||||
from app.modules.tenancy.services.admin_service import AdminService, admin_service
|
||||
from app.modules.tenancy.services.merchant_service import MerchantService, merchant_service
|
||||
from app.modules.tenancy.services.merchant_service import (
|
||||
MerchantService,
|
||||
merchant_service,
|
||||
)
|
||||
from app.modules.tenancy.services.platform_service import (
|
||||
PlatformService,
|
||||
PlatformStats,
|
||||
platform_service,
|
||||
)
|
||||
from app.modules.tenancy.services.team_service import TeamService, team_service
|
||||
from app.modules.tenancy.services.store_domain_service import (
|
||||
StoreDomainService,
|
||||
store_domain_service,
|
||||
@@ -36,6 +38,7 @@ from app.modules.tenancy.services.store_team_service import (
|
||||
StoreTeamService,
|
||||
store_team_service,
|
||||
)
|
||||
from app.modules.tenancy.services.team_service import TeamService, team_service
|
||||
|
||||
__all__ = [
|
||||
# Store
|
||||
|
||||
@@ -20,9 +20,7 @@ from app.modules.tenancy.exceptions import (
|
||||
AdminOperationException,
|
||||
CannotModifySelfException,
|
||||
)
|
||||
from app.modules.tenancy.models import AdminPlatform
|
||||
from app.modules.tenancy.models import Platform
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.models import AdminPlatform, Platform, User
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -344,7 +342,6 @@ class AdminPlatformService:
|
||||
field="user_id",
|
||||
)
|
||||
|
||||
old_status = user.is_super_admin
|
||||
user.is_super_admin = is_super_admin
|
||||
user.updated_at = datetime.now(UTC)
|
||||
db.flush()
|
||||
|
||||
@@ -23,21 +23,18 @@ from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.exceptions import (
|
||||
AdminOperationException,
|
||||
CannotModifySelfException,
|
||||
StoreAlreadyExistsException,
|
||||
StoreNotFoundException,
|
||||
StoreVerificationException,
|
||||
UserAlreadyExistsException,
|
||||
UserCannotBeDeletedException,
|
||||
UserNotFoundException,
|
||||
UserRoleChangeException,
|
||||
UserStatusChangeException,
|
||||
StoreAlreadyExistsException,
|
||||
StoreNotFoundException,
|
||||
StoreVerificationException,
|
||||
)
|
||||
from middleware.auth import AuthManager
|
||||
from app.modules.tenancy.models import Merchant
|
||||
from app.modules.tenancy.models import Platform
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.models import Role, Store
|
||||
from app.modules.tenancy.models import Merchant, Platform, Role, Store, User
|
||||
from app.modules.tenancy.schemas.store import StoreCreate
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -564,7 +561,6 @@ class AdminService:
|
||||
store = self._get_store_by_id_or_raise(db, store_id)
|
||||
|
||||
try:
|
||||
original_status = store.is_active
|
||||
store.is_active = not store.is_active
|
||||
store.updated_at = datetime.now(UTC)
|
||||
db.flush()
|
||||
|
||||
@@ -80,7 +80,7 @@ class MerchantDomainService:
|
||||
"""
|
||||
try:
|
||||
# Verify merchant exists
|
||||
merchant = self._get_merchant_by_id_or_raise(db, merchant_id)
|
||||
self._get_merchant_by_id_or_raise(db, merchant_id)
|
||||
|
||||
# Check domain limit
|
||||
self._check_domain_limit(db, merchant_id)
|
||||
|
||||
@@ -12,10 +12,16 @@ import string
|
||||
from sqlalchemy import func, select
|
||||
from sqlalchemy.orm import Session, joinedload
|
||||
|
||||
from app.modules.tenancy.exceptions import MerchantNotFoundException, UserNotFoundException
|
||||
from app.modules.tenancy.models import Merchant
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.schemas.merchant import MerchantCreate, MerchantTransferOwnership, MerchantUpdate
|
||||
from app.modules.tenancy.exceptions import (
|
||||
MerchantNotFoundException,
|
||||
UserNotFoundException,
|
||||
)
|
||||
from app.modules.tenancy.models import Merchant, Store, User
|
||||
from app.modules.tenancy.schemas.merchant import (
|
||||
MerchantCreate,
|
||||
MerchantTransferOwnership,
|
||||
MerchantUpdate,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -320,6 +326,15 @@ class MerchantService:
|
||||
|
||||
return merchant, old_owner, new_owner
|
||||
|
||||
def get_merchant_stores(
|
||||
self, db: Session, merchant_id: int, skip: int = 0, limit: int = 100
|
||||
) -> tuple[list, int]:
|
||||
"""Get paginated stores for a merchant."""
|
||||
query = db.query(Store).filter(Store.merchant_id == merchant_id)
|
||||
total = query.count()
|
||||
stores = query.order_by(Store.id).offset(skip).limit(limit).all()
|
||||
return stores, total
|
||||
|
||||
def _generate_temp_password(self, length: int = 12) -> str:
|
||||
"""Generate secure temporary password."""
|
||||
alphabet = string.ascii_letters + string.digits + "!@#$%^&*"
|
||||
|
||||
@@ -32,8 +32,6 @@ Usage:
|
||||
import logging
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
from app.modules.base import PermissionDefinition
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
|
||||
@@ -17,12 +17,11 @@ from dataclasses import dataclass
|
||||
from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.cms.models import ContentPage
|
||||
from app.modules.tenancy.exceptions import (
|
||||
PlatformNotFoundException,
|
||||
)
|
||||
from app.modules.cms.models import ContentPage
|
||||
from app.modules.tenancy.models import Platform
|
||||
from app.modules.tenancy.models import StorePlatform
|
||||
from app.modules.tenancy.models import Platform, StorePlatform
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -159,7 +158,7 @@ class PlatformService:
|
||||
db.query(func.count(ContentPage.id))
|
||||
.filter(
|
||||
ContentPage.platform_id == platform_id,
|
||||
ContentPage.store_id == None,
|
||||
ContentPage.store_id is None,
|
||||
ContentPage.is_platform_page == True,
|
||||
)
|
||||
.scalar()
|
||||
@@ -182,7 +181,7 @@ class PlatformService:
|
||||
db.query(func.count(ContentPage.id))
|
||||
.filter(
|
||||
ContentPage.platform_id == platform_id,
|
||||
ContentPage.store_id == None,
|
||||
ContentPage.store_id is None,
|
||||
ContentPage.is_platform_page == False,
|
||||
)
|
||||
.scalar()
|
||||
@@ -205,7 +204,7 @@ class PlatformService:
|
||||
db.query(func.count(ContentPage.id))
|
||||
.filter(
|
||||
ContentPage.platform_id == platform_id,
|
||||
ContentPage.store_id != None,
|
||||
ContentPage.store_id is not None,
|
||||
)
|
||||
.scalar()
|
||||
or 0
|
||||
|
||||
@@ -29,9 +29,11 @@ from app.modules.tenancy.exceptions import (
|
||||
StoreDomainNotFoundException,
|
||||
StoreNotFoundException,
|
||||
)
|
||||
from app.modules.tenancy.models import Store
|
||||
from app.modules.tenancy.models import StoreDomain
|
||||
from app.modules.tenancy.schemas.store_domain import StoreDomainCreate, StoreDomainUpdate
|
||||
from app.modules.tenancy.models import Store, StoreDomain
|
||||
from app.modules.tenancy.schemas.store_domain import (
|
||||
StoreDomainCreate,
|
||||
StoreDomainUpdate,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -74,7 +76,7 @@ class StoreDomainService:
|
||||
"""
|
||||
try:
|
||||
# Verify store exists
|
||||
store = self._get_store_by_id_or_raise(db, store_id)
|
||||
self._get_store_by_id_or_raise(db, store_id)
|
||||
|
||||
# Check domain limit
|
||||
self._check_domain_limit(db, store_id)
|
||||
|
||||
@@ -18,12 +18,11 @@ from sqlalchemy.orm import Session
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.exceptions import (
|
||||
InvalidStoreDataException,
|
||||
UnauthorizedStoreAccessException,
|
||||
StoreAlreadyExistsException,
|
||||
StoreNotFoundException,
|
||||
UnauthorizedStoreAccessException,
|
||||
)
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.models import Store
|
||||
from app.modules.tenancy.models import Store, User
|
||||
from app.modules.tenancy.schemas.store import StoreCreate
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -489,10 +488,7 @@ class StoreService:
|
||||
return True
|
||||
|
||||
# Check if user is owner via StoreUser relationship
|
||||
if user.is_owner_of(store.id):
|
||||
return True
|
||||
|
||||
return False
|
||||
return bool(user.is_owner_of(store.id))
|
||||
|
||||
def update_store(
|
||||
self,
|
||||
|
||||
@@ -24,6 +24,7 @@ from app.modules.tenancy.services.permission_discovery_service import (
|
||||
def get_preset_permissions(preset_name: str) -> set[str]:
|
||||
"""Get permissions for a preset role."""
|
||||
return permission_discovery_service.get_preset_permissions(preset_name)
|
||||
from app.modules.billing.exceptions import TierLimitExceededException
|
||||
from app.modules.tenancy.exceptions import (
|
||||
CannotRemoveOwnerException,
|
||||
InvalidInvitationTokenException,
|
||||
@@ -31,10 +32,8 @@ from app.modules.tenancy.exceptions import (
|
||||
TeamMemberAlreadyExistsException,
|
||||
UserNotFoundException,
|
||||
)
|
||||
from app.modules.billing.exceptions import TierLimitExceededException
|
||||
from app.modules.tenancy.models import Role, Store, StoreUser, StoreUserType, User
|
||||
from middleware.auth import AuthManager
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.models import Role, Store, StoreUser, StoreUserType
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -15,8 +15,7 @@ from typing import Any
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.models import Role, StoreUser
|
||||
from app.modules.tenancy.models import Role, StoreUser, User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@ from sqlalchemy import func
|
||||
|
||||
from app.modules.contracts.features import (
|
||||
FeatureDeclaration,
|
||||
FeatureProviderProtocol,
|
||||
FeatureScope,
|
||||
FeatureType,
|
||||
FeatureUsage,
|
||||
@@ -113,9 +112,9 @@ class TenancyFeatureProvider:
|
||||
merchant_id: int,
|
||||
platform_id: int,
|
||||
) -> list[FeatureUsage]:
|
||||
from app.modules.tenancy.models.user import User
|
||||
from app.modules.tenancy.models.store import Store, StoreUser
|
||||
from app.modules.tenancy.models.store_platform import StorePlatform
|
||||
from app.modules.tenancy.models.user import User
|
||||
|
||||
# Count active users associated with stores owned by this merchant
|
||||
count = (
|
||||
|
||||
@@ -16,9 +16,8 @@ from sqlalchemy import func
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.contracts.metrics import (
|
||||
MetricValue,
|
||||
MetricsContext,
|
||||
MetricsProviderProtocol,
|
||||
MetricValue,
|
||||
)
|
||||
|
||||
if TYPE_CHECKING:
|
||||
@@ -124,7 +123,14 @@ class TenancyMetricsProvider:
|
||||
- Total users
|
||||
- Active users
|
||||
"""
|
||||
from app.modules.tenancy.models import AdminPlatform, Merchant, StoreUser, User, Store, StorePlatform
|
||||
from app.modules.tenancy.models import (
|
||||
AdminPlatform,
|
||||
Merchant,
|
||||
Store,
|
||||
StorePlatform,
|
||||
StoreUser,
|
||||
User,
|
||||
)
|
||||
|
||||
try:
|
||||
# Store metrics - using StorePlatform junction table
|
||||
|
||||
@@ -15,7 +15,6 @@ from sqlalchemy.orm import Session
|
||||
|
||||
from app.modules.contracts.widgets import (
|
||||
DashboardWidget,
|
||||
DashboardWidgetProviderProtocol,
|
||||
ListWidget,
|
||||
WidgetContext,
|
||||
WidgetListItem,
|
||||
|
||||
@@ -0,0 +1,317 @@
|
||||
# app/modules/tenancy/tests/integration/test_merchant_auth_routes.py
|
||||
"""
|
||||
Integration tests for merchant authentication API routes.
|
||||
|
||||
Tests the merchant auth endpoints at:
|
||||
/api/v1/merchants/auth/*
|
||||
|
||||
Uses real login flow (no dependency overrides) to verify JWT generation,
|
||||
cookie setting, and token validation end-to-end.
|
||||
"""
|
||||
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.tenancy.models import Merchant, User
|
||||
|
||||
# ============================================================================
|
||||
# Fixtures
|
||||
# ============================================================================
|
||||
|
||||
BASE = "/api/v1/merchants/auth"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ma_owner(db):
|
||||
"""Create a merchant owner user with known credentials."""
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
auth = AuthManager()
|
||||
uid = uuid.uuid4().hex[:8]
|
||||
user = User(
|
||||
email=f"maowner_{uid}@test.com",
|
||||
username=f"maowner_{uid}",
|
||||
hashed_password=auth.hash_password("mapass123"),
|
||||
role="store",
|
||||
is_active=True,
|
||||
)
|
||||
db.add(user)
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ma_merchant(db, ma_owner):
|
||||
"""Create a merchant owned by ma_owner."""
|
||||
merchant = Merchant(
|
||||
name="Auth Test Merchant",
|
||||
owner_user_id=ma_owner.id,
|
||||
contact_email=ma_owner.email,
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
)
|
||||
db.add(merchant)
|
||||
db.commit()
|
||||
db.refresh(merchant)
|
||||
return merchant
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ma_non_merchant_user(db):
|
||||
"""Create a user who does NOT own any merchants."""
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
auth = AuthManager()
|
||||
uid = uuid.uuid4().hex[:8]
|
||||
user = User(
|
||||
email=f"nonmerch_{uid}@test.com",
|
||||
username=f"nonmerch_{uid}",
|
||||
hashed_password=auth.hash_password("nonmerch123"),
|
||||
role="store",
|
||||
is_active=True,
|
||||
)
|
||||
db.add(user)
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def ma_inactive_user(db):
|
||||
"""Create an inactive user who owns a merchant."""
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
auth = AuthManager()
|
||||
uid = uuid.uuid4().hex[:8]
|
||||
user = User(
|
||||
email=f"inactive_{uid}@test.com",
|
||||
username=f"inactive_{uid}",
|
||||
hashed_password=auth.hash_password("inactive123"),
|
||||
role="store",
|
||||
is_active=False,
|
||||
)
|
||||
db.add(user)
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
|
||||
merchant = Merchant(
|
||||
name="Inactive Owner Merchant",
|
||||
owner_user_id=user.id,
|
||||
contact_email=user.email,
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
)
|
||||
db.add(merchant)
|
||||
db.commit()
|
||||
|
||||
return user
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Login Tests
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class TestMerchantLogin:
|
||||
"""Tests for POST /api/v1/merchants/auth/login."""
|
||||
|
||||
def test_login_success(self, client, ma_owner, ma_merchant):
|
||||
response = client.post(
|
||||
f"{BASE}/login",
|
||||
json={
|
||||
"email_or_username": ma_owner.username,
|
||||
"password": "mapass123",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "access_token" in data
|
||||
assert data["token_type"] == "bearer"
|
||||
assert "expires_in" in data
|
||||
assert "user" in data
|
||||
|
||||
def test_login_sets_cookie(self, client, ma_owner, ma_merchant):
|
||||
response = client.post(
|
||||
f"{BASE}/login",
|
||||
json={
|
||||
"email_or_username": ma_owner.username,
|
||||
"password": "mapass123",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
# Check Set-Cookie header
|
||||
cookies = response.headers.get_list("set-cookie") if hasattr(response.headers, "get_list") else [
|
||||
v for k, v in response.headers.items() if k.lower() == "set-cookie"
|
||||
]
|
||||
merchant_cookies = [c for c in cookies if "merchant_token" in c]
|
||||
assert len(merchant_cookies) > 0
|
||||
# Verify path restriction
|
||||
assert "path=/merchants" in merchant_cookies[0].lower() or "Path=/merchants" in merchant_cookies[0]
|
||||
|
||||
def test_login_wrong_password(self, client, ma_owner, ma_merchant):
|
||||
response = client.post(
|
||||
f"{BASE}/login",
|
||||
json={
|
||||
"email_or_username": ma_owner.username,
|
||||
"password": "wrong_password",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 401
|
||||
|
||||
def test_login_non_merchant_user(self, client, ma_non_merchant_user):
|
||||
response = client.post(
|
||||
f"{BASE}/login",
|
||||
json={
|
||||
"email_or_username": ma_non_merchant_user.username,
|
||||
"password": "nonmerch123",
|
||||
},
|
||||
)
|
||||
# Should fail because user doesn't own any merchants
|
||||
assert response.status_code in (401, 403)
|
||||
|
||||
def test_login_inactive_user(self, client, ma_inactive_user):
|
||||
response = client.post(
|
||||
f"{BASE}/login",
|
||||
json={
|
||||
"email_or_username": ma_inactive_user.username,
|
||||
"password": "inactive123",
|
||||
},
|
||||
)
|
||||
assert response.status_code in (401, 403)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Me Tests
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class TestMerchantMe:
|
||||
"""Tests for GET /api/v1/merchants/auth/me."""
|
||||
|
||||
def test_me_success(self, client, ma_owner, ma_merchant):
|
||||
# Login first to get token
|
||||
login_resp = client.post(
|
||||
f"{BASE}/login",
|
||||
json={
|
||||
"email_or_username": ma_owner.username,
|
||||
"password": "mapass123",
|
||||
},
|
||||
)
|
||||
assert login_resp.status_code == 200
|
||||
token = login_resp.json()["access_token"]
|
||||
|
||||
# Call /me with the token
|
||||
response = client.get(
|
||||
f"{BASE}/me",
|
||||
headers={"Authorization": f"Bearer {token}"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["username"] == ma_owner.username
|
||||
assert data["email"] == ma_owner.email
|
||||
|
||||
def test_me_no_token(self, client):
|
||||
response = client.get(f"{BASE}/me")
|
||||
assert response.status_code in (401, 403)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Logout Tests
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class TestMerchantLogout:
|
||||
"""Tests for POST /api/v1/merchants/auth/logout."""
|
||||
|
||||
def test_logout_clears_cookie(self, client, ma_owner, ma_merchant):
|
||||
# Login first
|
||||
login_resp = client.post(
|
||||
f"{BASE}/login",
|
||||
json={
|
||||
"email_or_username": ma_owner.username,
|
||||
"password": "mapass123",
|
||||
},
|
||||
)
|
||||
assert login_resp.status_code == 200
|
||||
|
||||
# Logout
|
||||
response = client.post(f"{BASE}/logout")
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "message" in data
|
||||
|
||||
# Check that cookie deletion is in response
|
||||
cookies = [
|
||||
v for k, v in response.headers.items() if k.lower() == "set-cookie"
|
||||
]
|
||||
merchant_cookies = [c for c in cookies if "merchant_token" in c]
|
||||
assert len(merchant_cookies) > 0
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Auth Failure & Isolation Tests
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class TestMerchantAuthFailures:
|
||||
"""Tests for authentication edge cases and cross-portal isolation."""
|
||||
|
||||
def test_expired_token_rejected(self, client, ma_owner, ma_merchant):
|
||||
"""An expired JWT should be rejected."""
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
from jose import jwt
|
||||
|
||||
# Create an already-expired token
|
||||
payload = {
|
||||
"sub": str(ma_owner.id),
|
||||
"username": ma_owner.username,
|
||||
"email": ma_owner.email,
|
||||
"role": ma_owner.role,
|
||||
"exp": datetime.now(UTC) - timedelta(hours=1),
|
||||
"iat": datetime.now(UTC) - timedelta(hours=2),
|
||||
}
|
||||
import os
|
||||
secret = os.getenv("JWT_SECRET_KEY", "your-secret-key-change-in-production-please")
|
||||
expired_token = jwt.encode(payload, secret, algorithm="HS256")
|
||||
|
||||
response = client.get(
|
||||
f"{BASE}/me",
|
||||
headers={"Authorization": f"Bearer {expired_token}"},
|
||||
)
|
||||
assert response.status_code in (401, 403)
|
||||
|
||||
def test_invalid_token_rejected(self, client):
|
||||
"""A completely invalid token should be rejected."""
|
||||
response = client.get(
|
||||
f"{BASE}/me",
|
||||
headers={"Authorization": "Bearer invalid.token.here"},
|
||||
)
|
||||
assert response.status_code in (401, 403)
|
||||
|
||||
def test_store_token_not_accepted(self, client, db, ma_owner, ma_merchant):
|
||||
"""A store-context token should not grant merchant /me access.
|
||||
|
||||
Store tokens include token_type=store which the merchant auth
|
||||
dependency does not accept.
|
||||
"""
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
auth = AuthManager()
|
||||
# Create a real token for the user, but with store context
|
||||
token_data = auth.create_access_token(
|
||||
user=ma_owner,
|
||||
store_id=999,
|
||||
store_code="FAKE_STORE",
|
||||
store_role="owner",
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
f"{BASE}/me",
|
||||
headers={"Authorization": f"Bearer {token_data['access_token']}"},
|
||||
)
|
||||
# Store tokens should be rejected at merchant endpoints
|
||||
# (they have store context which merchant auth doesn't accept)
|
||||
assert response.status_code in (401, 403)
|
||||
233
app/modules/tenancy/tests/integration/test_merchant_routes.py
Normal file
233
app/modules/tenancy/tests/integration/test_merchant_routes.py
Normal file
@@ -0,0 +1,233 @@
|
||||
# app/modules/tenancy/tests/integration/test_merchant_routes.py
|
||||
"""
|
||||
Integration tests for merchant portal tenancy API routes.
|
||||
|
||||
Tests the merchant portal endpoints at:
|
||||
/api/v1/merchants/account/*
|
||||
|
||||
Authentication: Overrides get_merchant_for_current_user and
|
||||
get_current_merchant_api with mocks that return the test merchant/user.
|
||||
"""
|
||||
|
||||
import uuid
|
||||
|
||||
import pytest
|
||||
|
||||
from app.api.deps import get_current_merchant_api, get_merchant_for_current_user
|
||||
from app.modules.tenancy.models import Merchant, Store, User
|
||||
from main import app
|
||||
from models.schema.auth import UserContext
|
||||
|
||||
# ============================================================================
|
||||
# Fixtures
|
||||
# ============================================================================
|
||||
|
||||
BASE = "/api/v1/merchants/account"
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mt_owner(db):
|
||||
"""Create a merchant owner user."""
|
||||
from middleware.auth import AuthManager
|
||||
|
||||
auth = AuthManager()
|
||||
uid = uuid.uuid4().hex[:8]
|
||||
user = User(
|
||||
email=f"mtowner_{uid}@test.com",
|
||||
username=f"mtowner_{uid}",
|
||||
hashed_password=auth.hash_password("mtpass123"),
|
||||
role="store",
|
||||
is_active=True,
|
||||
)
|
||||
db.add(user)
|
||||
db.commit()
|
||||
db.refresh(user)
|
||||
return user
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mt_merchant(db, mt_owner):
|
||||
"""Create a merchant owned by mt_owner."""
|
||||
merchant = Merchant(
|
||||
name="Merchant Portal Test",
|
||||
description="A test merchant for portal routes",
|
||||
owner_user_id=mt_owner.id,
|
||||
contact_email=mt_owner.email,
|
||||
contact_phone="+352 123 456",
|
||||
website="https://example.com",
|
||||
business_address="1 Rue Test, Luxembourg",
|
||||
tax_number="LU12345678",
|
||||
is_active=True,
|
||||
is_verified=True,
|
||||
)
|
||||
db.add(merchant)
|
||||
db.commit()
|
||||
db.refresh(merchant)
|
||||
return merchant
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mt_stores(db, mt_merchant):
|
||||
"""Create stores for the merchant."""
|
||||
stores = []
|
||||
for i in range(3):
|
||||
uid = uuid.uuid4().hex[:8]
|
||||
store = Store(
|
||||
merchant_id=mt_merchant.id,
|
||||
store_code=f"MT_{uid.upper()}",
|
||||
subdomain=f"mtstore{uid}",
|
||||
name=f"MT Store {i}",
|
||||
is_active=i < 2, # Third store inactive
|
||||
is_verified=True,
|
||||
)
|
||||
db.add(store)
|
||||
stores.append(store)
|
||||
db.commit()
|
||||
for s in stores:
|
||||
db.refresh(s)
|
||||
return stores
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mt_auth(mt_owner, mt_merchant):
|
||||
"""Override auth dependencies to return the test merchant/user."""
|
||||
user_context = UserContext(
|
||||
id=mt_owner.id,
|
||||
email=mt_owner.email,
|
||||
username=mt_owner.username,
|
||||
role="store",
|
||||
is_active=True,
|
||||
)
|
||||
|
||||
def _override_merchant():
|
||||
return mt_merchant
|
||||
|
||||
def _override_user():
|
||||
return user_context
|
||||
|
||||
app.dependency_overrides[get_merchant_for_current_user] = _override_merchant
|
||||
app.dependency_overrides[get_current_merchant_api] = _override_user
|
||||
yield {"Authorization": "Bearer fake-token"}
|
||||
app.dependency_overrides.pop(get_merchant_for_current_user, None)
|
||||
app.dependency_overrides.pop(get_current_merchant_api, None)
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Store Endpoints
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class TestMerchantStoresList:
|
||||
"""Tests for GET /api/v1/merchants/account/stores."""
|
||||
|
||||
def test_list_stores_success(self, client, mt_auth, mt_stores):
|
||||
response = client.get(f"{BASE}/stores", headers=mt_auth)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert "stores" in data
|
||||
assert "total" in data
|
||||
assert data["total"] == 3
|
||||
|
||||
def test_list_stores_response_shape(self, client, mt_auth, mt_stores):
|
||||
response = client.get(f"{BASE}/stores", headers=mt_auth)
|
||||
assert response.status_code == 200
|
||||
store = response.json()["stores"][0]
|
||||
assert "id" in store
|
||||
assert "name" in store
|
||||
assert "store_code" in store
|
||||
assert "is_active" in store
|
||||
assert "subdomain" in store
|
||||
|
||||
def test_list_stores_pagination(self, client, mt_auth, mt_stores):
|
||||
response = client.get(
|
||||
f"{BASE}/stores",
|
||||
params={"skip": 0, "limit": 2},
|
||||
headers=mt_auth,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data["stores"]) == 2
|
||||
assert data["total"] == 3
|
||||
assert data["skip"] == 0
|
||||
assert data["limit"] == 2
|
||||
|
||||
def test_list_stores_empty(self, client, mt_auth, mt_merchant):
|
||||
response = client.get(f"{BASE}/stores", headers=mt_auth)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["stores"] == []
|
||||
assert data["total"] == 0
|
||||
|
||||
|
||||
# ============================================================================
|
||||
# Profile Endpoints
|
||||
# ============================================================================
|
||||
|
||||
|
||||
class TestMerchantProfile:
|
||||
"""Tests for GET/PUT /api/v1/merchants/account/profile."""
|
||||
|
||||
def test_get_profile_success(self, client, mt_auth, mt_merchant):
|
||||
response = client.get(f"{BASE}/profile", headers=mt_auth)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["id"] == mt_merchant.id
|
||||
assert data["name"] == "Merchant Portal Test"
|
||||
assert data["description"] == "A test merchant for portal routes"
|
||||
assert data["contact_email"] == mt_merchant.contact_email
|
||||
assert data["contact_phone"] == "+352 123 456"
|
||||
assert data["website"] == "https://example.com"
|
||||
assert data["business_address"] == "1 Rue Test, Luxembourg"
|
||||
assert data["tax_number"] == "LU12345678"
|
||||
assert data["is_verified"] is True
|
||||
|
||||
def test_get_profile_all_fields_present(self, client, mt_auth, mt_merchant):
|
||||
response = client.get(f"{BASE}/profile", headers=mt_auth)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
expected_fields = {
|
||||
"id", "name", "description", "contact_email", "contact_phone",
|
||||
"website", "business_address", "tax_number", "is_verified",
|
||||
}
|
||||
assert expected_fields.issubset(set(data.keys()))
|
||||
|
||||
def test_update_profile_partial(self, client, mt_auth, mt_merchant):
|
||||
response = client.put(
|
||||
f"{BASE}/profile",
|
||||
json={"name": "Updated Merchant Name"},
|
||||
headers=mt_auth,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert data["name"] == "Updated Merchant Name"
|
||||
# Other fields should remain unchanged
|
||||
assert data["contact_phone"] == "+352 123 456"
|
||||
|
||||
def test_update_profile_email_validation(self, client, mt_auth, mt_merchant):
|
||||
response = client.put(
|
||||
f"{BASE}/profile",
|
||||
json={"contact_email": "not-an-email"},
|
||||
headers=mt_auth,
|
||||
)
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_update_profile_cannot_set_admin_fields(self, client, mt_auth, mt_merchant):
|
||||
"""Admin-only fields (is_active, is_verified) are not accepted."""
|
||||
response = client.put(
|
||||
f"{BASE}/profile",
|
||||
json={"is_active": False, "is_verified": False},
|
||||
headers=mt_auth,
|
||||
)
|
||||
# Should succeed but ignore unknown fields (Pydantic extra="ignore" by default)
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
# is_verified should remain True (not changed)
|
||||
assert data["is_verified"] is True
|
||||
|
||||
def test_update_profile_name_too_short(self, client, mt_auth, mt_merchant):
|
||||
response = client.put(
|
||||
f"{BASE}/profile",
|
||||
json={"name": "A"},
|
||||
headers=mt_auth,
|
||||
)
|
||||
assert response.status_code == 422
|
||||
@@ -8,7 +8,10 @@ Tests the admin platform assignment service operations.
|
||||
import pytest
|
||||
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.exceptions import AdminOperationException, CannotModifySelfException
|
||||
from app.modules.tenancy.exceptions import (
|
||||
AdminOperationException,
|
||||
CannotModifySelfException,
|
||||
)
|
||||
from app.modules.tenancy.services.admin_platform_service import AdminPlatformService
|
||||
|
||||
|
||||
@@ -242,8 +245,7 @@ class TestAdminPlatformServiceQueries:
|
||||
self, db, test_platform_admin, test_platform, test_super_admin, auth_manager
|
||||
):
|
||||
"""Test getting admins for a platform."""
|
||||
from app.modules.tenancy.models import AdminPlatform
|
||||
from app.modules.tenancy.models import User
|
||||
from app.modules.tenancy.models import AdminPlatform, User
|
||||
|
||||
service = AdminPlatformService()
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import pytest
|
||||
from app.modules.tenancy.models.merchant_domain import MerchantDomain
|
||||
from app.modules.tenancy.models.store_domain import StoreDomain
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# MODEL TESTS
|
||||
# =============================================================================
|
||||
|
||||
@@ -6,11 +6,9 @@ from datetime import UTC, datetime
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app.modules.tenancy.exceptions import (
|
||||
DNSVerificationException,
|
||||
DomainAlreadyVerifiedException,
|
||||
DomainNotVerifiedException,
|
||||
DomainVerificationFailedException,
|
||||
@@ -29,7 +27,6 @@ from app.modules.tenancy.services.merchant_domain_service import (
|
||||
merchant_domain_service,
|
||||
)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# ADD DOMAIN TESTS
|
||||
# =============================================================================
|
||||
|
||||
@@ -6,11 +6,9 @@ from datetime import UTC, datetime
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from app.modules.tenancy.exceptions import (
|
||||
DNSVerificationException,
|
||||
DomainAlreadyVerifiedException,
|
||||
DomainNotVerifiedException,
|
||||
DomainVerificationFailedException,
|
||||
@@ -20,10 +18,12 @@ from app.modules.tenancy.exceptions import (
|
||||
StoreNotFoundException,
|
||||
)
|
||||
from app.modules.tenancy.models import StoreDomain
|
||||
from app.modules.tenancy.schemas.store_domain import StoreDomainCreate, StoreDomainUpdate
|
||||
from app.modules.tenancy.schemas.store_domain import (
|
||||
StoreDomainCreate,
|
||||
StoreDomainUpdate,
|
||||
)
|
||||
from app.modules.tenancy.services.store_domain_service import store_domain_service
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# FIXTURES
|
||||
# =============================================================================
|
||||
|
||||
@@ -12,14 +12,13 @@ import pytest
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.exceptions import (
|
||||
InvalidStoreDataException,
|
||||
UnauthorizedStoreAccessException,
|
||||
StoreAlreadyExistsException,
|
||||
StoreNotFoundException,
|
||||
UnauthorizedStoreAccessException,
|
||||
)
|
||||
from app.modules.tenancy.services.store_service import StoreService
|
||||
from app.modules.tenancy.models import Merchant
|
||||
from app.modules.tenancy.models import Store
|
||||
from app.modules.tenancy.models import Merchant, Store
|
||||
from app.modules.tenancy.schemas.store import StoreCreate
|
||||
from app.modules.tenancy.services.store_service import StoreService
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
||||
@@ -3,21 +3,17 @@
|
||||
|
||||
import uuid
|
||||
from datetime import datetime, timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.tenancy.exceptions import (
|
||||
CannotRemoveOwnerException,
|
||||
InvalidInvitationTokenException,
|
||||
TeamInvitationAlreadyAcceptedException,
|
||||
TeamMemberAlreadyExistsException,
|
||||
UserNotFoundException,
|
||||
)
|
||||
from app.modules.tenancy.models import Role, User, Store, StoreUser, StoreUserType
|
||||
from app.modules.tenancy.models import Role, Store, StoreUser, StoreUserType, User
|
||||
from app.modules.tenancy.services.store_team_service import store_team_service
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# FIXTURES
|
||||
# =============================================================================
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
import pytest
|
||||
|
||||
from app.modules.tenancy.models import Role, Store, StoreUser
|
||||
from app.modules.tenancy.models import Role, StoreUser
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
@@ -10,14 +10,12 @@ Tests cover:
|
||||
- Get store roles
|
||||
"""
|
||||
|
||||
from datetime import UTC, datetime
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from app.exceptions import ValidationException
|
||||
from app.modules.tenancy.services.team_service import TeamService, team_service
|
||||
from app.modules.tenancy.models import Role, StoreUser
|
||||
from app.modules.tenancy.services.team_service import TeamService, team_service
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
|
||||
Reference in New Issue
Block a user