# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test59
# FileName:      test_login_addDem_getDemMsg.py
# Author:       laozhao
# Datetime:     2024/3/18 17:17
# Description:
# 
# ---------------------------------------------------------------------------
import base64

import allure
import pytest
import requests
from faker import Faker

depends_data = {}


# 登录
@allure.epic("BPM-场景")
@allure.feature("认证接口")
@allure.story("登录系统")
@allure.title("场景用例的正向用例")
@allure.severity("高")
@pytest.mark.dependency()
def test_login():
    url = "http://120.46.172.186:8080/auth"
    data = {"username": "admin", "password": base64.b64encode("123456".encode()).decode()}
    res = requests.post(url=url, json=data)

    token = res.json().get("token")
    depends_data["Authorization"] = "Bearer "+token
    assert "超级" in res.text


@allure.epic("BPM-场景")
@allure.feature("维度管理")
@allure.story("添加维度")
@allure.title("添加维度场景用例的正向用例")
@allure.severity("高")
@pytest.mark.dependency(depends=["test_login"])
def test_add_dem():
    url = "http://120.46.172.186:8080/api/demension/v1/dem/addDem"
    data = Faker(locale="zh_cn")
    code = data.phone_number()
    data = {
        "code": code,
        "description": "test_add_dem_1234",
        "isDefault": 0,
        "name": "test_add_dem_1234"
    }
    res = requests.post(url=url, json=data, headers={"Authorization": depends_data["Authorization"]})
    depends_data["dem_code"] = code
    assert "成功" in res.text


@allure.epic("BPM-场景")
@allure.feature("维度管理")
@allure.story("根据维度编码获取维度信息")
@allure.title("根据维度编码获取维度信息的正向用例")
@allure.severity("高")
@pytest.mark.dependency(depends=["test_add_dem"])
def test_get_dem_msg():
    url = "http://120.46.172.186:8080/api/demension/v1/dem/getDem"
    data = {"code": depends_data["dem_code"]}

    res = requests.get(url=url, params=data, headers={"Authorization": depends_data["Authorization"]})
    assert "isDelete" in res.text

