# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test62
# FileName:      test_bpm.py
# Author:       lao_zhao
# Datetime:     2024/9/2 16:55
# Description:
# 
# ---------------------------------------------------------------------------
import allure
import pytest



class TestBPMDem:
    host = 'http://36.139.193.99:8088'

    @allure.epic("BPM系统-场景测试")
    @allure.feature("维度管理")
    @allure.story("添加维度")
    @allure.title("添加维度-正向用例")
    @allure.severity("高")
    @pytest.mark.dependency(depends=['test_case/test_dependency/test_bpm_1_login.py::TestBPMLogin::test_login'], scope="session")
    def test_add_dem(self, fix_req, fix_db, fix_dependency):
        # 判断Session对象中是否有token，如果有再添加维度，如果没有之间报错
        if "Authorization" in list(fix_req.headers.keys()):
            # 配置添加维度的数据
            add_dem_url = self.host + "/api/demension/v1/dem/addDem"
            add_dem_data = {
                    "code": "testAddDem",
                    "description": "testAddDem",
                    "isDefault": 0,
                    "name": "测试添加的维度"
                }
            # 添加维度之前需要删除数据库中已存在的维度
            fix_db.delete("""delete from uc_demension where CODE_="testAddDem";""")
            # 发送请求
            res = fix_req.request(method="post", url=add_dem_url, json=add_dem_data)
            # 断言
            try:
                assert "添加维度成功" in res.text
            except AssertionError:
                raise AttributeError("断言失败")
            else:
                dem_id = fix_db.select("""select ID_ from uc_demension where CODE_="testAddDem";""")
                fix_dependency["demId"] = dem_id
        else:
            raise ValueError("Session对象中没有token")



if __name__ == '__main__':
    pytest.main()