chore: 清理敏感与开发文档,仅同步代码
- 永久忽略并从仓库移除 开发文档/ - 移除并忽略 .env 与小程序私有配置 - 同步小程序/管理端/API与脚本改动 Made-with: Cursor
This commit is contained in:
67
scripts/test/conftest.py
Normal file
67
scripts/test/conftest.py
Normal file
@@ -0,0 +1,67 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
共享 fixtures:base_url、admin_token、miniapp_token
|
||||
"""
|
||||
import pytest
|
||||
import requests
|
||||
|
||||
from config import (
|
||||
API_BASE,
|
||||
ADMIN_USERNAME,
|
||||
ADMIN_PASSWORD,
|
||||
MINIAPP_DEV_USER_ID,
|
||||
get_env_banner,
|
||||
)
|
||||
|
||||
|
||||
def pytest_report_header(config):
|
||||
"""pytest 报告头部显示测试环境,避免误测"""
|
||||
return get_env_banner().strip().split("\n")
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def base_url():
|
||||
"""API 基础地址"""
|
||||
return API_BASE
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def admin_token(base_url):
|
||||
"""
|
||||
管理端 JWT。通过 POST /api/admin 登录获取。
|
||||
失败时返回空字符串,用例可 skip。
|
||||
"""
|
||||
try:
|
||||
r = requests.post(
|
||||
f"{base_url}/api/admin",
|
||||
json={"username": ADMIN_USERNAME, "password": ADMIN_PASSWORD},
|
||||
timeout=10,
|
||||
)
|
||||
data = r.json()
|
||||
if data.get("success") and data.get("token"):
|
||||
return data["token"]
|
||||
except Exception:
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
@pytest.fixture(scope="session")
|
||||
def miniapp_token(base_url):
|
||||
"""
|
||||
小程序 token。通过 POST /api/miniprogram/dev/login-as 获取(仅 APP_ENV=development)。
|
||||
若 MINIAPP_DEV_USER_ID 未配置或接口不可用,返回空字符串。
|
||||
"""
|
||||
if not MINIAPP_DEV_USER_ID:
|
||||
return ""
|
||||
try:
|
||||
r = requests.post(
|
||||
f"{base_url}/api/miniprogram/dev/login-as",
|
||||
json={"userId": MINIAPP_DEV_USER_ID},
|
||||
timeout=10,
|
||||
)
|
||||
data = r.json()
|
||||
if data.get("success") and data.get("data", {}).get("token"):
|
||||
return data["data"]["token"]
|
||||
except Exception:
|
||||
pass
|
||||
return ""
|
||||
Reference in New Issue
Block a user