完善采购审批流程、企业微信通知和采购专用章
This commit is contained in:
+3
-71
@@ -1,73 +1,5 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""测试 Excel 明细导入接口(multipart 上传)。"""
|
||||
import io
|
||||
import os
|
||||
import re
|
||||
import urllib.parse
|
||||
import urllib.request
|
||||
|
||||
import openpyxl
|
||||
|
||||
BASE = "http://127.0.0.1:8080"
|
||||
OUT = r"D:\2026-09-09-task-18\tools\out"
|
||||
os.makedirs(OUT, exist_ok=True)
|
||||
|
||||
|
||||
def new_session():
|
||||
import http.cookiejar
|
||||
cj = http.cookiejar.CookieJar()
|
||||
return urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
||||
|
||||
|
||||
def post_form(op, path, data):
|
||||
body = urllib.parse.urlencode(data).encode()
|
||||
r = op.open(urllib.request.Request(BASE + path, data=body), timeout=30)
|
||||
return r.geturl(), r.read()
|
||||
|
||||
|
||||
def multipart_upload(op, path, field, filename, content, extra=None):
|
||||
boundary = "----PoTestBoundary1234"
|
||||
buf = io.BytesIO()
|
||||
for k, v in (extra or {}).items():
|
||||
buf.write(("--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n"
|
||||
% (boundary, k, v)).encode("utf-8"))
|
||||
buf.write(("--%s\r\nContent-Disposition: form-data; name=\"%s\"; filename=\"%s\"\r\n"
|
||||
"Content-Type: application/octet-stream\r\n\r\n" % (boundary, field, filename))
|
||||
.encode("utf-8"))
|
||||
buf.write(content)
|
||||
buf.write(("\r\n--%s--\r\n" % boundary).encode())
|
||||
req = urllib.request.Request(BASE + path, data=buf.getvalue(), method="POST")
|
||||
req.add_header("Content-Type", "multipart/form-data; boundary=%s" % boundary)
|
||||
r = op.open(req, timeout=30)
|
||||
return r.geturl(), r.read().decode("utf-8", "replace")
|
||||
|
||||
|
||||
def main():
|
||||
op = new_session()
|
||||
post_form(op, "/login", {"username": "maker", "password": "123456"})
|
||||
|
||||
wb = openpyxl.Workbook()
|
||||
ws = wb.active
|
||||
ws.append([u"物料代码", u"物料规格", u"单位", u"数量", u"含税单价", u"交期", u"备注"])
|
||||
ws.append([u"X-001", u"导入测试件 & <一>", u"件", 10, 99.9, "2026-10-01", u"首件"])
|
||||
ws.append([u"X-002", u"导入测试件 二", u"套", 3, 128.5, "2026-10-05", u""])
|
||||
buf = io.BytesIO()
|
||||
wb.save(buf)
|
||||
xlsx = buf.getvalue()
|
||||
|
||||
url, _ = post_form(op, "/orders/new", {"doc_type": "purchase", "supplier_id": ""})
|
||||
oid = int(re.search(r"/orders/(\d+)", url).group(1))
|
||||
print("order id", oid)
|
||||
|
||||
url, html = multipart_upload(op, "/orders/%d/import_excel" % oid, "file",
|
||||
"test.xlsx", xlsx, {"mode": "replace"})
|
||||
ok = "已导入 2 行明细" in html
|
||||
print("import rows ok:", ok)
|
||||
ok2 = "99.90" in html or "99.9" in html
|
||||
print("price present:", ok2)
|
||||
assert ok and ok2
|
||||
print("IMPORT TEST PASSED")
|
||||
|
||||
"""Compatibility entry point; tests only use temporary databases."""
|
||||
from run_tests import main
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
raise SystemExit(main(('-k', 'chinese_filename')))
|
||||
|
||||
Reference in New Issue
Block a user