You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
3.0 KiB

# -*- coding: utf-8 -*-
"""票 06 对照实验:edit form 绑定行为(判 C8「清字段」真因)。
X1 建商机(全字段非空)→ DB 确认;
X2 edit 只传 id(全空表单)→ code + DB 六字段是否被清;
X3 edit 传 'opportunityName'(DTO 无此属性)→ code + opp_name 是否变(判 key 绑定性);
X4 edit 传 'oppName'=''(DTO 真名改空)→ 预期 66001 + 字段不变;
X5 edit 传 'oppName'=新名 → 预期放行 + DB 生效(正常路径对照)。
"""
import io, sys
import pymysql
import requests
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
BASE = 'http://localhost:8080'
TAG = 'e2e-t06exp'
r = requests.get(f'{BASE}/api/auth/debug/token', params={'userId': '739564171091247104'}, timeout=15)
H = {'Authorization': f"Bearer {r.json()['data']}"}
def api(method, path, form=None, params=None):
headers = dict(H)
data = None
if form is not None:
headers['Content-Type'] = 'application/x-www-form-urlencoded'
data = form
b = requests.request(method, BASE + path, headers=headers, data=data, params=params, timeout=30).json()
print(f" <- {method} {path} code={b.get('code')} msg={str(b.get('message'))[:50]}")
return b
def db_fields(oid, label):
conn = pymysql.connect(host='8.129.84.155', port=3306, user='root', password='Itc@123456',
database='crm', charset='utf8mb4', autocommit=True)
cur = conn.cursor()
cur.execute("SELECT opp_name, opp_source, bid_form, province_code, city_code, locality_type "
"FROM opportunity WHERE id=%s", (int(oid),))
print(f" [DB {label}]", cur.fetchall())
conn.close()
base = {'opportunityName': f'票06实验X-{TAG}', 'oppSource': 'opp_source_02', 'industryCode': 'gov',
'localityType': 'locality_type_01', 'bidForm': 'bid_form_01',
'provinceCode': '510000', 'cityCode': '510100', 'partyAClear': 1, 'partyA': '票06实验'}
b = api('POST', '/api/opportunity', form=base)
x = b.get('data')
print('X id =', x)
db_fields(x, 'X1 创建后')
print('\n-- X2: edit 只传 id(全空表单)--')
api('POST', '/api/opportunity/edit', form={'id': x})
db_fields(x, 'X2 后')
print("\n-- X3: edit 传 'opportunityName'(DTO 无此属性)--")
api('POST', '/api/opportunity/edit', form={'id': x, 'opportunityName': 'X改名试验'})
db_fields(x, 'X3 后')
print("\n-- X4: edit 传 'oppName'=''(真名改空)--")
api('POST', '/api/opportunity/edit', form={'id': x, 'oppName': ''})
db_fields(x, 'X4 后')
print("\n-- X5: edit 传 'oppName'=新名(正常路径)--")
api('POST', '/api/opportunity/edit', form={'id': x, 'oppName': f'票06实验X改-{TAG}'})
db_fields(x, 'X5 后')
# 清理实验商机
conn = pymysql.connect(host='8.129.84.155', port=3306, user='root', password='Itc@123456',
database='crm', charset='utf8mb4', autocommit=True)
cur = conn.cursor()
cur.execute("UPDATE opportunity SET deleted=1 WHERE opp_name LIKE %s OR remark LIKE %s",
('票06实验%', '票06实验%'))
print('\nCLEANUP exp opp rows=', cur.rowcount)
conn.close()