# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test65
# FileName:      test1.py
# Author:       lao_zhao
# Datetime:     2025/3/11 9:45
# Description:
# 
# ---------------------------------------------------------------------------
import random
import string

import allure
import pytest



@allure.epic("BPM项目-场景测试")
@allure.feature("维度管理")
@allure.story("添加维度")
@allure.title("正向用例")
@pytest.mark.dependency(depends=["test_case/test_dependency/test_demo1/test_demo.py::test_login"], scope="session")
def test_add_dem(session_fix, set_value):
    add_dem_url = "http://36.139.193.99:8088/api/demension/v1/dem/addDem"
    dem_code = "".join(random.sample(string.ascii_letters, 13))
    add_dem_data = {
            "code": dem_code,
            "description": "xx",
            "isDefault": 0,
            "name": dem_code
        }
    res = session_fix.request(method="post", url=add_dem_url, json=add_dem_data)
    try:
        assert "成功" in res.text
    except AssertionError:
        raise AssertionError("断言失败")
    else:
        set_value("dem_code", dem_code)


@allure.epic("BPM项目-场景测试")
@allure.feature("维度管理")
@allure.story("获取维度信息")
@allure.title("正向用例")
@pytest.mark.dependency(depends=["test_case/test_dependency/test_demo2/test_demension_func.py::test_add_dem"], scope="session")
def test_get_dem_msg(get_value, session_fix, set_value):
    get_dem_msg_url = "http://36.139.193.99:8088/api/demension/v1/dem/getDem"
    get_dem_msg_data = {"code": get_value("dem_code")}
    res = session_fix.request(method="get", url=get_dem_msg_url, params=get_dem_msg_data)
    try:
        assert "0" in res.text
    except AssertionError:
        raise AssertionError("断言失败")
    else:
        dem_id = res.json()["id"]
        set_value("dem_id", dem_id)
