backend-api-test-doc-methodology.md 4.6 KB

接口测试文档 — methodology


1. 模块概览

字段 值
模块名称 methodology
模块说明 方法论展示配置管理 — 查询/保存方法论,步骤数4~10,序号连续
路由前缀 /api/v1/official-site/methodology
数据库表 official_site_methodology, official_site_methodology_steps
外部依赖 H5CacheManager(缓存失效)

2. 接口列表

序号 方法 路径 说明
1 GET /api/v1/official-site/methodology 查询方法论配置
2 POST /api/v1/official-site/methodology 保存方法论配置

3. 接口详细说明

3.1 查询方法论配置

基本信息

字段 值
方法 GET
路径 /api/v1/official-site/methodology
说明 查询当前方法论配置,无数据时返回默认值

响应参数

字段路径 类型 说明
config_id integer 配置ID,无数据时为0
display_status string 展示状态:enable/disable
main_title string 主标题,默认"方法论"
sub_title string 副标题
steps array 步骤列表,按 step_order 排序
steps[].step_id integer 步骤ID
steps[].step_icon string 步骤图标URL
steps[].step_name string 步骤名称
steps[].step_order integer 步骤序号
steps[].step_image string 步骤图片URL
updated_at string 更新时间

3.2 保存方法论配置

基本信息

字段 值
方法 POST
路径 /api/v1/official-site/methodology
说明 保存/更新方法论配置,自动替换旧数据
Content-Type application/json

请求参数

参数名 位置 类型 必填 说明
display_status body string 否 默认"enable"
main_title body string 是 主标题,最长100
sub_title body string 是 副标题,最长200
steps body array 否 步骤列表,数量4~10
steps[].step_icon body string 是 图标URL,最长500
steps[].step_name body string 是 步骤名称,最长20
steps[].step_order body integer 是 序号,从1开始连续
steps[].step_image body string 是 步骤图片URL,最长500

响应参数

字段路径 类型 说明
config_id integer 配置ID,同一配置更新后 ID 不变
updated_at string 更新时间

错误码

HTTP 状态码 触发条件 错误信息示例
400 步骤数 <4 或 >10 "4.*10"
400 步骤序号不连续 "序号"
400 步骤序号重复 "序号"

4. 测试场景

4.1 查询方法论

序号 场景名称 分类 预期结果
1 空数据返回默认 正常 config_id=0, main_title="方法论", steps=[]
2 有数据正确返回 正常 config_id>0, steps按step_order排序
3 步骤按序号排序 正常 乱序插入后返回有序

4.2 保存方法论

序号 场景名称 分类 预期结果
1 新建成功 正常 config_id>0, 查询确认4条步骤
2 更新已有配置 正常 config_id不变, main_title更新为"新标题", steps=6条
3 步骤数不足(<4) 异常 ValueError 匹配 "4.*10"
4 步骤序号不连续 异常 ValueError 匹配 "序号"
5 步骤序号重复 异常 ValueError 匹配 "序号"
6 保存后缓存失效 正常 cache.was_invalidated()==True

4.3 集成流程

序号 场景名称 预期结果
1 查询空→保存→查询有数据 config_id从0变为>0, steps=4条, orders=[1,2,3,4]

5. 对应测试代码

测试文件:backend/tests/test_methodology_api.py

测试类 测试方法 对应场景
TestGetMethodology test_query_empty_returns_default 4.1-1
TestGetMethodology test_query_with_data 4.1-2
TestGetMethodology test_steps_sorted_by_order 4.1-3
TestSaveMethodology test_save_new 4.2-1
TestSaveMethodology test_save_updates_existing 4.2-2
TestSaveMethodology test_step_count_too_few 4.2-3
TestSaveMethodology test_step_order_non_sequential 4.2-4
TestSaveMethodology test_step_order_duplicate 4.2-5
TestSaveMethodology test_save_invalidates_cache 4.2-6
TestIntegrationFlow test_query_save_query 4.3-1