Files
hr-portal/test_simple.py
Porsche Chen 360533393f feat: HR Portal - Complete Multi-Tenant System with Redis Session Storage
Major Features:
-  Multi-tenant architecture (tenant isolation)
-  Employee CRUD with lifecycle management (onboarding/offboarding)
-  Department tree structure with email domain management
-  Company info management (single-record editing)
-  System functions CRUD (permission management)
-  Email account management (multi-account per employee)
-  Keycloak SSO integration (auth.lab.taipei)
-  Redis session storage (10.1.0.254:6379)
  - Solves Cookie 4KB limitation
  - Cross-system session sharing
  - Sliding expiration (8 hours)
  - Automatic token refresh

Technical Stack:
Backend:
- FastAPI + SQLAlchemy
- PostgreSQL 16 (10.1.0.20:5433)
- Keycloak Admin API integration
- Docker Mailserver integration (SSH)
- Alembic migrations

Frontend:
- Next.js 14 (App Router)
- NextAuth 4 with Keycloak Provider
- Redis session storage (ioredis)
- Tailwind CSS

Infrastructure:
- Redis 7 (10.1.0.254:6379) - Session + Cache
- Keycloak 26.1.0 (auth.lab.taipei)
- Docker Mailserver (10.1.0.254)

Architecture Highlights:
- Session管理由 Keycloak + Redis 統一控制
- 支援多系統 (HR/WebMail/Calendar/Drive/Office) 共享 session
- Token 自動刷新,異質服務整合
- 未來可無縫遷移到雲端

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-23 20:12:43 +08:00

76 lines
2.2 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""簡單測試 HR Portal"""
import sys
import os
# 添加 backend 路徑
backend_path = os.path.join(os.path.dirname(__file__), 'backend')
sys.path.insert(0, backend_path)
print("=" * 60)
print("HR Portal 簡單測試")
print("=" * 60)
try:
# 載入環境變數
print("\n[1] 載入環境變數...")
from dotenv import load_dotenv
env_path = os.path.join(backend_path, '.env')
load_dotenv(env_path)
print(" [OK] 環境變數載入成功")
# 測試配置
print("\n[2] 測試配置...")
from app.core.config import settings
print(f" Project: {settings.PROJECT_NAME}")
print(f" Port: {settings.PORT}")
print(f" Database: {settings.DATABASE_URL[:50]}...")
# 測試資料庫連接
print("\n[3] 測試資料庫連接...")
from app.db.session import get_engine
from sqlalchemy import text
engine = get_engine()
with engine.connect() as conn:
result = conn.execute(text("SELECT version();"))
version = result.fetchone()[0]
print(f" [OK] PostgreSQL: {version[:60]}")
# 檢查資料表
result = conn.execute(text("""
SELECT COUNT(*) FROM information_schema.tables
WHERE table_schema = 'public'
"""))
table_count = result.fetchone()[0]
print(f" [OK] 資料表數量: {table_count}")
# 測試 FastAPI 應用
print("\n[4] 測試 FastAPI 應用...")
from app.main import app
print(f" [OK] App Title: {app.title}")
print(f" [OK] App Version: {app.version}")
# 列出路由
print("\n[5] API 端點數量:")
routes_count = 0
for route in app.routes:
if hasattr(route, 'methods'):
routes_count += len([m for m in route.methods if m != 'HEAD'])
print(f" [OK] {routes_count} 個端點")
print("\n" + "=" * 60)
print("測試全部通過!")
print("=" * 60)
print("\n啟動後端:")
print(" cd W:/DevOps-Workspace/5.Projects/hr-portal/backend")
print(" uvicorn app.main:app --host 0.0.0.0 --port 10181 --reload")
except Exception as e:
print(f"\n[FAIL] 測試失敗: {e}")
import traceback
traceback.print_exc()
sys.exit(1)