init: 博特维采购订单系统 v1.0 源码
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""编辑功能 + 明细行模板 冒烟测试。
|
||||
|
||||
覆盖:
|
||||
1) 新建订单(0 条明细,正是"点添加一行没反应"的场景)页面必须带 rowTpl 模板行
|
||||
2) 物料列表编辑:POST /materials 带 id 能改库
|
||||
3) 供应商列表编辑:POST /suppliers 带 id 能改库
|
||||
|
||||
用法:先启动服务(python app.py 8099),再 python test_edit_row.py 8099
|
||||
"""
|
||||
import os
|
||||
import re
|
||||
import sqlite3
|
||||
import sys
|
||||
|
||||
import requests
|
||||
|
||||
PORT = sys.argv[1] if len(sys.argv) > 1 else "8099"
|
||||
BASE = "http://127.0.0.1:%s" % PORT
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
DB = os.path.join(os.path.dirname(HERE), "po_app", "instance", "po.db")
|
||||
|
||||
s = requests.Session()
|
||||
FAILS = []
|
||||
|
||||
|
||||
def check(label, cond, extra=""):
|
||||
print((" OK " if cond else " FAIL ") + label + (" " + str(extra) if extra else ""))
|
||||
if not cond:
|
||||
FAILS.append(label)
|
||||
|
||||
|
||||
def main():
|
||||
r = s.post(BASE + "/login", data={"username": "admin", "password": "admin123"})
|
||||
check("登录", r.status_code == 200, r.status_code)
|
||||
|
||||
print("\n[1] 新建订单(0 明细)—— 明细行模板")
|
||||
r = s.post(BASE + "/orders/new", data={"doc_type": "purchase"})
|
||||
html = r.text
|
||||
no = ""
|
||||
m = re.search(r"PO\d{12}", html)
|
||||
if m:
|
||||
no = m.group(0)
|
||||
check("新建订单页含 rowTpl 模板", 'id="rowTpl"' in html)
|
||||
tpl = re.search(r'<template id="rowTpl">(.*?)</template>', html, re.S)
|
||||
check("模板内含 tr 行", bool(tpl) and "<tr>" in tpl.group(1))
|
||||
check("模板含 item_code 输入框", bool(tpl) and 'name="item_code"' in tpl.group(1))
|
||||
check("模板含 matpick 下拉", bool(tpl) and "matpick" in tpl.group(1))
|
||||
n_code = html.count('name="item_code"')
|
||||
check("当前确实 0 条明细(模板是唯一来源)", n_code == 1,
|
||||
"item_code 出现 %d 次" % n_code)
|
||||
|
||||
print("\n[2] 物料列表编辑")
|
||||
con = sqlite3.connect(DB)
|
||||
cur = con.cursor()
|
||||
cur.execute("SELECT id FROM materials WHERE code='M-1002'")
|
||||
row = cur.fetchone()
|
||||
con.close()
|
||||
if not row:
|
||||
check("找到物料 M-1002", False)
|
||||
else:
|
||||
mid = row[0]
|
||||
r = s.post(BASE + "/materials",
|
||||
data={"id": mid, "code": "M-1002", "spec": u"步进电机(已编辑)",
|
||||
"unit": u"台", "price": "299.5"})
|
||||
check("物料编辑请求成功", r.status_code == 200, r.status_code)
|
||||
con = sqlite3.connect(DB)
|
||||
cur = con.cursor()
|
||||
cur.execute("SELECT spec, unit, price FROM materials WHERE id=?", (mid,))
|
||||
got = cur.fetchone()
|
||||
check("物料已更新", got == (u"步进电机(已编辑)", u"台", 299.5), got)
|
||||
cur.execute("UPDATE materials SET spec=?, price=? WHERE id=?",
|
||||
(u"步进电机 57BYG250 2相", 265.0, mid))
|
||||
con.commit()
|
||||
con.close()
|
||||
print(" 已还原 M-1002")
|
||||
|
||||
print("\n[3] 供应商列表编辑")
|
||||
con = sqlite3.connect(DB)
|
||||
cur = con.cursor()
|
||||
cur.execute("SELECT id FROM suppliers WHERE code='S002'")
|
||||
row = cur.fetchone()
|
||||
con.close()
|
||||
if not row:
|
||||
check("找到供应商 S002", False)
|
||||
else:
|
||||
sid = row[0]
|
||||
r = s.post(BASE + "/suppliers",
|
||||
data={"id": sid, "code": "S002", "name": u"昆山宏远电子科技有限公司",
|
||||
"contact": u"陈主管(已编辑)", "phone": "13900000002",
|
||||
"payment_terms": u"货到付款", "tax_no": "91320583MA2XXXXXXX",
|
||||
"bank_name": u"建设银行昆山分行",
|
||||
"bank_account": "3220 1988 2233 4455"})
|
||||
check("供应商编辑请求成功", r.status_code == 200, r.status_code)
|
||||
con = sqlite3.connect(DB)
|
||||
cur = con.cursor()
|
||||
cur.execute("SELECT contact, payment_terms FROM suppliers WHERE id=?", (sid,))
|
||||
got = cur.fetchone()
|
||||
check("供应商已更新", got == (u"陈主管(已编辑)", u"货到付款"), got)
|
||||
cur.execute("UPDATE suppliers SET contact=? WHERE id=?", (u"陈主管", sid))
|
||||
con.commit()
|
||||
con.close()
|
||||
print(" 已还原 S002")
|
||||
|
||||
print("\n[4] 清理测试订单 " + no)
|
||||
if no:
|
||||
con = sqlite3.connect(DB)
|
||||
cur = con.cursor()
|
||||
cur.execute("DELETE FROM order_items WHERE order_id IN "
|
||||
"(SELECT id FROM orders WHERE order_no=?)", (no,))
|
||||
cur.execute("DELETE FROM orders WHERE order_no=?", (no,))
|
||||
con.commit()
|
||||
con.close()
|
||||
|
||||
print("\n" + ("全部通过" if not FAILS else "失败: " + "; ".join(FAILS)))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user