Files
smart-management-auto-test/dulizhan/test_case/TestCase/接口/JoyHub/Joyhub_Faq.py
zhouqi 3191ec4f3c feat: 新增JoyHub模块测试用例和功能增强
1. 新增模块测试用例:
   - News分类接口测试 (Joyhub_NewsCate.py)
   - News内容接口测试 (Joyhub_News.py)
   - 产品分类接口测试 (Joyhub_ProductCate.py)
   - 产品属性接口测试 (Joyhub_ProductAttr.py)
   - 产品管理接口测试 (Joyhub_Product.py)
   - FAQ分类接口测试 (Joyhub_FaqCate.py)
   - FAQ内容接口测试 (Joyhub_Faq.py)
   - 博客分类接口测试 (Joyhub_BlogCate.py)
   - 地址国家接口测试 (Joyhub_AddressCountry.py)
   - 下载二维码接口测试 (Joyhub_DownloadQrcode.py)
   - 支付页产品推荐接口测试 (Joyhub_ProductPaymentRecommend.py)

2. 新增业务关键字层:
   - NewsCateManage.py
   - NewsManage.py
   - ProductCateManage.py
   - ProductAttrManage.py
   - ProductManage.py
   - FaqCateManage.py
   - FaqManage.py
   - BlogCateManage.py
   - AddressCountryManage.py
   - DownloadQrcodeManage.py
   - ProductPaymentRecommendManage.py

3. 接口层增强:
   - Dlizhan_interface.py 添加JoyHub相关接口封装

4. 功能增强:
   - run_tests.py 添加自动清除旧测试结果和报告功能
   - Joyhub_Product.py 添加数据库连接获取运费模板ID和品牌ID

5. 修复:
   - 修复产品创建测试用例缺少前置数据问题
2026-05-08 18:09:48 +08:00

