Files
dbx-main/app/modules/dispatch/tests/test_period_export.py
T
king 66b5155b9b feat(dispatch): 수퍼 관리자 전용 기간별 발송 수량 엑셀 다운로드
- GET /dispatch/period-export?date_from=&date_to= (서버 측 is_super_admin 검사, 최대 366일)
- 시트 「날짜별」(날짜/아이템코드/상품이름/수량) + 「아이템별 요약」(아이템×날짜 피벗, 합계)
- seller_sku _N 배수 반영, 콤보는 발송된 그대로(분해 안 함), 상품명은 itemcode_db 우선
- 배치 목록 오른쪽에 기간 선택 카드(수퍼 관리자에게만 표시)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-28 15:53:05 +09:00

68 lines
2.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""기간별 발송 수량 엑셀(export.aggregate_shipped / build_period_xlsx) 테스트.
DB 없이 집계·엑셀 생성만 검증한다.
python -m app.modules.dispatch.tests.test_period_export
또는 pytest 로 실행 가능.
"""
from __future__ import annotations
import io
from app.modules.dispatch import export
_ROWS = [
{"dispatch_date": "2026-10-02", "seller_sku": "MT-0320", "product_name": "A", "qty": 2},
{"dispatch_date": "2026-10-01", "seller_sku": "MT-0320_3", "product_name": "A", "qty": 1},
{"dispatch_date": "2026-10-01", "seller_sku": "mt-0320", "product_name": "A", "qty": 1},
{"dispatch_date": "2026-10-01", "seller_sku": "MY-0001", "product_name": "Set", "qty": 4},
{"dispatch_date": "2026-10-02", "seller_sku": "", "product_name": "", "qty": 9},
]
def test_aggregate_multiplier_and_merge():
"""_N 배수 반영 + 대소문자/접미사 다른 같은 코드 합산, 빈 코드 제외, 콤보는 그대로."""
dates, names, qty = export.aggregate_shipped(_ROWS, {"MT-0320": "상품A"})
assert dates == ["2026-10-01", "2026-10-02"], dates
assert qty[("2026-10-01", "MT-0320")] == 4 # 1×3 + 1
assert qty[("2026-10-02", "MT-0320")] == 2
assert qty[("2026-10-01", "MY-0001")] == 4
assert names["MT-0320"] == "상품A" # itemcode 이름 우선
assert names["MY-0001"] == "Set" # 없으면 파싱된 이름
def test_build_period_xlsx_sheets():
from openpyxl import load_workbook
data = export.build_period_xlsx(
rows=_ROWS, date_from="2026-10-01", date_to="2026-10-02", name_map={}
)
wb = load_workbook(io.BytesIO(data))
assert wb.sheetnames == ["날짜별", "아이템별 요약"]
ws = wb["날짜별"]
rows = list(ws.iter_rows(values_only=True))
assert rows[0] == ("발송 날짜", "아이템 코드", "상품이름", "수량")
assert rows[1] == ("2026-10-01", "MT-0320", "A", 4)
assert rows[2] == ("2026-10-01", "MY-0001", "Set", 4)
assert rows[3] == ("2026-10-02", "MT-0320", "A", 2)
assert rows[-1][0] == "합계" and rows[-1][3] == 10
ws2 = wb["아이템별 요약"]
rows2 = list(ws2.iter_rows(values_only=True))
assert rows2[0] == ("아이템 코드", "상품이름", "2026-10-01", "2026-10-02", "합계")
assert rows2[1] == ("MT-0320", "A", 4, 2, 6)
assert rows2[2] == ("MY-0001", "Set", 4, None, 4)
assert rows2[3] == ("합계", None, 8, 2, 10)
def test_period_filename():
assert export.period_filename("2026-10-01", "2026-10-28") == "2026.10.01-2026.10.28_shipped_qty.xlsx"
if __name__ == "__main__":
test_aggregate_multiplier_and_merge()
test_build_period_xlsx_sheets()
test_period_filename()
print("OK")