kdrug-inventory-system/dev_scripts/test_herb_info_page.py
시골약사 ad9ac396e2 chore: 개발 파일 정리 및 구조화
- 개발/테스트 스크립트를 dev_scripts/ 폴더로 이동
- 스크린샷을 screenshots/ 폴더로 이동
- 백업 파일 보존 (.backup)
- 처방 관련 추가 스크립트 포함

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-18 04:44:48 +00:00

193 lines
6.4 KiB
Python

#!/usr/bin/env python3
"""약재 정보 페이지 테스트 - 렌더링 문제 수정 후 검증"""
import requests
import json
import re
from datetime import datetime
BASE_URL = "http://localhost:5001"
def test_html_structure():
"""HTML 구조 검증 - herb-info가 content-area 안에 있는지 확인"""
print("1. HTML 구조 검증...")
response = requests.get(f"{BASE_URL}/")
if response.status_code != 200:
print(f" FAIL: 페이지 로드 실패 {response.status_code}")
return False
content = response.text
# herb-info가 col-md-10 content-area 안에 있는지 확인
idx_content = content.find('col-md-10 content-area')
idx_herb_info = content.find('id="herb-info"')
if idx_content < 0:
print(" FAIL: col-md-10 content-area 찾을 수 없음")
return False
if idx_herb_info < 0:
print(" FAIL: herb-info div 찾을 수 없음")
return False
if idx_herb_info > idx_content:
print(" PASS: herb-info가 content-area 안에 올바르게 위치함")
else:
print(" FAIL: herb-info가 content-area 밖에 있음!")
return False
# efficacyFilter ID 중복 검사
count_efficacy = content.count('id="efficacyFilter"')
if count_efficacy > 1:
print(f" FAIL: id=\"efficacyFilter\" 중복 {count_efficacy}개 발견!")
return False
else:
print(f" PASS: id=\"efficacyFilter\" 중복 없음 (개수: {count_efficacy})")
# herbInfoEfficacyFilter 존재 확인
if 'id="herbInfoEfficacyFilter"' in content:
print(" PASS: herbInfoEfficacyFilter ID 정상 존재")
else:
print(" FAIL: herbInfoEfficacyFilter ID 없음!")
return False
return True
def test_efficacy_tags():
"""효능 태그 조회 API 검증"""
print("\n2. 효능 태그 목록 조회...")
response = requests.get(f"{BASE_URL}/api/efficacy-tags")
if response.status_code != 200:
print(f" FAIL: {response.status_code}")
return False
tags = response.json()
if not isinstance(tags, list):
print(f" FAIL: 응답이 리스트가 아님 - {type(tags)}")
return False
print(f" PASS: {len(tags)}개의 효능 태그 조회 성공")
for tag in tags[:3]:
print(f" - {tag.get('name', '')}: {tag.get('description', '')}")
return True
def test_herb_masters_api():
"""약재 마스터 목록 + herb_id 포함 여부 검증"""
print("\n3. 약재 마스터 목록 조회 (herb_id 포함 여부 확인)...")
response = requests.get(f"{BASE_URL}/api/herbs/masters")
if response.status_code != 200:
print(f" FAIL: {response.status_code}")
return False
result = response.json()
if not result.get('success'):
print(f" FAIL: success=False")
return False
herbs = result.get('data', [])
print(f" PASS: {len(herbs)}개의 약재 조회 성공")
if not herbs:
print(" FAIL: 약재 데이터 없음")
return False
first = herbs[0]
# herb_id 확인
if 'herb_id' in first:
print(f" PASS: herb_id 필드 존재 (값: {first['herb_id']})")
else:
print(f" FAIL: herb_id 필드 누락! 키 목록: {list(first.keys())}")
return False
# ingredient_code 확인
if 'ingredient_code' in first:
print(f" PASS: ingredient_code 필드 존재")
else:
print(" FAIL: ingredient_code 필드 누락!")
return False
# efficacy_tags가 리스트인지 확인
if isinstance(first.get('efficacy_tags'), list):
print(f" PASS: efficacy_tags가 리스트 형식")
else:
print(f" FAIL: efficacy_tags 형식 오류: {first.get('efficacy_tags')}")
return False
return True
def test_herb_extended_info():
"""약재 확장 정보 조회 API 검증"""
print("\n4. 약재 확장 정보 조회 (herb_id=1 기준)...")
response = requests.get(f"{BASE_URL}/api/herbs/1/extended")
if response.status_code != 200:
print(f" FAIL: {response.status_code}")
return False
info = response.json()
if not isinstance(info, dict):
print(f" FAIL: 응답이 dict가 아님")
return False
print(f" PASS: herb_id=1 확장 정보 조회 성공")
print(f" - herb_name: {info.get('herb_name', '-')}")
print(f" - name_korean: {info.get('name_korean', '-')}")
print(f" - property: {info.get('property', '-')}")
return True
def test_herb_masters_has_extended_fields():
"""약재 마스터 목록에 확장 정보(property, main_effects)가 포함되는지 검증"""
print("\n5. 약재 마스터에 확장 정보 필드 포함 여부...")
response = requests.get(f"{BASE_URL}/api/herbs/masters")
result = response.json()
herbs = result.get('data', [])
required_fields = ['ingredient_code', 'herb_name', 'herb_id', 'has_stock',
'efficacy_tags', 'property', 'main_effects']
first = herbs[0] if herbs else {}
missing = [f for f in required_fields if f not in first]
if missing:
print(f" FAIL: 누락된 필드: {missing}")
return False
print(f" PASS: 필수 필드 모두 존재: {required_fields}")
return True
def main():
print("=== 약재 정보 페이지 렌더링 수정 검증 테스트 ===")
print(f"시간: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print(f"서버: {BASE_URL}")
print("-" * 50)
results = []
results.append(("HTML 구조 검증", test_html_structure()))
results.append(("효능 태그 API", test_efficacy_tags()))
results.append(("약재 마스터 API (herb_id)", test_herb_masters_api()))
results.append(("약재 확장 정보 API", test_herb_extended_info()))
results.append(("약재 마스터 필드 완전성", test_herb_masters_has_extended_fields()))
print("\n" + "=" * 50)
success = sum(1 for _, r in results if r)
total = len(results)
print(f"테스트 결과: {success}/{total} 성공")
for name, result in results:
status = "PASS" if result else "FAIL"
print(f" [{status}] {name}")
if success == total:
print("\n모든 테스트 통과. 약재 정보 페이지가 정상적으로 동작해야 합니다.")
else:
print(f"\n{total - success}개 테스트 실패. 추가 수정이 필요합니다.")
return success == total
if __name__ == "__main__":
main()