- internal_code DB 저장 → 프론트에서 선택한 제품 그대로 주문 - 기존 장바구니 백업/복구로 사용자 장바구니 보존 - 수인약품 submit_order() 수정 (체크박스 제외 방식) - 테스트 파일 정리 및 문서 추가
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""체크박스 로직 테스트 - 체크 안 함 vs 체크함"""
|
|
import sys; sys.path.insert(0, '.'); import wholesale_path
|
|
from wholesale import SooinSession
|
|
from bs4 import BeautifulSoup
|
|
import re
|
|
|
|
s = SooinSession()
|
|
s.login()
|
|
s.clear_cart()
|
|
|
|
# 장바구니에 품목 추가
|
|
result = s.search_products('코자정')
|
|
product = result['items'][0]
|
|
s.add_to_cart(product['internal_code'], qty=1, price=product['price'], stock=product['stock'])
|
|
|
|
print("="*60)
|
|
print("테스트 1: 체크박스 제외 (체크 안 함 = 주문 포함)")
|
|
print("="*60)
|
|
|
|
resp = s.session.get(f'{s.BAG_VIEW_URL}?currVenCd={s.vendor_code}', timeout=15)
|
|
soup = BeautifulSoup(resp.content, 'html.parser')
|
|
form = soup.find('form', {'id': 'frmBag'})
|
|
|
|
form_data = {}
|
|
for inp in form.find_all('input'):
|
|
name = inp.get('name', '')
|
|
if not name: continue
|
|
inp_type = inp.get('type', '').lower()
|
|
if inp_type == 'checkbox':
|
|
continue # 체크박스 제외!
|
|
form_data[name] = inp.get('value', '')
|
|
|
|
print(f"chk_0 전송됨? {'chk_0' in form_data}")
|
|
print(f"intArray: {form_data.get('intArray')}")
|
|
|
|
resp = s.session.post(
|
|
s.ORDER_END_URL,
|
|
data=form_data,
|
|
headers={'Content-Type': 'application/x-www-form-urlencoded'},
|
|
timeout=30
|
|
)
|
|
|
|
alert_match = re.search(r'alert\("([^"]*)"\)', resp.text)
|
|
alert_msg = alert_match.group(1) if alert_match else ''
|
|
print(f"응답 alert: '{alert_msg}'")
|
|
|
|
# 장바구니 확인
|
|
resp2 = s.session.get(f'{s.BAG_VIEW_URL}?currVenCd={s.vendor_code}', timeout=15)
|
|
soup2 = BeautifulSoup(resp2.content, 'html.parser')
|
|
int_array = soup2.find('input', {'name': 'intArray'})
|
|
val = int_array.get('value') if int_array else 'N/A'
|
|
print(f"주문 후 intArray: {val}")
|
|
|
|
if '주문이 완료' in alert_msg:
|
|
print("✅ 성공!")
|
|
else:
|
|
print("❌ 실패")
|