#!/usr/bin/env python3 """ 로트 배분 검증 테스트 - 재고 부족 및 잘못된 배분 테스트 """ import json import requests BASE_URL = "http://localhost:5001" def test_insufficient_stock(): print("=== 로트 배분 검증 테스트 ===\n") # 1. 배분 합계가 맞지 않는 경우 print("1. 배분 합계가 필요량과 맞지 않는 경우") compound_data = { "patient_id": 1, "formula_id": None, "je_count": 1, "cheop_total": 1, "pouch_total": 1, "ingredients": [ { "herb_item_id": 63, "grams_per_cheop": 100.0, "total_grams": 100.0, "origin": "manual", "lot_assignments": [ {"lot_id": 208, "quantity": 50.0}, # 50g {"lot_id": 219, "quantity": 30.0} # 30g = 총 80g (100g 필요) ] } ] } response = requests.post(f"{BASE_URL}/api/compounds", json=compound_data, headers={"Content-Type": "application/json"}) if response.status_code != 200: result = response.json() print(f" ✅ 예상된 오류 발생: {result.get('error')}") else: print(f" ❌ 오류가 발생해야 하는데 성공함") # 2. 로트 재고가 부족한 경우 print("\n2. 로트 재고가 부족한 경우") compound_data = { "patient_id": 1, "formula_id": None, "je_count": 1, "cheop_total": 1, "pouch_total": 1, "ingredients": [ { "herb_item_id": 63, "grams_per_cheop": 5000.0, # 5000g 요청 "total_grams": 5000.0, "origin": "manual", "lot_assignments": [ {"lot_id": 208, "quantity": 5000.0} # 로트 208에 5000g 요청 (실제로는 4784g만 있음) ] } ] } response = requests.post(f"{BASE_URL}/api/compounds", json=compound_data, headers={"Content-Type": "application/json"}) if response.status_code != 200: result = response.json() print(f" ✅ 예상된 오류 발생: {result.get('error')}") else: print(f" ❌ 오류가 발생해야 하는데 성공함") # 3. 존재하지 않는 로트 print("\n3. 존재하지 않는 로트 ID 사용") compound_data = { "patient_id": 1, "formula_id": None, "je_count": 1, "cheop_total": 1, "pouch_total": 1, "ingredients": [ { "herb_item_id": 63, "grams_per_cheop": 10.0, "total_grams": 10.0, "origin": "manual", "lot_assignments": [ {"lot_id": 99999, "quantity": 10.0} # 존재하지 않는 로트 ] } ] } response = requests.post(f"{BASE_URL}/api/compounds", json=compound_data, headers={"Content-Type": "application/json"}) if response.status_code != 200: result = response.json() print(f" ✅ 예상된 오류 발생: {result.get('error')}") else: print(f" ❌ 오류가 발생해야 하는데 성공함") print("\n✅ 모든 검증 테스트 완료 - 잘못된 요청을 올바르게 거부함") if __name__ == "__main__": test_insufficient_stock()