1439 lines
50 KiB
Python
1439 lines
50 KiB
Python
import hashlib
|
|
import hmac
|
|
import json
|
|
import random
|
|
import re
|
|
import sys
|
|
import time
|
|
import uuid
|
|
from datetime import date, datetime, timedelta
|
|
from pathlib import Path
|
|
|
|
PYDEPS = Path(r"C:\Users\win-2697\AppData\Local\Temp\codex-yuminail-pydeps")
|
|
sys.path.insert(0, str(PYDEPS))
|
|
|
|
import openpyxl
|
|
import pymysql
|
|
import requests
|
|
|
|
ROOT = Path(r"E:\yuminail")
|
|
ART = ROOT / "artifacts" / "full-regression"
|
|
ART.mkdir(parents=True, exist_ok=True)
|
|
CORE = "http://127.0.0.1:18081"
|
|
RUN_ID = "fd" + datetime.now().strftime("%m%d%H%M%S")
|
|
SQL_PATH = ROOT / "YumiNail-Core" / "src" / "main" / "resources" / "files" / "YumiNail.sql"
|
|
|
|
CASES = []
|
|
STATE = {"runId": RUN_ID, "baseUrl": CORE, "ids": {}, "tokens": {}, "db": {}}
|
|
|
|
|
|
def gen_id():
|
|
return int(time.time() * 1000) * 100000 + random.randint(1000, 99999)
|
|
|
|
|
|
def mask_text(text, max_len=900):
|
|
if text is None:
|
|
return ""
|
|
value = str(text)
|
|
value = re.sub(r"Bearer\s+[A-Za-z0-9._\-]+", "Bearer ***", value)
|
|
value = re.sub(
|
|
r'("(?:accessToken|refreshToken|token|password|secret|accessKey|secretKey)"\s*:\s*")[^"]+',
|
|
r"\1***",
|
|
value,
|
|
flags=re.I,
|
|
)
|
|
value = re.sub(r"(password=)[^&\s]+", r"\1***", value, flags=re.I)
|
|
return value[:max_len]
|
|
|
|
|
|
def add_case(cid, role, module, pre, steps, expected, actual, status, priority="-", evidence=""):
|
|
CASES.append(
|
|
{
|
|
"id": cid,
|
|
"role": role,
|
|
"module": module,
|
|
"precondition": pre,
|
|
"steps": steps,
|
|
"expected": expected,
|
|
"actual": mask_text(actual, 1600),
|
|
"status": status,
|
|
"priority": priority,
|
|
"evidence": mask_text(evidence, 1600),
|
|
}
|
|
)
|
|
|
|
|
|
def read_env():
|
|
workbook_path = "E:\\codex\\docs\\\u5f00\u53d1\u73af\u5883\u670d\u52a1\u4fe1\u606f\u8868.xlsx"
|
|
workbook = openpyxl.load_workbook(workbook_path, data_only=True, read_only=True)
|
|
env = {}
|
|
for sheet in workbook.worksheets:
|
|
for row in sheet.iter_rows(values_only=True):
|
|
cells = [str(cell).strip() if cell is not None else "" for cell in row]
|
|
if len(cells) < 7:
|
|
continue
|
|
kind = cells[6]
|
|
if cells[2] == "192.168.5.15" and cells[3] == "3306" and cells[4] == "root":
|
|
env["mysql"] = {
|
|
"host": cells[2],
|
|
"port": int(cells[3]),
|
|
"user": cells[4],
|
|
"password": cells[5],
|
|
}
|
|
elif kind == "redis" and cells[2] == "192.168.5.15":
|
|
env["redis"] = {"host": cells[2], "port": int(cells[3]), "password": cells[5]}
|
|
elif kind == "mq" and cells[2] == "192.168.5.15":
|
|
env["mq"] = {"host": cells[2], "user": cells[4], "password": cells[5]}
|
|
elif kind == "minio" and cells[2] == "192.168.5.15":
|
|
env["minio"] = {"host": cells[2], "user": cells[4], "password": cells[5]}
|
|
elif "nacos" in kind and cells[2].startswith("192.168.5."):
|
|
env.setdefault("nacos", []).append(
|
|
{"host": cells[2], "port": cells[3], "user": cells[4], "password": cells[5]}
|
|
)
|
|
if "mysql" not in env:
|
|
raise RuntimeError("dev mysql not found in workbook")
|
|
return env
|
|
|
|
|
|
ENV = read_env()
|
|
|
|
|
|
def mysql_conn(db="nailart"):
|
|
return pymysql.connect(
|
|
host=ENV["mysql"]["host"],
|
|
port=ENV["mysql"]["port"],
|
|
user=ENV["mysql"]["user"],
|
|
password=ENV["mysql"]["password"],
|
|
database=db,
|
|
charset="utf8mb4",
|
|
autocommit=False,
|
|
cursorclass=pymysql.cursors.DictCursor,
|
|
)
|
|
|
|
|
|
def mysql_server_conn():
|
|
return pymysql.connect(
|
|
host=ENV["mysql"]["host"],
|
|
port=ENV["mysql"]["port"],
|
|
user=ENV["mysql"]["user"],
|
|
password=ENV["mysql"]["password"],
|
|
charset="utf8mb4",
|
|
autocommit=True,
|
|
cursorclass=pymysql.cursors.DictCursor,
|
|
)
|
|
|
|
|
|
def split_sql_script(text):
|
|
statements = []
|
|
current = []
|
|
delimiter = ";"
|
|
for raw_line in text.splitlines():
|
|
line = raw_line.rstrip("\n")
|
|
stripped = line.strip()
|
|
if not stripped or stripped.startswith("--") or stripped.startswith("#"):
|
|
continue
|
|
if stripped.upper().startswith("DELIMITER"):
|
|
parts = stripped.split()
|
|
delimiter = parts[1] if len(parts) > 1 else ";"
|
|
continue
|
|
current.append(line)
|
|
joined = "\n".join(current)
|
|
if delimiter == ";":
|
|
if stripped.endswith(";"):
|
|
statement = joined[:-1].strip()
|
|
if statement:
|
|
statements.append(statement)
|
|
current = []
|
|
elif joined.rstrip().endswith(delimiter):
|
|
statement = joined.rstrip()[: -len(delimiter)].strip()
|
|
if statement:
|
|
statements.append(statement)
|
|
current = []
|
|
tail = "\n".join(current).strip()
|
|
if tail:
|
|
statements.append(tail)
|
|
return statements
|
|
|
|
|
|
def reset_db():
|
|
sql_text = SQL_PATH.read_text(encoding="utf-8-sig")
|
|
statements = split_sql_script(sql_text)
|
|
with mysql_server_conn() as conn:
|
|
with conn.cursor() as cur:
|
|
cur.execute("DROP DATABASE IF EXISTS nailart")
|
|
cur.execute("CREATE DATABASE nailart DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci")
|
|
errors = []
|
|
with mysql_conn("nailart") as conn:
|
|
with conn.cursor() as cur:
|
|
for index, statement in enumerate(statements, 1):
|
|
try:
|
|
cur.execute(statement)
|
|
except Exception as exc:
|
|
errors.append({"index": index, "sql": statement[:240], "error": str(exc)})
|
|
if len(errors) > 20:
|
|
break
|
|
if errors:
|
|
conn.rollback()
|
|
raise RuntimeError(json.dumps(errors[:5], ensure_ascii=False))
|
|
conn.commit()
|
|
return len(statements)
|
|
|
|
|
|
def db_one(sql, args=None):
|
|
with mysql_conn() as conn:
|
|
with conn.cursor() as cur:
|
|
cur.execute(sql, args or ())
|
|
return cur.fetchone()
|
|
|
|
|
|
def db_all(sql, args=None):
|
|
with mysql_conn() as conn:
|
|
with conn.cursor() as cur:
|
|
cur.execute(sql, args or ())
|
|
return cur.fetchall()
|
|
|
|
|
|
def db_exec(sql, args=None):
|
|
with mysql_conn() as conn:
|
|
with conn.cursor() as cur:
|
|
cur.execute(sql, args or ())
|
|
lastrowid = cur.lastrowid
|
|
conn.commit()
|
|
return lastrowid
|
|
|
|
|
|
def json_bytes(obj):
|
|
if obj is None:
|
|
return b""
|
|
return json.dumps(obj, ensure_ascii=False, separators=(",", ":")).encode("utf-8")
|
|
|
|
|
|
def canonical_query(params):
|
|
if not params:
|
|
return ""
|
|
pairs = []
|
|
for key in sorted(params.keys()):
|
|
value = params[key]
|
|
if isinstance(value, (list, tuple)):
|
|
values = sorted("" if item is None else str(item) for item in value)
|
|
pairs.append(str(key) + "=" + ",".join(values))
|
|
else:
|
|
pairs.append(str(key) + "=" + ("" if value is None else str(value)))
|
|
return "&".join(pairs)
|
|
|
|
|
|
def sign_headers(method, path, token, body_obj=None, params=None):
|
|
timestamp = str(int(time.time() * 1000))
|
|
nonce = uuid.uuid4().hex
|
|
if body_obj is not None:
|
|
payload = json_bytes(body_obj)
|
|
elif params:
|
|
payload = canonical_query(params).encode("utf-8")
|
|
else:
|
|
payload = b""
|
|
body_hash = hashlib.sha256(payload).hexdigest()
|
|
canonical = "\n".join([method.upper(), path, timestamp, nonce, body_hash])
|
|
signature = hmac.new(token.encode("utf-8"), canonical.encode("utf-8"), hashlib.sha256).hexdigest()
|
|
return {
|
|
"Authorization": "Bearer " + token,
|
|
"X-Timestamp": timestamp,
|
|
"X-Nonce": nonce,
|
|
"X-Sign-Version": "v1",
|
|
"X-Signature": signature,
|
|
}
|
|
|
|
|
|
def request(method, path, token=None, body=None, params=None, timeout=18):
|
|
headers = {}
|
|
kwargs = {"timeout": timeout}
|
|
if params:
|
|
kwargs["params"] = params
|
|
if body is not None:
|
|
kwargs["data"] = json_bytes(body)
|
|
headers["Content-Type"] = "application/json;charset=UTF-8"
|
|
if token:
|
|
headers.update(sign_headers(method, path, token, body, params))
|
|
kwargs["headers"] = headers
|
|
try:
|
|
response = requests.request(method, CORE + path, **kwargs)
|
|
try:
|
|
parsed = response.json()
|
|
except Exception:
|
|
parsed = {"raw": response.text}
|
|
return {"http": response.status_code, "json": parsed, "text": response.text}
|
|
except Exception as exc:
|
|
return {"http": 0, "json": {"error": str(exc)}, "text": str(exc)}
|
|
|
|
|
|
def ok(resp):
|
|
return resp.get("http") == 200 and isinstance(resp.get("json"), dict) and resp["json"].get("code") == 200
|
|
|
|
|
|
def data(resp):
|
|
return resp.get("json", {}).get("data") if isinstance(resp.get("json"), dict) else None
|
|
|
|
|
|
def id_data(resp):
|
|
value = data(resp)
|
|
if isinstance(value, dict) and "id" in value:
|
|
return int(value["id"])
|
|
return int(value)
|
|
|
|
|
|
def api_case(cid, role, module, pre, steps, expected, method, path, token=None, body=None, params=None, priority="P1", evidence=""):
|
|
resp = request(method, path, token=token, body=body, params=params)
|
|
status = "PASS" if ok(resp) else "FAIL"
|
|
add_case(
|
|
cid,
|
|
role,
|
|
module,
|
|
pre,
|
|
steps,
|
|
expected,
|
|
json.dumps(resp["json"], ensure_ascii=False, default=str),
|
|
status,
|
|
"-" if status == "PASS" else priority,
|
|
evidence or (method + " " + path),
|
|
)
|
|
return resp
|
|
|
|
|
|
def create_shop(admin_token, suffix, status=1, start_delta=-1, days=30):
|
|
start = (date.today() + timedelta(days=start_delta)).isoformat()
|
|
expire = (datetime.now() + timedelta(days=start_delta + days)).strftime("%Y-%m-%dT%H:%M:%S")
|
|
payload = {
|
|
"shopName": f"{RUN_ID} {suffix} shop",
|
|
"description": f"{suffix} dev shop",
|
|
"address": f"{RUN_ID} road {suffix}",
|
|
"businessHours": "09:00-21:00",
|
|
"status": status,
|
|
"authorizationStartDate": start,
|
|
"authorizationDays": days,
|
|
"authorizationExpireTime": expire,
|
|
"themePrimaryColor": "#1677ff",
|
|
"themeSecondaryColor": "#f5f5f5",
|
|
"themeAccentColor": "#ff7a45",
|
|
"themePageBgColor": "#ffffff",
|
|
"themeCardBgColor": "#ffffff",
|
|
}
|
|
return api_case(
|
|
"ADMIN-002-" + suffix,
|
|
"平台管理员",
|
|
"店铺管理",
|
|
"平台管理员已登录",
|
|
f"创建{suffix}门店",
|
|
"返回门店ID且 t_shop 可查",
|
|
"POST",
|
|
"/admin/shops/create",
|
|
admin_token,
|
|
body=payload,
|
|
priority="P1",
|
|
)
|
|
|
|
|
|
def create_user(admin_token, role_key, shop_id, user_type, phone_suffix, wechat=True):
|
|
payload = {
|
|
"shopId": shop_id,
|
|
"shopIds": [shop_id],
|
|
"nickname": f"{RUN_ID} {role_key}",
|
|
"account": f"{RUN_ID}{role_key}",
|
|
"password": "Aa888888!",
|
|
"type": user_type,
|
|
"phone": "19" + phone_suffix[-9:],
|
|
"contactPhone": "19" + phone_suffix[-9:],
|
|
"signature": f"{RUN_ID} signature",
|
|
}
|
|
if wechat:
|
|
payload["wechatId"] = f"wx{RUN_ID}{role_key}"
|
|
return api_case(
|
|
"ADMIN-007-" + role_key,
|
|
"平台管理员",
|
|
"账号管理",
|
|
"门店已创建",
|
|
f"创建{role_key} type={user_type}",
|
|
"返回用户ID、默认权限和门店绑定写入",
|
|
"POST",
|
|
"/admin/user/create",
|
|
admin_token,
|
|
body=payload,
|
|
priority="P1",
|
|
)
|
|
|
|
|
|
def try_create_service_user(admin_token, role_key, shop_id, user_type, phone_suffix):
|
|
payload = {
|
|
"shopId": shop_id,
|
|
"shopIds": [shop_id],
|
|
"nickname": f"{RUN_ID} {role_key}",
|
|
"account": f"{RUN_ID}{role_key}",
|
|
"password": "Aa888888!",
|
|
"type": user_type,
|
|
"phone": "19" + phone_suffix[-9:],
|
|
"contactPhone": "19" + phone_suffix[-9:],
|
|
"wechatId": f"wx{RUN_ID}{role_key}",
|
|
}
|
|
return request("POST", "/admin/user/create", token=admin_token, body=payload)
|
|
|
|
|
|
def login_admin(account, password, shop_id=None):
|
|
body = {"account": account, "password": password, "rememberMe": True}
|
|
if shop_id is not None:
|
|
body["shopId"] = shop_id
|
|
return request("POST", "/admin/auth/login", body=body)
|
|
|
|
|
|
def login_user(account, password, shop_id, versions):
|
|
body = {
|
|
"account": account,
|
|
"password": password,
|
|
"rememberMe": True,
|
|
"shopId": shop_id,
|
|
"agreementAccepted": True,
|
|
"agreementVersions": versions,
|
|
"clientType": "TEST",
|
|
}
|
|
return request("POST", "/user/login", body=body)
|
|
|
|
|
|
def extract_token(resp):
|
|
payload = data(resp) or {}
|
|
return payload.get("accessToken"), payload.get("userInfo") or {}
|
|
|
|
|
|
def assign_all_permissions(user_id):
|
|
permissions = db_all("select id from t_permission where is_delete=0")
|
|
with mysql_conn() as conn:
|
|
with conn.cursor() as cur:
|
|
for permission in permissions:
|
|
cur.execute(
|
|
"select id from t_user_permission where user_id=%s and permission_id=%s limit 1",
|
|
(user_id, permission["id"]),
|
|
)
|
|
if cur.fetchone():
|
|
continue
|
|
cur.execute(
|
|
"""insert into t_user_permission
|
|
(id,user_id,permission_id,create_time,update_time,create_by,update_by,is_delete)
|
|
values(%s,%s,%s,NOW(),NOW(),0,0,0)""",
|
|
(gen_id(), user_id, permission["id"]),
|
|
)
|
|
conn.commit()
|
|
|
|
|
|
def seed_nail_artist(user_id, status=1, participate=1):
|
|
existing = db_one("select id from t_nail_artist_info where user_id=%s and is_delete=0", (user_id,))
|
|
if existing:
|
|
db_exec(
|
|
"""update t_nail_artist_info
|
|
set status=%s, participate_production=%s, work_start_time=%s, work_end_time=%s
|
|
where user_id=%s""",
|
|
(status, participate, "09:00:00", "21:00:00", user_id),
|
|
)
|
|
return existing["id"]
|
|
new_id = gen_id()
|
|
db_exec(
|
|
"""insert into t_nail_artist_info
|
|
(id,user_id,identity,experience,skills,rating,status,participate_production,work_start_time,work_end_time,portfolio,create_time,update_time,is_delete)
|
|
values(%s,%s,%s,3,%s,4.8,%s,%s,%s,%s,%s,NOW(),NOW(),0)""",
|
|
(new_id, user_id, "高级设计师", "法式,通勤,延长", status, participate, "09:00:00", "21:00:00", ""),
|
|
)
|
|
return new_id
|
|
|
|
|
|
def db_counts():
|
|
tables = [
|
|
"t_user",
|
|
"t_shop",
|
|
"t_user_shop_binding",
|
|
"t_nail_artist_info",
|
|
"t_artist_schedule",
|
|
"t_product",
|
|
"t_order",
|
|
"t_order_item",
|
|
"t_appointment_reservation",
|
|
"t_user_agreement_consent",
|
|
]
|
|
output = {}
|
|
for table in tables:
|
|
try:
|
|
output[table] = db_one("select count(*) c from " + table)["c"]
|
|
except Exception as exc:
|
|
output[table] = "ERR " + str(exc)
|
|
return output
|
|
|
|
|
|
def cell(value):
|
|
return str(value).replace("|", "/").replace("\n", "<br>")[:900]
|
|
|
|
|
|
def main():
|
|
try:
|
|
health = requests.get(CORE + "/shop/list/simple", timeout=6)
|
|
add_case(
|
|
"ENV-001",
|
|
"环境",
|
|
"Core 健康检查",
|
|
"Core 18081 已启动",
|
|
"GET /shop/list/simple",
|
|
"HTTP 200",
|
|
f"HTTP {health.status_code}, {mask_text(health.text, 300)}",
|
|
"PASS" if health.status_code == 200 else "FAIL",
|
|
"P0",
|
|
"http://127.0.0.1:18081",
|
|
)
|
|
except Exception as exc:
|
|
add_case(
|
|
"ENV-001",
|
|
"环境",
|
|
"Core 健康检查",
|
|
"Core 18081 已启动",
|
|
"GET /shop/list/simple",
|
|
"HTTP 200",
|
|
str(exc),
|
|
"FAIL",
|
|
"P0",
|
|
"http://127.0.0.1:18081",
|
|
)
|
|
|
|
if ENV.get("nacos"):
|
|
nacos = ENV["nacos"][0]
|
|
try:
|
|
response = requests.post(
|
|
f"http://{nacos['host']}:{nacos['port']}/nacos/v1/auth/login",
|
|
data={"username": nacos["user"].split("/")[0], "password": nacos["password"]},
|
|
timeout=5,
|
|
)
|
|
nacos_actual = f"HTTP {response.status_code}"
|
|
nacos_status = "PASS" if response.status_code == 200 else "BLOCKED"
|
|
except Exception as exc:
|
|
nacos_actual = type(exc).__name__
|
|
nacos_status = "BLOCKED"
|
|
add_case(
|
|
"ENV-002",
|
|
"环境",
|
|
"Nacos Dev 命名空间",
|
|
"仅读开发 Nacos",
|
|
"登录 Nacos 读取 YumiNail-Dev",
|
|
"成功读取或记录阻塞",
|
|
nacos_actual,
|
|
nacos_status,
|
|
"P3",
|
|
"Nacos dev host reachable; secrets redacted",
|
|
)
|
|
|
|
statement_count = reset_db()
|
|
STATE["db"]["initStatements"] = statement_count
|
|
add_case(
|
|
"ENV-003",
|
|
"环境",
|
|
"数据库重建",
|
|
"已有备份 nailart_backup_fd0608202858.sql",
|
|
"DROP/CREATE nailart 并执行 YumiNail.sql",
|
|
"初始化成功且基础权限/管理员存在",
|
|
f"初始化语句 {statement_count}, counts={db_counts()}",
|
|
"PASS",
|
|
"-",
|
|
"YumiNail-Core/src/main/resources/files/YumiNail.sql",
|
|
)
|
|
|
|
admin_resp = login_admin("xiaowang", "888888")
|
|
admin_token, admin_user = extract_token(admin_resp)
|
|
STATE["tokens"]["platformAdmin"] = "***" if admin_token else None
|
|
add_case(
|
|
"ADMIN-001",
|
|
"平台管理员",
|
|
"登录",
|
|
"默认管理员 xiaowang",
|
|
"账号密码登录后台",
|
|
"返回 type=4 accessToken",
|
|
json.dumps(admin_resp["json"], ensure_ascii=False, default=str),
|
|
"PASS" if admin_token and admin_user.get("type") == 4 else "FAIL",
|
|
"P0",
|
|
"POST /admin/auth/login",
|
|
)
|
|
if not admin_token:
|
|
raise RuntimeError("platform admin login failed")
|
|
|
|
normal_id = id_data(create_shop(admin_token, "normal", 1, -1, 30))
|
|
expired_id = id_data(create_shop(admin_token, "expired", 1, -60, 1))
|
|
disabled_id = id_data(create_shop(admin_token, "disabled", 0, -1, 30))
|
|
other_id = id_data(create_shop(admin_token, "other", 1, -1, 30))
|
|
STATE["ids"].update(
|
|
{"normalShop": normal_id, "expiredShop": expired_id, "disabledShop": disabled_id, "otherShop": other_id}
|
|
)
|
|
|
|
update_payload = {
|
|
"shopName": f"{RUN_ID} normal shop edited",
|
|
"description": "normal edited",
|
|
"address": "Dev 1",
|
|
"businessHours": "09:00-21:00",
|
|
"status": 1,
|
|
"authorizationStartDate": (date.today() - timedelta(days=1)).isoformat(),
|
|
"authorizationDays": 45,
|
|
"authorizationExpireTime": (datetime.now() + timedelta(days=45)).strftime("%Y-%m-%dT%H:%M:%S"),
|
|
"themePrimaryColor": "#1677ff",
|
|
"themeSecondaryColor": "#f5f5f5",
|
|
"themeAccentColor": "#ff7a45",
|
|
"themePageBgColor": "#ffffff",
|
|
"themeCardBgColor": "#ffffff",
|
|
}
|
|
api_case(
|
|
"ADMIN-003",
|
|
"平台管理员",
|
|
"店铺管理",
|
|
"normal 门店存在",
|
|
"编辑门店资料后查询详情",
|
|
"更新成功且详情为新值",
|
|
"PUT",
|
|
f"/admin/shops/update/{normal_id}",
|
|
admin_token,
|
|
body=update_payload,
|
|
priority="P1",
|
|
)
|
|
api_case(
|
|
"ADMIN-003B",
|
|
"平台管理员",
|
|
"店铺管理",
|
|
"normal 门店存在",
|
|
"查询门店详情",
|
|
"返回 normal 门店详情",
|
|
"GET",
|
|
f"/admin/shops/{normal_id}",
|
|
admin_token,
|
|
priority="P1",
|
|
)
|
|
status_resp = api_case(
|
|
"ADMIN-004",
|
|
"平台管理员",
|
|
"店铺启停",
|
|
"disabled 门店存在",
|
|
"JSON body 修改门店状态为启用",
|
|
"状态更新成功",
|
|
"PUT",
|
|
f"/admin/shops/status/{disabled_id}",
|
|
admin_token,
|
|
body={"status": 1},
|
|
priority="P1",
|
|
)
|
|
if ok(status_resp):
|
|
api_case(
|
|
"ADMIN-004B",
|
|
"平台管理员",
|
|
"店铺启停",
|
|
"disabled 门店已启用",
|
|
"JSON body 修改门店状态为停用",
|
|
"状态更新成功",
|
|
"PUT",
|
|
f"/admin/shops/status/{disabled_id}",
|
|
admin_token,
|
|
body={"status": 0},
|
|
priority="P1",
|
|
)
|
|
|
|
manager_id = id_data(create_user(admin_token, "manager", normal_id, 2, "100000001", wechat=True))
|
|
artist1_id = id_data(create_user(admin_token, "artistone", normal_id, 3, "100000002", wechat=True))
|
|
artist2_id = id_data(create_user(admin_token, "artisttwo", normal_id, 3, "100000003", wechat=True))
|
|
customer_id = id_data(create_user(admin_token, "customer", normal_id, 0, "100000004", wechat=False))
|
|
other_manager_id = id_data(create_user(admin_token, "othermgr", other_id, 2, "100000005", wechat=True))
|
|
STATE["ids"].update(
|
|
{
|
|
"manager": manager_id,
|
|
"artist1": artist1_id,
|
|
"artist2": artist2_id,
|
|
"customer": customer_id,
|
|
"otherManager": other_manager_id,
|
|
}
|
|
)
|
|
expired_resp = create_user(admin_token, "expiredmgr", expired_id, 2, "100000006", wechat=True)
|
|
expired_text = json.dumps(expired_resp["json"], ensure_ascii=False)
|
|
expired_status = "PASS" if (not ok(expired_resp) and ("冻结" in expired_text or "授权" in expired_text)) else "FAIL"
|
|
CASES[-1]["status"] = expired_status
|
|
CASES[-1]["expected"] = "过期/冻结门店禁止创建可登录店长,返回明确错误"
|
|
CASES[-1]["priority"] = "-" if expired_status == "PASS" else "P1"
|
|
|
|
for user_id in [manager_id, other_manager_id, artist1_id, artist2_id]:
|
|
assign_all_permissions(user_id)
|
|
for user_id in [artist1_id, artist2_id]:
|
|
seed_nail_artist(user_id, 1, 1)
|
|
|
|
manager_resp = login_admin(f"{RUN_ID}manager", "Aa888888!", normal_id)
|
|
manager_token, manager_info = extract_token(manager_resp)
|
|
add_case(
|
|
"MANAGER-001",
|
|
"指尖管理师/店长",
|
|
"登录",
|
|
"manager 账号绑定 normal 门店",
|
|
"后台/管理师账号登录并选择门店",
|
|
"返回 type=2 shopId=normal",
|
|
json.dumps(manager_resp["json"], ensure_ascii=False, default=str),
|
|
"PASS"
|
|
if manager_token and manager_info.get("type") == 2 and int(manager_info.get("shopId") or 0) == normal_id
|
|
else "FAIL",
|
|
"P0",
|
|
"POST /admin/auth/login",
|
|
)
|
|
other_manager_resp = login_admin(f"{RUN_ID}othermgr", "Aa888888!", other_id)
|
|
other_manager_token, _ = extract_token(other_manager_resp)
|
|
artist_resp = login_admin(f"{RUN_ID}artistone", "Aa888888!", normal_id)
|
|
artist_token, artist_info = extract_token(artist_resp)
|
|
add_case(
|
|
"ARTIST-001",
|
|
"设计师/美甲师",
|
|
"登录",
|
|
"artistone 账号绑定 normal 门店",
|
|
"设计师账号登录",
|
|
"返回 type=3 shopId=normal",
|
|
json.dumps(artist_resp["json"], ensure_ascii=False, default=str),
|
|
"PASS" if artist_token and artist_info.get("type") == 3 else "FAIL",
|
|
"P0",
|
|
"POST /admin/auth/login",
|
|
)
|
|
|
|
artist_save = {
|
|
"userId": artist1_id,
|
|
"identity": "首席设计师",
|
|
"experience": 5,
|
|
"skills": "法式,渐变,手绘",
|
|
"rating": 4.9,
|
|
"status": 1,
|
|
"participateProduction": 1,
|
|
"workStartTime": "09:00:00",
|
|
"workEndTime": "21:00:00",
|
|
"userType": 3,
|
|
"portfolio": "",
|
|
"nickname": f"{RUN_ID} artistone",
|
|
"shopId": normal_id,
|
|
"signature": "detail",
|
|
}
|
|
api_case(
|
|
"ADMIN-008",
|
|
"店长",
|
|
"设计师资料",
|
|
"设计师账号存在",
|
|
"保存设计师资料",
|
|
"返回保存后的设计师资料",
|
|
"POST",
|
|
"/admin/nail-artist/save",
|
|
manager_token,
|
|
body=artist_save,
|
|
priority="P1",
|
|
)
|
|
appointment_date = (date.today() + timedelta(days=2)).isoformat()
|
|
schedule = {
|
|
"shopId": normal_id,
|
|
"artistId": artist1_id,
|
|
"workDate": appointment_date,
|
|
"startTime": "09:00:00",
|
|
"endTime": "21:00:00",
|
|
"slotMinutes": 60,
|
|
"capacity": 1,
|
|
"status": 1,
|
|
"remark": RUN_ID,
|
|
}
|
|
api_case(
|
|
"ADMIN-011",
|
|
"店长",
|
|
"排班",
|
|
"设计师可用",
|
|
"保存设计师排班",
|
|
"t_artist_schedule 生成记录",
|
|
"POST",
|
|
"/admin/artist-schedule/save",
|
|
manager_token,
|
|
body=schedule,
|
|
priority="P1",
|
|
)
|
|
plan_date = (date.today() + timedelta(days=3)).isoformat()
|
|
schedule_plan = dict(schedule)
|
|
schedule_plan["workDate"] = plan_date
|
|
schedule_plan["remark"] = RUN_ID + "-planning"
|
|
api_case(
|
|
"ADMIN-011B",
|
|
"店长",
|
|
"排班",
|
|
"规划端新建预约目标日",
|
|
"补充规划端目标日期排班",
|
|
"t_artist_schedule 生成第二天排班",
|
|
"POST",
|
|
"/admin/artist-schedule/save",
|
|
manager_token,
|
|
body=schedule_plan,
|
|
priority="P1",
|
|
)
|
|
schedule_artist2 = dict(schedule)
|
|
schedule_artist2["artistId"] = artist2_id
|
|
schedule_artist2["remark"] = RUN_ID + "-move-target"
|
|
api_case(
|
|
"ADMIN-011C",
|
|
"店长",
|
|
"排班",
|
|
"改派目标设计师",
|
|
"给 artisttwo 补充同日排班",
|
|
"改派目标日有可用容量",
|
|
"POST",
|
|
"/admin/artist-schedule/save",
|
|
manager_token,
|
|
body=schedule_artist2,
|
|
priority="P1",
|
|
)
|
|
|
|
agreements = request("GET", "/legal-agreement/current")
|
|
versions = {}
|
|
if ok(agreements):
|
|
for item in data(agreements) or []:
|
|
versions[item.get("agreementType")] = item.get("version")
|
|
add_case(
|
|
"USER-001",
|
|
"普通用户",
|
|
"协议",
|
|
"匿名可访问",
|
|
"读取当前用户协议版本",
|
|
"返回 USER_TERMS 和 PRIVACY_POLICY",
|
|
json.dumps(agreements["json"], ensure_ascii=False, default=str),
|
|
"PASS" if ok(agreements) and len(versions) >= 2 else "FAIL",
|
|
"P0",
|
|
"GET /legal-agreement/current",
|
|
)
|
|
user_resp = login_user(f"{RUN_ID}customer", "Aa888888!", normal_id, versions)
|
|
user_token, user_info = extract_token(user_resp)
|
|
add_case(
|
|
"USER-003",
|
|
"普通用户",
|
|
"登录",
|
|
"普通用户账号已创建并提交当前协议版本",
|
|
"账号密码登录用户端",
|
|
"返回 accessToken 并写入协议同意记录",
|
|
json.dumps(user_resp["json"], ensure_ascii=False, default=str),
|
|
"PASS" if user_token and user_info.get("type") == 0 else "FAIL",
|
|
"P0",
|
|
"POST /user/login",
|
|
)
|
|
consent_count = db_one("select count(*) c from t_user_agreement_consent where user_id=%s", (customer_id,))["c"]
|
|
add_case(
|
|
"USER-003B",
|
|
"普通用户",
|
|
"协议留痕",
|
|
"用户登录成功",
|
|
"查询 t_user_agreement_consent",
|
|
"至少 2 条同意记录",
|
|
f"consent_count={consent_count}",
|
|
"PASS" if consent_count >= 2 else "FAIL",
|
|
"P1",
|
|
"DB t_user_agreement_consent",
|
|
)
|
|
|
|
product_payload = {
|
|
"shopId": normal_id,
|
|
"title": f"{RUN_ID} 主链路款式",
|
|
"description": "全链路测试作品",
|
|
"targetAudience": "通勤",
|
|
"precautions": "无",
|
|
"imageFileIds": "",
|
|
"price": "128.00",
|
|
"tags": "法式,测试",
|
|
"approximateDuration": "60分钟",
|
|
"bookableArtists": str(artist1_id),
|
|
"availableCoupons": "",
|
|
}
|
|
product_resp = api_case(
|
|
"ADMIN-012",
|
|
"店长",
|
|
"作品管理",
|
|
"normal 门店和设计师可用",
|
|
"创建可预约作品",
|
|
"返回 productId 且用户端可见",
|
|
"POST",
|
|
"/admin/product/create",
|
|
manager_token,
|
|
body=product_payload,
|
|
priority="P1",
|
|
)
|
|
product_id = id_data(product_resp) if ok(product_resp) else None
|
|
STATE["ids"]["product"] = product_id
|
|
if product_id:
|
|
api_case(
|
|
"USER-004",
|
|
"普通用户",
|
|
"浏览",
|
|
"作品已上架",
|
|
"匿名查询作品详情",
|
|
"详情返回数据",
|
|
"GET",
|
|
f"/product/get/{product_id}",
|
|
priority="P1",
|
|
)
|
|
product_list = request("GET", f"/product/list/shop/{normal_id}")
|
|
add_case(
|
|
"USER-004B",
|
|
"普通用户",
|
|
"浏览",
|
|
"作品已上架",
|
|
"匿名查询门店作品列表",
|
|
"列表包含新建作品",
|
|
json.dumps(product_list["json"], ensure_ascii=False, default=str),
|
|
"PASS" if ok(product_list) and str(product_id) in json.dumps(data(product_list), ensure_ascii=False) else "FAIL",
|
|
"P1",
|
|
f"GET /product/list/shop/{normal_id}",
|
|
)
|
|
|
|
order_id = None
|
|
order_item_id = None
|
|
if user_token and product_id:
|
|
api_case(
|
|
"USER-005",
|
|
"普通用户",
|
|
"收藏",
|
|
"用户已登录,作品存在",
|
|
"收藏作品",
|
|
"收藏成功",
|
|
"POST",
|
|
"/wishlist/add",
|
|
user_token,
|
|
body={"productId": product_id},
|
|
priority="P2",
|
|
)
|
|
api_case(
|
|
"USER-005B",
|
|
"普通用户",
|
|
"收藏",
|
|
"作品已收藏",
|
|
"查询收藏状态",
|
|
"返回已收藏",
|
|
"GET",
|
|
"/wishlist/check",
|
|
user_token,
|
|
params={"productId": product_id},
|
|
priority="P2",
|
|
)
|
|
api_case(
|
|
"USER-005C",
|
|
"普通用户",
|
|
"购物车",
|
|
"用户已登录,作品存在",
|
|
"加入购物车",
|
|
"购物车新增该作品,供结算/下单使用",
|
|
"POST",
|
|
"/cart/add",
|
|
user_token,
|
|
body={"productId": product_id, "quantity": 1},
|
|
priority="P0",
|
|
)
|
|
api_case(
|
|
"USER-005D",
|
|
"普通用户",
|
|
"购物车",
|
|
"作品已加入购物车",
|
|
"查询购物车列表",
|
|
"列表包含新建作品及可预约设计师",
|
|
"GET",
|
|
"/cart/list",
|
|
user_token,
|
|
priority="P1",
|
|
)
|
|
appointment_time = datetime.combine(
|
|
date.today() + timedelta(days=2), datetime.strptime("10:00:00", "%H:%M:%S").time()
|
|
).strftime("%Y-%m-%d %H:%M:%S")
|
|
order_body = {
|
|
"couponSourceType": "NONE",
|
|
"remark": RUN_ID,
|
|
"items": [
|
|
{
|
|
"productId": product_id,
|
|
"quantity": 1,
|
|
"artistId": artist1_id,
|
|
"appointmentTime": appointment_time,
|
|
}
|
|
],
|
|
}
|
|
api_case(
|
|
"USER-006",
|
|
"普通用户",
|
|
"结算预览",
|
|
"用户已登录,作品可预约",
|
|
"checkout-preview",
|
|
"返回金额和可用优惠信息",
|
|
"POST",
|
|
"/order/checkout-preview",
|
|
user_token,
|
|
body=order_body,
|
|
priority="P1",
|
|
)
|
|
order_resp = api_case(
|
|
"USER-007",
|
|
"普通用户",
|
|
"下单",
|
|
"用户已登录,作品/设计师/排班可用",
|
|
"创建订单",
|
|
"返回订单、订单项,DB 生成 t_order/t_order_item",
|
|
"POST",
|
|
"/order/create",
|
|
user_token,
|
|
body=order_body,
|
|
priority="P0",
|
|
)
|
|
if ok(order_resp):
|
|
order_payload = data(order_resp) or {}
|
|
order_id = int(order_payload.get("id"))
|
|
items = order_payload.get("items") or []
|
|
if items:
|
|
order_item_id = int(items[0]["id"])
|
|
else:
|
|
order_item_id = int(db_one("select id from t_order_item where order_id=%s", (order_id,))["id"])
|
|
STATE["ids"].update({"order": order_id, "orderItem": order_item_id})
|
|
order_row = db_one(
|
|
"""select o.status,o.quote_status,oi.artist_id,oi.appointment_time
|
|
from t_order o join t_order_item oi on oi.order_id=o.id where o.id=%s""",
|
|
(order_id,),
|
|
)
|
|
add_case(
|
|
"USER-007B",
|
|
"普通用户",
|
|
"DB核验",
|
|
"订单创建成功",
|
|
"查询 t_order/t_order_item",
|
|
"订单项设计师和预约时间一致",
|
|
json.dumps(order_row, ensure_ascii=False, default=str),
|
|
"PASS" if order_row and int(order_row["artist_id"]) == artist1_id else "FAIL",
|
|
"P0",
|
|
"DB t_order + t_order_item",
|
|
)
|
|
api_case(
|
|
"EDGE-001A",
|
|
"普通用户",
|
|
"预约冲突",
|
|
"首单已创建且购物车已被清空",
|
|
"重新加入同作品以验证重复预约冲突",
|
|
"加购成功,下一步应进入预约冲突校验",
|
|
"POST",
|
|
"/cart/add",
|
|
user_token,
|
|
body={"productId": product_id, "quantity": 1},
|
|
priority="P0",
|
|
)
|
|
conflict_resp = request("POST", "/order/create", user_token, body=order_body)
|
|
conflict_text = json.dumps(conflict_resp["json"], ensure_ascii=False)
|
|
add_case(
|
|
"EDGE-001",
|
|
"普通用户",
|
|
"预约冲突",
|
|
"已有同设计师同时间订单占用",
|
|
"重复提交同时间预约",
|
|
"应拦截重复占用/冲突或操作幂等保护",
|
|
conflict_text,
|
|
"PASS"
|
|
if (not ok(conflict_resp) and any(key in conflict_text for key in ["冲突", "重复", "已被预约", "预约"]))
|
|
else "FAIL",
|
|
"P0",
|
|
"POST /order/create duplicate",
|
|
)
|
|
quote_body = {"remark": "店长报价", "items": [{"orderItemId": order_item_id, "quotedPrice": "138.00"}]}
|
|
api_case(
|
|
"LINK-001",
|
|
"店长",
|
|
"报价联动",
|
|
"用户订单已创建",
|
|
"店长提交报价",
|
|
"订单 quote_status 更新为 WAIT_USER/PROCESSING",
|
|
"POST",
|
|
f"/admin/order/{order_id}/quote",
|
|
manager_token,
|
|
body=quote_body,
|
|
priority="P0",
|
|
)
|
|
api_case(
|
|
"LINK-002",
|
|
"店长",
|
|
"报价联动",
|
|
"店长已提交报价",
|
|
"店长确认报价",
|
|
"订单 quote_shop_confirmed=1",
|
|
"PUT",
|
|
f"/admin/order/{order_id}/quote/confirm",
|
|
manager_token,
|
|
priority="P0",
|
|
)
|
|
api_case(
|
|
"LINK-003",
|
|
"普通用户",
|
|
"报价联动",
|
|
"店长已确认报价",
|
|
"用户确认报价",
|
|
"订单 quote_user_confirmed=1,并生成预约占用",
|
|
"PUT",
|
|
f"/order/{order_id}/quote/confirm",
|
|
user_token,
|
|
priority="P0",
|
|
)
|
|
quote_row = db_one(
|
|
"""select o.quote_status,o.quote_user_confirmed,o.quote_shop_confirmed,oi.confirmed_price,
|
|
ar.status ar_status,ar.artist_id,ar.appointment_start_time,ar.appointment_end_time
|
|
from t_order o
|
|
join t_order_item oi on oi.order_id=o.id
|
|
left join t_appointment_reservation ar on ar.order_item_id=oi.id and ar.is_delete=0
|
|
where o.id=%s""",
|
|
(order_id,),
|
|
)
|
|
add_case(
|
|
"LINK-003B",
|
|
"普通用户/店长",
|
|
"DB联动",
|
|
"用户确认报价后",
|
|
"查询订单项和预约占用",
|
|
"报价确认、预约占用生成且时间/设计师一致",
|
|
json.dumps(quote_row, ensure_ascii=False, default=str),
|
|
"PASS" if quote_row and quote_row["ar_status"] is not None and int(quote_row["artist_id"]) == artist1_id else "FAIL",
|
|
"P0",
|
|
"DB t_order/t_order_item/t_appointment_reservation",
|
|
)
|
|
calendar_resp = request(
|
|
"GET",
|
|
"/admin/planning/calendar",
|
|
manager_token,
|
|
params={"startDate": appointment_date, "endDate": appointment_date, "artistId": artist1_id},
|
|
)
|
|
calendar_text = json.dumps(data(calendar_resp), ensure_ascii=False, default=str)
|
|
add_case(
|
|
"MANAGER-002",
|
|
"指尖管理师",
|
|
"日/周/月规划",
|
|
"订单已确认报价并生成占用",
|
|
"查询 planning calendar 日视图",
|
|
"返回包含该预约/单量",
|
|
json.dumps(calendar_resp["json"], ensure_ascii=False, default=str),
|
|
"PASS" if ok(calendar_resp) and (str(order_id) in calendar_text or str(order_item_id) in calendar_text) else "FAIL",
|
|
"P0",
|
|
"GET /admin/planning/calendar",
|
|
)
|
|
move_date = (date.today() + timedelta(days=2)).isoformat()
|
|
move_body = {
|
|
"artistId": artist2_id,
|
|
"appointmentDate": move_date,
|
|
"appointmentTime": "11:00",
|
|
"appointmentStartTime": f"{move_date} 11:00:00",
|
|
"durationMinutes": 60,
|
|
}
|
|
api_case(
|
|
"MANAGER-003",
|
|
"指尖管理师",
|
|
"改时间/改派",
|
|
"订单预约已存在",
|
|
"改派到 artisttwo 并改到 11:00",
|
|
"订单项和预约占用同步更新",
|
|
"PUT",
|
|
f"/admin/planning/appointments/{order_item_id}/time-artist",
|
|
manager_token,
|
|
body=move_body,
|
|
priority="P0",
|
|
)
|
|
move_row = db_one(
|
|
"""select oi.artist_id,oi.appointment_time,ar.artist_id ar_artist,ar.appointment_start_time
|
|
from t_order_item oi
|
|
left join t_appointment_reservation ar on ar.order_item_id=oi.id and ar.is_delete=0
|
|
where oi.id=%s""",
|
|
(order_item_id,),
|
|
)
|
|
add_case(
|
|
"MANAGER-003B",
|
|
"指尖管理师",
|
|
"DB联动",
|
|
"改派接口已执行",
|
|
"查询订单项/预约占用",
|
|
"artist_id 和 appointment_time 均同步为新值",
|
|
json.dumps(move_row, ensure_ascii=False, default=str),
|
|
"PASS"
|
|
if move_row and int(move_row["artist_id"]) == artist2_id and int(move_row["ar_artist"]) == artist2_id
|
|
else "FAIL",
|
|
"P0",
|
|
"DB t_order_item/t_appointment_reservation",
|
|
)
|
|
artist_list = request("GET", "/admin/order/list", artist_token, params={"page": 1, "size": 20}) if artist_token else {"json": {}}
|
|
add_case(
|
|
"ARTIST-002",
|
|
"设计师/美甲师",
|
|
"本人订单",
|
|
"订单已改派到 artisttwo",
|
|
"artistone 查询本人订单列表",
|
|
"不能看到已改派给他人的订单",
|
|
json.dumps(artist_list["json"], ensure_ascii=False, default=str),
|
|
"PASS" if ok(artist_list) and str(order_id) not in json.dumps(data(artist_list), ensure_ascii=False) else "FAIL",
|
|
"P0",
|
|
"GET /admin/order/list as artistone",
|
|
)
|
|
|
|
if manager_token and product_id:
|
|
plan_body = {
|
|
"customerUserId": customer_id,
|
|
"customerName": f"{RUN_ID} customer",
|
|
"phone": "19100000004",
|
|
"productId": product_id,
|
|
"quantity": 1,
|
|
"artistId": artist1_id,
|
|
"appointmentDate": plan_date,
|
|
"appointmentTime": "14:00",
|
|
"appointmentStartTime": f"{plan_date} 14:00:00",
|
|
"durationMinutes": 60,
|
|
"remark": RUN_ID + " planning",
|
|
}
|
|
plan_resp = api_case(
|
|
"LINK-004",
|
|
"指尖管理师",
|
|
"新建预约联动",
|
|
"客户/作品/设计师存在",
|
|
"规划端新建预约",
|
|
"后台订单、订单项、预约占用同步生成",
|
|
"POST",
|
|
"/admin/planning/appointments",
|
|
manager_token,
|
|
body=plan_body,
|
|
priority="P0",
|
|
)
|
|
plan_order = None
|
|
plan_item = None
|
|
if ok(plan_resp):
|
|
plan_payload = data(plan_resp) or {}
|
|
if isinstance(plan_payload, dict):
|
|
raw_item = plan_payload.get("orderItemId") or plan_payload.get("id") or 0
|
|
plan_item = int(raw_item) if raw_item else None
|
|
row = db_one("select order_id,id from t_order_item where id=%s", (plan_item,)) if plan_item else None
|
|
if not row:
|
|
row = db_one(
|
|
"""select oi.order_id,oi.id
|
|
from t_order_item oi join t_order o on o.id=oi.order_id
|
|
where o.customer_remark like %s order by oi.create_time desc limit 1""",
|
|
("%" + RUN_ID + " planning%",),
|
|
)
|
|
if row:
|
|
plan_order = int(row["order_id"])
|
|
plan_item = int(row["id"])
|
|
planning_row = (
|
|
db_one(
|
|
"""select o.id order_id,oi.id item_id,ar.id reservation_id,ar.status
|
|
from t_order o
|
|
join t_order_item oi on oi.order_id=o.id
|
|
left join t_appointment_reservation ar on ar.order_item_id=oi.id and ar.is_delete=0
|
|
where o.id=%s""",
|
|
(plan_order,),
|
|
)
|
|
if plan_order
|
|
else None
|
|
)
|
|
add_case(
|
|
"LINK-004B",
|
|
"指尖管理师/后台",
|
|
"DB联动",
|
|
"规划端新建预约成功",
|
|
"查询 t_order/t_order_item/t_appointment_reservation",
|
|
"三表同步生成且有关联",
|
|
json.dumps(planning_row, ensure_ascii=False, default=str),
|
|
"PASS" if planning_row and planning_row.get("reservation_id") else "FAIL",
|
|
"P0",
|
|
"DB order/item/reservation",
|
|
)
|
|
if plan_order and user_token:
|
|
api_case(
|
|
"LINK-005",
|
|
"后台店长",
|
|
"取消联动",
|
|
"规划端预约已生成",
|
|
"用户端取消订单",
|
|
"预约占用释放/状态变更",
|
|
"PUT",
|
|
f"/order/cancel/{plan_order}",
|
|
user_token,
|
|
priority="P0",
|
|
)
|
|
cancel_row = db_one(
|
|
"""select o.status, ar.status ar_status, ar.is_delete ar_deleted
|
|
from t_order o left join t_appointment_reservation ar on ar.order_id=o.id
|
|
where o.id=%s""",
|
|
(plan_order,),
|
|
)
|
|
add_case(
|
|
"LINK-005B",
|
|
"后台/管理师",
|
|
"DB联动",
|
|
"取消接口已执行",
|
|
"查询订单和预约占用",
|
|
"订单取消且预约不再 active",
|
|
json.dumps(cancel_row, ensure_ascii=False, default=str),
|
|
"PASS"
|
|
if cancel_row
|
|
and int(cancel_row["status"]) == 3
|
|
and (cancel_row.get("ar_status") is None or str(cancel_row["ar_status"]).upper() != "CONFIRMED")
|
|
else "FAIL",
|
|
"P0",
|
|
"DB t_order/t_appointment_reservation",
|
|
)
|
|
|
|
if other_manager_token:
|
|
other_product_list = request(
|
|
"GET", "/admin/product/list", other_manager_token, params={"page": 1, "size": 20, "shopId": normal_id}
|
|
)
|
|
other_text = json.dumps(other_product_list["json"], ensure_ascii=False, default=str)
|
|
add_case(
|
|
"PERM-001",
|
|
"后台店长",
|
|
"跨店隔离",
|
|
"other 店长登录 other 门店",
|
|
"请求 normal 门店作品列表",
|
|
"应无权查看或返回本店空列表,不泄露 normal 数据",
|
|
other_text,
|
|
"PASS" if (not ok(other_product_list) or (product_id and str(product_id) not in other_text)) else "FAIL",
|
|
"P0",
|
|
"GET /admin/product/list?shopId=normal as other manager",
|
|
)
|
|
|
|
disabled_manager_resp = try_create_service_user(admin_token, "disabledmgr", disabled_id, 2, "100000007")
|
|
disabled_text = json.dumps(disabled_manager_resp["json"], ensure_ascii=False, default=str)
|
|
add_case(
|
|
"EDGE-002",
|
|
"平台管理员",
|
|
"停用店铺",
|
|
"disabled 门店为停用",
|
|
"尝试给停用店铺创建店长",
|
|
"应拦截并提示店铺不可用/冻结",
|
|
disabled_text,
|
|
"PASS" if not ok(disabled_manager_resp) else "FAIL",
|
|
"P1",
|
|
"POST /admin/user/create disabled shop",
|
|
)
|
|
anon_write = request("POST", "/order/create", body={"items": []})
|
|
add_case(
|
|
"EDGE-003",
|
|
"未登录用户",
|
|
"鉴权健壮性",
|
|
"无 token",
|
|
"直接调用写接口下单",
|
|
"返回 401,不创建订单",
|
|
json.dumps(anon_write["json"], ensure_ascii=False, default=str),
|
|
"PASS" if anon_write["http"] in [401, 403] or anon_write["json"].get("code") in [401, 403] else "FAIL",
|
|
"P0",
|
|
"POST /order/create without token",
|
|
)
|
|
bad_token = requests.get(CORE + "/order/list", headers={"Authorization": "Bearer invalid.token.value"}, timeout=8)
|
|
add_case(
|
|
"EDGE-004",
|
|
"过期/错误 token",
|
|
"鉴权健壮性",
|
|
"错误 token",
|
|
"调用需登录 GET 接口",
|
|
"返回 401/403",
|
|
f"HTTP {bad_token.status_code}, {mask_text(bad_token.text, 300)}",
|
|
"PASS" if bad_token.status_code in [401, 403] else "FAIL",
|
|
"P0",
|
|
"GET /order/list with invalid token",
|
|
)
|
|
|
|
counts = db_counts()
|
|
orphan = db_one(
|
|
"""select count(*) c
|
|
from t_appointment_reservation ar
|
|
left join t_order_item oi on oi.id=ar.order_item_id
|
|
where ar.is_delete=0 and oi.id is null"""
|
|
)["c"]
|
|
duplicate = db_one(
|
|
"""select count(*) c from (
|
|
select artist_id, appointment_start_time, appointment_end_time, count(*) n
|
|
from t_appointment_reservation
|
|
where is_delete=0 and status=1
|
|
group by artist_id, appointment_start_time, appointment_end_time
|
|
having n>1
|
|
) x"""
|
|
)["c"]
|
|
add_case(
|
|
"PASS-010",
|
|
"全角色",
|
|
"数据一致性",
|
|
"主链路执行后",
|
|
"核验核心表计数、孤儿预约、重复占用",
|
|
"无孤儿预约、无重复 active 占用",
|
|
f"counts={counts}, orphan={orphan}, duplicate={duplicate}",
|
|
"PASS" if orphan == 0 and duplicate == 0 else "FAIL",
|
|
"P0",
|
|
"DB consistency",
|
|
)
|
|
add_case(
|
|
"UI-002",
|
|
"小程序端",
|
|
"微信开发者工具页面测试",
|
|
"当前会话未暴露微信开发者工具自动化入口",
|
|
"执行管理师/用户/设计师小程序页面真实点击",
|
|
"页面可交互、布局不遮挡",
|
|
"工具阻塞:未发现可调用微信开发者工具/小程序 MCP;API+DB 联动已执行",
|
|
"BLOCKED",
|
|
"P3",
|
|
"tool unavailable",
|
|
)
|
|
|
|
|
|
def write_reports():
|
|
summary = {"PASS": 0, "FAIL": 0, "BLOCKED": 0}
|
|
for case in CASES:
|
|
summary[case["status"]] = summary.get(case["status"], 0) + 1
|
|
result = {
|
|
"runId": RUN_ID,
|
|
"executedAt": datetime.now().isoformat(timespec="seconds"),
|
|
"summary": summary,
|
|
"state": STATE,
|
|
"cases": CASES,
|
|
"counts": db_counts(),
|
|
}
|
|
json_path = ART / f"acceptance_{RUN_ID}.json"
|
|
md_path = ART / f"acceptance_{RUN_ID}.md"
|
|
json_path.write_text(json.dumps(result, ensure_ascii=False, indent=2, default=str), encoding="utf-8")
|
|
|
|
lines = [
|
|
f"# Fingertip Designer 全链路用户视角验收清单 - {RUN_ID}",
|
|
"",
|
|
f"- 执行时间:{result['executedAt']}",
|
|
"- 环境:开发 MySQL 192.168.5.15 / 本地 Core http://127.0.0.1:18081",
|
|
"- 数据策略:执行前已重建 nailart,本轮数据均带 runId 前缀;密钥和密码不写入报告。",
|
|
"",
|
|
"## 汇总",
|
|
"",
|
|
f"- PASS: {summary.get('PASS', 0)}",
|
|
f"- FAIL: {summary.get('FAIL', 0)}",
|
|
f"- BLOCKED: {summary.get('BLOCKED', 0)}",
|
|
f"- DB counts: {result['counts']}",
|
|
"",
|
|
"## 验收清单",
|
|
"",
|
|
"| 用例编号 | 角色 | 模块 | 前置数据 | 操作步骤 | 预期结果 | 实际结果 | 状态 | 缺陷等级 | 证据 |",
|
|
"|---|---|---|---|---|---|---|---|---|---|",
|
|
]
|
|
for case in CASES:
|
|
lines.append(
|
|
"| "
|
|
+ " | ".join(
|
|
cell(case[key])
|
|
for key in [
|
|
"id",
|
|
"role",
|
|
"module",
|
|
"precondition",
|
|
"steps",
|
|
"expected",
|
|
"actual",
|
|
"status",
|
|
"priority",
|
|
"evidence",
|
|
]
|
|
)
|
|
+ " |"
|
|
)
|
|
lines.extend(["", "## 失败 / 阻塞项", "", "| 用例编号 | 等级 | 状态 | 复现/证据 |", "|---|---|---|---|"])
|
|
for case in CASES:
|
|
if case["status"] != "PASS":
|
|
lines.append(
|
|
f"| {case['id']} | {case['priority']} | {case['status']} | {cell(case['actual'])} / {cell(case['evidence'])} |"
|
|
)
|
|
md_path.write_text("\n".join(lines), encoding="utf-8")
|
|
print(json.dumps({"runId": RUN_ID, "summary": summary, "json": str(json_path), "md": str(md_path), "counts": result["counts"]}, ensure_ascii=False, default=str))
|
|
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
main()
|
|
finally:
|
|
write_reports()
|