kdrug-inventory-system/test_upload_api.py
시골약사 ae0d093044 test: 입고 프로세스 테스트 및 유틸리티 추가
추가된 파일:
1. reset_purchase_data.py
   - 입고 및 관련 데이터 초기화 스크립트
   - 조제, 재고, 입고장 데이터 완전 초기화
   - 잘못된 herb_items 정리 기능

2. test_improved_import.py
   - Excel 보험코드 9자리 패딩 테스트
   - 한의사랑/한의정보 형식 처리 확인

3. test_upload_api.py
   - API를 통한 Excel 업로드 테스트
   - 도매상 생성 및 입고 처리 검증
   - 재고 현황 확인

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

Co-Authored-By: Claude <noreply@anthropic.com>
2026-02-16 14:39:44 +00:00

97 lines
3.5 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
API를 통한 Excel 입고 처리 테스트
"""
import requests
import json
# API 베이스 URL
BASE_URL = "http://localhost:5001"
def test_upload_excel():
"""Excel 업로드 테스트"""
# 1. 도매상 목록 확인
print("=== 도매상 목록 확인 ===")
response = requests.get(f"{BASE_URL}/api/suppliers")
suppliers = response.json()
if suppliers['success'] and suppliers['data']:
print(f"✓ 도매상 {len(suppliers['data'])}개 조회")
supplier_id = suppliers['data'][0]['supplier_id']
supplier_name = suppliers['data'][0]['name']
print(f"✓ 선택된 도매상: {supplier_name} (ID: {supplier_id})")
else:
print("도매상이 없습니다. 새로 생성합니다.")
# 도매상 생성
supplier_data = {
'name': '한의정보',
'business_no': '123-45-67890',
'contact_person': '담당자',
'phone': '02-1234-5678'
}
response = requests.post(f"{BASE_URL}/api/suppliers", json=supplier_data)
result = response.json()
if result['success']:
supplier_id = result['supplier_id']
print(f"✓ 도매상 생성 완료 (ID: {supplier_id})")
else:
print(f"✗ 도매상 생성 실패: {result.get('error')}")
return
# 2. Excel 파일 업로드
print("\n=== Excel 파일 업로드 ===")
# 파일 열기
file_path = 'sample/한의정보.xlsx'
with open(file_path, 'rb') as f:
files = {'file': ('한의정보.xlsx', f, 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')}
data = {'supplier_id': supplier_id}
# 업로드
response = requests.post(f"{BASE_URL}/api/upload/purchase", files=files, data=data)
# 결과 확인
result = response.json()
if result['success']:
print(f"✓ 업로드 성공!")
print(f" - 형식: {result['summary']['format']}")
print(f" - 처리된 행: {result['summary']['processed_rows']}")
if 'processed_items' in result['summary']:
print(f" - 처리된 품목: {result['summary']['processed_items']}")
if 'total_amount' in result['summary']:
total = result['summary']['total_amount']
if isinstance(total, (int, float)):
print(f" - 총액: {total:,.0f}")
else:
print(f" - 총액: {total}")
else:
print(f"✗ 업로드 실패: {result.get('error')}")
# 3. 입고된 herb_items 확인
print("\n=== 입고된 herb_items 확인 ===")
response = requests.get(f"{BASE_URL}/api/herbs")
herbs = response.json()
if herbs['success']:
print(f"✓ 총 {len(herbs['data'])}개 herb_items")
# 샘플 출력
for herb in herbs['data'][:5]:
print(f" - {herb['herb_name']}: 보험코드={herb.get('insurance_code', 'N/A')}, 재고={herb.get('stock_quantity', 0):,.0f}g")
# 4. 재고 현황 확인
print("\n=== 재고 현황 확인 ===")
response = requests.get(f"{BASE_URL}/api/inventory/summary")
inventory = response.json()
if inventory['success']:
summary = inventory['data']
print(f"✓ 재고 요약:")
print(f" - 총 품목: {summary['total_items']}")
print(f" - 재고 있는 품목: {summary['items_with_stock']}")
print(f" - 총 재고 가치: {summary['total_value']:,.0f}")
if __name__ == "__main__":
test_upload_excel()