182 lines
8.9 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 -*-
"""
FAQ数据管理接口测试用例
"""
import json
import pytest
import allure
import logging
import time
import requests
from dulizhan.library.BusinessKw.JoyHub.FaqManage import FaqManage
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@allure.feature("管理后台 - FAQ数据管理模块")
class TestFaqManage:
faq_id = None
faq_cate_id = None
token_set = False
@classmethod
def setup_class(cls):
"""在整个测试类开始时登录一次所有测试用例共享token"""
logging.info("=============================================")
logging.info("=========== 开始登录获取Token ============")
logging.info("=============================================")
cls.test_case = FaqManage()
username = "joytest"
password = "Zhou1599"
cls.test_case._clear_user_fingerprint(username)
url = 'https://joyhub-website-manager-api-test.best-envision.com/admin-api/system/auth/login-dev'
payload = {'username': username, 'password': password}
headers = {'Content-Type': 'application/json', 'tenant-id': '126'}
response = requests.post(url, json=payload, headers=headers, verify=False, timeout=10)
login_response = response.json()
if login_response and login_response.get('code') == 0:
token = login_response.get('data', {}).get('accessToken', '')
cls.test_case.set_joyhub_token(token)
cls.token_set = True
logging.info("登录成功Token已设置")
# 获取FAQ分类ID供后续使用
cate_list_resp = cls.test_case.kw_joyhub_faq_cate_list_get()
if cate_list_resp.get('code') == 0 and cate_list_resp.get('data'):
cls.faq_cate_id = cate_list_resp['data'][0].get('faqCateId')
logging.info(f"获取到FAQ分类ID: {cls.faq_cate_id}")
else:
logging.error(f"登录失败: {login_response}")
@allure.story("验证登录接口")
@allure.title("测试登录接口")
def test_joyhub_login_post(self):
"""测试登录接口"""
assert TestFaqManage.token_set is True, "登录失败未获取到token"
logging.info("登录验证通过")
@allure.story("验证获得FAQ数据分页")
@allure.title("测试获得FAQ数据分页接口")
def test_joyhub_faq_page_get(self):
"""测试获得FAQ数据分页接口"""
with allure.step("1. 调用分页接口"):
resp = self.test_case.kw_joyhub_faq_page_get(page_no=1, page_size=10)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "list" in resp["data"], "响应中缺少list字段"
assert isinstance(resp["data"]["list"], list), "list字段不是列表类型"
logging.info("获得FAQ数据分页验证通过")
@allure.story("验证获得FAQ数据详情")
@allure.title("测试获得FAQ数据详情接口")
def test_joyhub_faq_get_get(self):
"""测试获得FAQ数据详情接口"""
with allure.step("1. 从分页获取现有FAQ数据ID"):
page_resp = self.test_case.kw_joyhub_faq_page_get(page_no=1, page_size=10)
assert page_resp.get("code") == 0, f"获取分页失败code={page_resp.get('code')}, msg={page_resp.get('msg')}"
assert page_resp.get("data", {}).get("list"), "没有找到可用的FAQ数据"
faq_id = page_resp["data"]["list"][0].get("id")
assert faq_id, "FAQ数据ID为空"
with allure.step("2. 调用获取详情接口"):
resp = self.test_case.kw_joyhub_faq_get_get(faq_id=faq_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"请求失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert "id" in resp["data"], "响应中缺少id字段"
assert resp["data"]["id"] == faq_id, "返回的ID与请求的ID不一致"
assert "question" in resp["data"], "响应中缺少question字段"
assert isinstance(resp["data"]["question"], str), "question字段不是字符串类型"
logging.info("获得FAQ数据详情验证通过")
@allure.story("验证创建和更新FAQ数据")
@allure.title("测试创建和更新FAQ数据接口")
def test_joyhub_faq_create_and_update(self):
"""测试创建和更新FAQ数据接口"""
if not TestFaqManage.faq_cate_id:
pytest.skip("没有可用的FAQ分类跳过测试")
with allure.step("1. 创建FAQ数据"):
timestamp = int(time.time())
create_params = {
"faq_cate_id": TestFaqManage.faq_cate_id,
"question": f"测试问题_{timestamp}",
"answer": f"测试回答内容_{timestamp}",
"rank_num": 1,
"lang": "zh_CN",
"is_hot": 0,
"status": 1
}
allure.attach(json.dumps(create_params, ensure_ascii=False), name="创建请求参数", attachment_type=allure.attachment_type.TEXT)
create_resp = self.test_case.kw_joyhub_faq_create_post(**create_params)
allure.attach(json.dumps(create_resp, ensure_ascii=False, indent=2), name="创建响应数据", attachment_type=allure.attachment_type.JSON)
assert create_resp is not None, "响应为空"
assert "code" in create_resp, "响应中缺少code字段"
assert create_resp["code"] == 0, f"创建失败code={create_resp.get('code')}, msg={create_resp.get('msg')}"
assert "data" in create_resp, "响应中缺少data字段"
assert isinstance(create_resp["data"], int), "data字段不是整数类型"
faq_id = create_resp["data"]
TestFaqManage.faq_id = faq_id
logging.info(f"创建FAQ数据成功ID: {faq_id}")
with allure.step("2. 调用更新接口"):
timestamp = int(time.time())
update_params = {
"faq_id": faq_id,
"faq_cate_id": TestFaqManage.faq_cate_id,
"question": f"测试问题_{timestamp}_updated",
"answer": f"测试回答内容_{timestamp}_updated",
"rank_num": 2,
"lang": "en",
"is_hot": 1,
"status": 2
}
allure.attach(json.dumps(update_params, ensure_ascii=False), name="更新请求参数", attachment_type=allure.attachment_type.TEXT)
update_resp = self.test_case.kw_joyhub_faq_update_put(**update_params)
allure.attach(json.dumps(update_resp, ensure_ascii=False, indent=2), name="更新响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("3. 验证更新响应"):
assert update_resp is not None, "响应为空"
assert "code" in update_resp, "响应中缺少code字段"
assert update_resp["code"] == 0, f"更新失败code={update_resp.get('code')}, msg={update_resp.get('msg')}"
assert "data" in update_resp, "响应中缺少data字段"
assert update_resp["data"] is True, "更新FAQ数据失败"
logging.info("创建并更新FAQ数据验证通过")
@allure.story("验证删除FAQ数据")
@allure.title("测试删除FAQ数据接口")
def test_joyhub_faq_delete_delete(self):
"""测试删除FAQ数据接口"""
if not TestFaqManage.faq_id:
pytest.skip("没有可删除的FAQ数据")
with allure.step("1. 调用删除接口"):
resp = self.test_case.kw_joyhub_faq_delete_delete(faq_id=TestFaqManage.faq_id)
allure.attach(json.dumps(resp, ensure_ascii=False, indent=2), name="响应数据", attachment_type=allure.attachment_type.JSON)
with allure.step("2. 验证响应"):
assert resp is not None, "响应为空"
assert "code" in resp, "响应中缺少code字段"
assert resp["code"] == 0, f"删除失败code={resp.get('code')}, msg={resp.get('msg')}"
assert "data" in resp, "响应中缺少data字段"
assert resp["data"] is True, "删除FAQ数据失败"
logging.info("删除FAQ数据验证通过")