# -*-coding:utf-8 -*- #
# ---------------------------------------------------------------------------
# ProjectName:   test64
# FileName:      test_auth_api.py
# Author:       lao_zhao
# Datetime:     2024/12/25 10:50
# Description:
# 
# ---------------------------------------------------------------------------
import pytest
import allure

login_case_data = [
    ["正向用例", {"username":"admin","password":"WuHRoZXGrg1LHOix8EVOhqGcu3CEEd0hOWNPRENTScZMb2ekrEtBGGBJweUxGKi36k346+OrS5mD3nnjyrocZOfzo4UqoshNoqJgx09u81LV2vc53Sy83DsBWKGoZZZRUhsDrpRj8feUlakJMCpgqswG0y9jm95Lk9auWpI146I="}, {"username":"超级管理员","account":"admin","userId":"1","expiration":86400}],
    ["反向用例", {"username":"admin","password":""}, {"message": "账号或密码错误1"}]
]


class TestAuth:

    @allure.epic("BPM-场景测试")
    @allure.feature("认证接口")
    @allure.story("登录系统")
    @allure.title("登录系统的标题")
    @allure.severity("高")
    @pytest.mark.dependency(scope="session")
    @pytest.mark.parametrize("title, case_data, expect_data", login_case_data)
    def test_login(self, req_fix, title, case_data, expect_data):
        res = req_fix.request(method="post", url="http://36.139.193.99:8088/auth", json=case_data)
        for key in expect_data:
            assert res.json().get(key) == expect_data[key]
        else:
            if title == "正向用例":
                req_fix.headers.update({"Authorization": "Bearer "+res.json().get("token")})
