Go + PostgreSQL + Valkey backend (cmd/internal/migrations), uni-app mobile frontend, PC web (web/), admin console (admin/), Android WebView container (android_project/). Build artifacts, node_modules, local env and debug screenshots excluded.
133 lines
5.2 KiB
Python
133 lines
5.2 KiB
Python
import requests
|
|
import sys
|
|
import time
|
|
|
|
BASE = "http://127.0.0.1:18080/api/v1"
|
|
|
|
def test_v5():
|
|
print("=== 开始运行 V5 新特性冒烟测试 ===")
|
|
suf = str(int(time.time()))
|
|
acc = f"user_{suf}"
|
|
pwd = "password-123456"
|
|
|
|
# 1. 注册
|
|
res = requests.post(f"{BASE}/auth/register", json={
|
|
"account": acc,
|
|
"password": pwd,
|
|
"nickname": f"测试用户_{suf}"
|
|
})
|
|
assert res.status_code == 201, f"注册失败: {res.text}"
|
|
token = res.json()["data"]["token"]
|
|
user_id = res.json()["data"]["user"]["id"]
|
|
headers = {"Authorization": f"Bearer {token}"}
|
|
print(f"✓ 用户注册成功 acc={acc} id={user_id}")
|
|
|
|
# 将其设为 super_admin
|
|
import subprocess
|
|
cmd = [
|
|
"C:/Program Files/PostgreSQL/16/bin/psql.exe",
|
|
"-h", "127.0.0.1", "-p", "55432", "-U", "postgres", "-d", "article_platform",
|
|
"-c", f"UPDATE users SET role='super_admin' WHERE id='{user_id}';"
|
|
]
|
|
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL)
|
|
print("✓ 用户权限已提升为 super_admin")
|
|
|
|
# 2. 修改个人资料
|
|
res = requests.put(f"{BASE}/users/me/profile", headers=headers, json={
|
|
"nickname": "烟测作者V5",
|
|
"bio": "这是我的个性签名",
|
|
"gender": "male",
|
|
"region": "北京 海淀"
|
|
})
|
|
assert res.status_code == 200, f"修改个人资料失败: {res.text}"
|
|
data = res.json()["data"]["user"]
|
|
assert data["nickname"] == "烟测作者V5"
|
|
assert data["gender"] == "male"
|
|
assert data["region"] == "北京 海淀"
|
|
print("✓ 修改个人资料成功 (nickname/bio/gender/region)")
|
|
|
|
# 3. 话题流程
|
|
res = requests.post(f"{BASE}/admin/topics", headers=headers, json={
|
|
"name": f"摄影交流_{suf}",
|
|
"description": "摄影与器材话题讨论",
|
|
"cover_url": "https://example.com/topic.jpg",
|
|
"status": "active"
|
|
})
|
|
assert res.status_code == 201, f"创建话题失败: {res.text}"
|
|
topic_id = res.json()["data"]["topic"]["id"]
|
|
print(f"✓ 管理后台创建话题成功 id={topic_id}")
|
|
|
|
res = requests.get(f"{BASE}/topics")
|
|
assert res.status_code == 200 and len(res.json()["data"]["items"]) >= 1
|
|
print("✓ 话题广场列表读取成功")
|
|
|
|
res = requests.post(f"{BASE}/topics/{topic_id}/follow", headers=headers)
|
|
assert res.status_code == 200 and res.json()["data"]["is_followed"] is True
|
|
print("✓ 关注话题成功")
|
|
|
|
res = requests.get(f"{BASE}/users/me/topics", headers=headers)
|
|
assert res.status_code == 200 and len(res.json()["data"]["items"]) >= 1
|
|
print("✓ 我的关注话题列表读取成功")
|
|
|
|
# 4. 创建一篇文章
|
|
res = requests.post(f"{BASE}/articles", headers=headers, json={
|
|
"title": f"测试文章_{suf}",
|
|
"subtitle": "副标题"
|
|
})
|
|
assert res.status_code == 201, f"创建文章失败: {res.text}"
|
|
mask_id = res.json()["data"]["mask_id"]
|
|
print(f"✓ 创建文章成功 mask_id={mask_id}")
|
|
|
|
# 浏览文章
|
|
res = requests.post(f"{BASE}/articles/{mask_id}/view", headers=headers)
|
|
assert res.status_code == 200
|
|
print(f"✓ 触发文章浏览成功")
|
|
|
|
res = requests.get(f"{BASE}/users/me/history", headers=headers)
|
|
assert res.status_code == 200 and len(res.json()["data"]["items"]) >= 1
|
|
print("✓ 我的浏览历史列表成功读取")
|
|
|
|
# 单篇数据看板
|
|
res = requests.get(f"{BASE}/author/articles/{mask_id}/stats", headers=headers)
|
|
assert res.status_code == 200, f"单篇看板失败: {res.status_code} {res.text}"
|
|
stats_data = res.json()["data"]
|
|
assert "metrics" in stats_data and "daily_trends" in stats_data
|
|
print("✓ 单篇作品数据看板读取成功")
|
|
|
|
# 5. 模板流程
|
|
res = requests.post(f"{BASE}/templates", headers=headers, json={
|
|
"title": "清新旅拍模板",
|
|
"description": "适合旅行游记",
|
|
"category": "travel",
|
|
"target_platform": "all",
|
|
"sections_json": [{"kind": "text", "text": "模板预设内容"}]
|
|
})
|
|
assert res.status_code == 201, f"创建模板失败: {res.text}"
|
|
tmpl_id = res.json()["data"]["template"]["id"]
|
|
print(f"✓ 创建模板成功 id={tmpl_id}")
|
|
|
|
res = requests.get(f"{BASE}/templates")
|
|
assert res.status_code == 200 and len(res.json()["data"]["items"]) >= 1
|
|
print("✓ 模板列表读取成功")
|
|
|
|
# 6. 我的收藏与点赞列表
|
|
res = requests.post(f"{BASE}/articles/{mask_id}/like", headers=headers)
|
|
assert res.status_code == 200
|
|
res = requests.post(f"{BASE}/articles/{mask_id}/favorite", headers=headers)
|
|
assert res.status_code == 200
|
|
|
|
res = requests.get(f"{BASE}/users/me/favorites", headers=headers)
|
|
assert res.status_code == 200 and len(res.json()["data"]["items"]) >= 1
|
|
res = requests.get(f"{BASE}/users/me/likes", headers=headers)
|
|
assert res.status_code == 200 and len(res.json()["data"]["items"]) >= 1
|
|
res = requests.get(f"{BASE}/users/me/followings", headers=headers)
|
|
assert res.status_code == 200
|
|
res = requests.get(f"{BASE}/users/me/followers", headers=headers)
|
|
assert res.status_code == 200
|
|
print("✓ 我的收藏、点赞、关注列表全部读取验证成功")
|
|
|
|
print("=== 全量 V5 新特性冒烟测试全部顺利通过!===")
|
|
|
|
if __name__ == "__main__":
|
|
test_v5()
|