| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- """公开磅单二维码只读接口。"""
- from datetime import date
- from types import SimpleNamespace
- from fastapi.testclient import TestClient
- from app.main import app
- from app.services.db.pound_qr_public import (
- build_pound_qr_label,
- build_public_pound_qr_read,
- )
- client = TestClient(app)
- def test_build_pound_qr_label():
- assert build_pound_qr_label("出库", "合肥德泽") == "出库 · 合肥德泽"
- assert build_pound_qr_label("入库", "") == "入库"
- assert build_pound_qr_label("", "安庆山峡") == "安庆山峡"
- def test_build_public_pound_qr_read_maps_fields():
- row = SimpleNamespace(
- id="inv-1",
- date=date(2026, 9, 12),
- business_type="出库",
- vehicle_no="皖AM8516",
- partner_company="合肥德泽化工科技有限公司",
- product="30% 工业硫酸",
- specification="30%",
- quantity=10.0,
- remark="注意安全",
- )
- read = build_public_pound_qr_read(row, quantity_unit="吨")
- dump = read.model_dump(by_alias=True)
- assert dump["id"] == "inv-1"
- assert dump["date"] == "2026-09-12"
- assert dump["businessType"] == "出库"
- assert dump["vehicleNo"] == "皖AM8516"
- assert dump["partnerCompany"] == "合肥德泽化工科技有限公司"
- assert dump["product"] == "30% 工业硫酸"
- assert dump["specification"] == "30%"
- assert dump["quantity"] == 10.0
- assert dump["quantityUnit"] == "吨"
- assert dump["remarks"] == "注意安全"
- def test_pound_qr_missing_returns_404():
- resp = client.get("/api/public/db/inventory/__missing_pound_qr_id__/pound-qr")
- assert resp.status_code == 404
|