Files
soul-yongping/scripts/test/conftest.py
Alex-larget d4ba905ee5 通过自动提及和标签创建功能,增强文章编辑功能
- 在文章编辑过程中,实现了自动创建不存在的@提及和#标签的功能,确保它们被添加到相应的数据库中。
- 更新了内容处理逻辑,以利用新创建的提及和标签,从而改善用户体验和内容管理。
- 增强了人物和链接标签创建的后端处理能力,使文章编辑过程中能够实现无缝集成。
2026-03-16 11:09:26 +08:00

68 lines
1.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
"""
共享 fixturesbase_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 ""