fix: route ordering bug and rewrite system error handling tests

- Move /health endpoint before /{slug} catch-all to prevent route conflict
- Rewrite system tests to use actual API endpoints:
  - /api/v1/admin/vendors (not /api/v1/vendor)
  - /api/v1/admin/products (not /api/v1/marketplace/product)
  - /api/v1/vendor/products (vendor context required)
- Update expected error codes to match actual API responses
- All 23 system error handling tests now pass

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-13 15:06:27 +01:00
parent e5cebc2fa5
commit f749cfc081
2 changed files with 230 additions and 361 deletions

83
main.py
View File

@@ -183,6 +183,50 @@ async def vendor_favicon():
return serve_favicon()
# ============================================================================
# HEALTH CHECK (Must be before catch-all routes)
# ============================================================================
@app.get("/health")
def health_check(db: Session = Depends(get_db)):
"""Health check endpoint"""
try:
# Test database connection
db.execute(text("SELECT 1"))
return {
"status": "healthy",
"timestamp": datetime.now(UTC),
"message": f"{settings.project_name} v{settings.version}",
"docs": {
"swagger": "/docs",
"redoc": "/redoc",
"openapi": "/openapi.json",
"complete": "/documentation",
},
"features": [
"Multi-tenant architecture with vendor isolation",
"JWT Authentication with role-based access control",
"Marketplace product import and curation",
"Vendor catalog management",
"Product-based inventory tracking",
"Stripe Connect payment processing",
],
"supported_marketplaces": [
"Letzshop",
],
"deployment_modes": [
"Subdomain-based (production): vendor.platform.com",
"Custom domain (production): customvendordomain.com",
"Path-based (development): /vendors/vendorname/ or /vendor/vendorname/",
],
"auth_required": "Most endpoints require Bearer token authentication",
}
except Exception as e:
logger.error(f"Health check failed: {e}")
raise ServiceUnavailableException("Service unhealthy")
# ============================================================================
# HTML PAGE ROUTES (Jinja2 Templates)
# ============================================================================
@@ -456,45 +500,6 @@ async def root(request: Request, db: Session = Depends(get_db)):
return RedirectResponse(url="/documentation")
@app.get("/health")
def health_check(db: Session = Depends(get_db)):
"""Health check endpoint"""
try:
# Test database connection
db.execute(text("SELECT 1"))
return {
"status": "healthy",
"timestamp": datetime.now(UTC),
"message": f"{settings.project_name} v{settings.version}",
"docs": {
"swagger": "/docs",
"redoc": "/redoc",
"openapi": "/openapi.json",
"complete": "/documentation",
},
"features": [
"Multi-tenant architecture with vendor isolation",
"JWT Authentication with role-based access control",
"Marketplace product import and curation",
"Vendor catalog management",
"Product-based inventory tracking",
"Stripe Connect payment processing",
],
"supported_marketplaces": [
"Letzshop",
],
"deployment_modes": [
"Subdomain-based (production): vendor.platform.com",
"Custom domain (production): customvendordomain.com",
"Path-based (development): /vendors/vendorname/ or /vendor/vendorname/",
],
"auth_required": "Most endpoints require Bearer token authentication",
}
except Exception as e:
logger.error(f"Health check failed: {e}")
raise ServiceUnavailableException("Service unhealthy")
@app.get("/documentation", response_class=HTMLResponse, include_in_schema=False)
async def documentation():
"""Redirect to documentation"""