2ND
This commit is contained in:
126
test_org_search.py
Normal file
126
test_org_search.py
Normal file
@@ -0,0 +1,126 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
測試組織架構搜尋功能的獨立腳本
|
||||
根據您提供的組織架構圖進行測試
|
||||
"""
|
||||
|
||||
from ldap_utils import search_ldap_groups
|
||||
from app import app
|
||||
|
||||
def test_org_units():
|
||||
"""測試組織單位搜尋"""
|
||||
print("=== 測試組織單位搜尋 ===")
|
||||
|
||||
# 根據您的組織架構圖測試這些關鍵字
|
||||
test_terms = [
|
||||
"PANJIT", # 主要組織
|
||||
"Audit Office", # 稽核室
|
||||
"Fab bu", # 晶圓事業部
|
||||
"CFPU", # 客戶產品事業部
|
||||
"GMO", # 總經理室
|
||||
"RBU", # 新創事業處
|
||||
"kM_ESP", # 知識管理
|
||||
"SBG", # 特殊應用事業群
|
||||
"AUBU", # 車載事業處
|
||||
"IQBU", # 檢測事業處
|
||||
"MBU1", # 行銷事業處1
|
||||
"AssEng", # 製程工程
|
||||
"scottlee", # 個人帳號
|
||||
"staceychu", # 個人帳號
|
||||
"ymirliu" # 劉經理
|
||||
]
|
||||
|
||||
for term in test_terms:
|
||||
print(f"\n搜尋: '{term}'")
|
||||
print("-" * 50)
|
||||
|
||||
try:
|
||||
results = search_ldap_groups(term, limit=10)
|
||||
|
||||
if results:
|
||||
print(f"找到 {len(results)} 個結果:")
|
||||
for i, result in enumerate(results, 1):
|
||||
type_text = "組織單位" if result['type'] == 'organizationalUnit' else "群組"
|
||||
print(f" {i}. {result['name']} ({type_text})")
|
||||
print(f" 成員: {result['member_count']}")
|
||||
if result.get('email'):
|
||||
print(f" 郵件: {result['email']}")
|
||||
print(f" DN: {result['dn']}")
|
||||
print()
|
||||
else:
|
||||
print("沒有找到結果")
|
||||
|
||||
except Exception as e:
|
||||
print(f"搜尋錯誤: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
def test_specific_search():
|
||||
"""測試特定搜尋詞"""
|
||||
print("\n=== 特定搜尋測試 ===")
|
||||
|
||||
while True:
|
||||
term = input("\n請輸入要搜尋的組織名稱 (或輸入 'quit' 結束): ").strip()
|
||||
|
||||
if term.lower() == 'quit':
|
||||
break
|
||||
|
||||
if not term:
|
||||
continue
|
||||
|
||||
print(f"\n搜尋組織: '{term}'")
|
||||
print("-" * 40)
|
||||
|
||||
try:
|
||||
results = search_ldap_groups(term, limit=15)
|
||||
|
||||
if results:
|
||||
print(f"找到 {len(results)} 個組織:")
|
||||
for i, result in enumerate(results, 1):
|
||||
type_text = "組織單位" if result['type'] == 'organizationalUnit' else "群組"
|
||||
print(f"{i}. {result['name']} ({type_text}, 成員: {result['member_count']})")
|
||||
|
||||
# 提供選擇選項
|
||||
if results:
|
||||
choice = input(f"\n要查看哪個組織的詳細資訊? (1-{len(results)}, 或按 Enter 跳過): ").strip()
|
||||
if choice.isdigit() and 1 <= int(choice) <= len(results):
|
||||
selected = results[int(choice) - 1]
|
||||
print(f"\n{selected['name']} 詳細資訊:")
|
||||
print(f" 類型: {selected['type']}")
|
||||
print(f" 成員數: {selected['member_count']}")
|
||||
print(f" DN: {selected['dn']}")
|
||||
if selected.get('email'):
|
||||
print(f" 群組郵件: {selected['email']}")
|
||||
|
||||
else:
|
||||
print("沒有找到相符的組織")
|
||||
|
||||
except Exception as e:
|
||||
print(f"搜尋失敗: {e}")
|
||||
|
||||
def main():
|
||||
"""主測試函式"""
|
||||
print("組織架構搜尋測試工具")
|
||||
print("=" * 50)
|
||||
print("此工具將測試根據您的 AD 組織架構搜尋群組和組織單位")
|
||||
|
||||
with app.app_context():
|
||||
# 自動測試常見組織名稱
|
||||
test_org_units()
|
||||
|
||||
# 互動式測試
|
||||
choice = input("\n是否要進行互動式組織搜尋測試? (y/N): ").strip().lower()
|
||||
if choice == 'y':
|
||||
test_specific_search()
|
||||
|
||||
print("\n測試完成!")
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except KeyboardInterrupt:
|
||||
print("\n\n測試已中斷")
|
||||
except Exception as e:
|
||||
print(f"\n測試發生錯誤: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
Reference in New Issue
Block a user