AdSafeLight / backend /scripts /test_law_api.py
Gae Zang
feat: setup Docker and CI/CD deploy pipeline for Hugging Face Space
b0fb923
Raw
History Blame Contribute Delete
1.94 kB
import sys
from pathlib import Path
# ๋ฐฑ์—”๋“œ ๊ฒฝ๋กœ ์„ค์ •
SCRIPTS_DIR = Path(__file__).resolve().parent
BACKEND_DIR = SCRIPTS_DIR.parent
sys.path.append(str(BACKEND_DIR))
from app.utils.law_api import law_api
def test_api():
print("=== [๊ตญ๊ฐ€๋ฒ•๋ น์ •๋ณด Open API ๊ธฐ๋Šฅ ๊ฒ€์ฆ ํ…Œ์ŠคํŠธ] ===")
# 1. ํ‘œ์‹œ๊ด‘๊ณ ๋ฒ• ๊ฒ€์ƒ‰
print("\n[Step 1] 'ํ‘œ์‹œ๊ด‘๊ณ ์˜ ๊ณต์ •ํ™”' MST ๊ฒ€์ƒ‰ ์ค‘...")
mst = law_api.search_law_mst("ํ‘œ์‹œ๊ด‘๊ณ ์˜ ๊ณต์ •ํ™”")
if not mst:
print("[Fail] 'ํ‘œ์‹œ๊ด‘๊ณ ์˜ ๊ณต์ •ํ™”' ์ผ๋ จ๋ฒˆํ˜ธ๋ฅผ ๊ฒ€์ƒ‰ํ•˜์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. API ํ‚ค๋‚˜ ๋„คํŠธ์›Œํฌ๋ฅผ ์ ๊ฒ€ํ•˜์„ธ์š”.")
return False
print(f"[Success] 'ํ‘œ์‹œ๊ด‘๊ณ ์˜ ๊ณต์ •ํ™”' MST ํš๋“: {mst}")
# 2. ํ‘œ์‹œ๊ด‘๊ณ ๋ฒ• ์ƒ์„ธ ์กฐ๋ฌธ ์กฐํšŒ
print("\n[Step 2] 'ํ‘œ์‹œ๊ด‘๊ณ ์˜ ๊ณต์ •ํ™”' ์กฐ๋ฌธ ๋ฐ์ดํ„ฐ ์กฐํšŒ ์ค‘...")
detail_text = law_api.get_law_detail_text(mst, limit_clause_count=5)
if not detail_text or "ํŒŒ์‹ฑ" in detail_text:
print("[Fail] ์กฐ๋ฌธ ๋ฐ์ดํ„ฐ๋ฅผ ๋ถˆ๋Ÿฌ์˜ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค.")
return False
print("[Success] ์กฐ๋ฌธ ๋ฐ์ดํ„ฐ ์ผ๋ถ€ ์ถœ๋ ฅ:")
print("-" * 50)
# ํ•œ๊ธ€ ์ธ์ฝ”๋”ฉ ๊นจ์ง ๋ฐฉ์ง€ ์œ„ํ•ด ์ด๋ชจ์ง€ ๋ฐฐ์ œํ•˜์—ฌ ์ถœ๋ ฅ
print(detail_text[:600] + "\n...")
print("-" * 50)
# 3. ์‹ํ’ˆํ‘œ์‹œ๊ด‘๊ณ ๋ฒ• ์ถ”๊ฐ€ ํ…Œ์ŠคํŠธ
print("\n[Step 3] '์‹ํ’ˆ ๋“ฑ์˜ ํ‘œ์‹œ' ์ถ”๊ฐ€ ๊ฒ€์ƒ‰ ์ค‘...")
mst_food = law_api.search_law_mst("์‹ํ’ˆ ๋“ฑ์˜ ํ‘œ์‹œ")
if mst_food:
print(f"[Success] '์‹ํ’ˆ ๋“ฑ์˜ ํ‘œ์‹œ' MST ํš๋“: {mst_food}")
food_text = law_api.get_law_detail_text(mst_food, limit_clause_count=3)
print(food_text[:300] + "\n...")
return True
if __name__ == "__main__":
success = test_api()
if success:
print("\n[Result] All Open API tests passed successfully!")
sys.exit(0)
else:
print("\n[Result] Open API tests failed.")
sys.exit(1)