# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test63
# FileName:      test_bpm.py
# Author:       lao_zhao
# Datetime:     2024/11/5 15:39
# Description:
# 
# ---------------------------------------------------------------------------
import pytest
import allure
from APIAutoTest_v3_1 import log
from APIAutoTest_v3_1.common.read_excel import ReadExcel
from APIAutoTest_v3_1.test_case.test_demo import USERNAME


class TestBPM:

    @allure.epic("BPM_DEMO")
    # @allure.feature("模块名称")
    # @allure.story("接口名称")
    # @allure.title("用例标题")
    # @allure.severity("用例等级")
    @pytest.mark.parametrize("module, api, title, level, method, url, mime, case_data, expect_data, sql_type, sql_data, update_key", ReadExcel(USERNAME).get_data())
    def test_bpm(self, req_fix, module, api, title, level, method, url, mime, case_data, expect_data, sql_type, sql_data, update_key):
        allure.dynamic.feature(module)
        allure.dynamic.story(api)
        allure.dynamic.title(title)
        allure.dynamic.severity(level)

        # 使用RequestsMethod类对象调用request_all方法发送请求。自定义固件就是RequestsMethod类对象
        res = req_fix.request_all(req_method=method, req_url=url, req_mime=mime, req_case_data=case_data, sql_type=sql_type, sql_data=sql_data, update_key=update_key)

        # 断言
        try:
            for key in expect_data.keys():
                assert res.json().get(key) == expect_data[key]
        except AssertionError:
            log.error(f"断言失败，用例数据为：{case_data}，期望数据为：{expect_data}， 服务器返回的数据为：{res.text}")
            raise AssertionError("断言失败")
        else:
            log.info(f"断言成功，用例数据为：{case_data}，期望数据为：{expect_data}， 服务器返回的数据为：{res.text}")