- test_integration.py: QR 토큰 생성 및 라벨 테스트 - samples/barcode_print.py: Brother QL 프린터 예제 - samples/barcode_reader_gui.py: 바코드 리더 GUI 참고 코드 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
99 lines
2.7 KiB
Python
99 lines
2.7 KiB
Python
"""
|
|
통합 테스트: QR 라벨 전체 흐름
|
|
토큰 생성 → DB 저장 → QR 라벨 이미지 생성
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
from datetime import datetime
|
|
|
|
# Path setup
|
|
sys.path.insert(0, os.path.join(os.path.dirname(__file__)))
|
|
|
|
from utils.qr_token_generator import generate_claim_token, save_token_to_db
|
|
from utils.qr_label_printer import print_qr_label
|
|
|
|
def test_full_flow():
|
|
"""전체 흐름 테스트"""
|
|
|
|
# 1. 테스트 데이터 (새로운 거래 ID)
|
|
test_tx_id = datetime.now().strftime("TEST%Y%m%d%H%M%S")
|
|
test_amount = 75000.0
|
|
test_time = datetime.now()
|
|
|
|
print("=" * 80)
|
|
print("QR 라벨 통합 테스트")
|
|
print("=" * 80)
|
|
print(f"거래 ID: {test_tx_id}")
|
|
print(f"판매 금액: {test_amount:,}원")
|
|
print()
|
|
|
|
# 2. 토큰 생성
|
|
print("[1/3] Claim Token 생성...")
|
|
token_info = generate_claim_token(test_tx_id, test_amount)
|
|
|
|
print(f" [OK] 토큰 원문: {token_info['token_raw'][:50]}...")
|
|
print(f" [OK] 토큰 해시: {token_info['token_hash'][:32]}...")
|
|
print(f" [OK] QR URL: {token_info['qr_url']}")
|
|
print(f" [OK] URL 길이: {len(token_info['qr_url'])} 문자")
|
|
print(f" [OK] 적립 포인트: {token_info['claimable_points']}P")
|
|
print()
|
|
|
|
# 3. DB 저장
|
|
print("[2/3] SQLite DB 저장...")
|
|
success, error = save_token_to_db(
|
|
test_tx_id,
|
|
token_info['token_hash'],
|
|
test_amount,
|
|
token_info['claimable_points'],
|
|
token_info['expires_at'],
|
|
token_info['pharmacy_id']
|
|
)
|
|
|
|
if not success:
|
|
print(f" [ERROR] DB 저장 실패: {error}")
|
|
return False
|
|
|
|
print(f" [OK] DB 저장 성공")
|
|
print()
|
|
|
|
# 4. QR 라벨 생성 (미리보기 모드)
|
|
print("[3/3] QR 라벨 이미지 생성...")
|
|
success, image_path = print_qr_label(
|
|
token_info['qr_url'],
|
|
test_tx_id,
|
|
test_amount,
|
|
token_info['claimable_points'],
|
|
test_time,
|
|
preview_mode=True
|
|
)
|
|
|
|
if not success:
|
|
print(f" [ERROR] 이미지 생성 실패")
|
|
return False
|
|
|
|
print(f" [OK] 이미지 저장: {image_path}")
|
|
print()
|
|
|
|
# 5. 결과 요약
|
|
print("=" * 80)
|
|
print("[SUCCESS] 통합 테스트 성공!")
|
|
print("=" * 80)
|
|
print(f"QR URL: {token_info['qr_url']}")
|
|
print(f"이미지 파일: {image_path}")
|
|
print(f"\n다음 명령으로 확인:")
|
|
print(f" start {image_path}")
|
|
print("=" * 80)
|
|
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
success = test_full_flow()
|
|
sys.exit(0 if success else 1)
|
|
except Exception as e:
|
|
print(f"\n[ERROR] 테스트 실패: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
sys.exit(1)
|