import time

import allure

from common.DButils import DButils
from common.untils import DriverTools
from config import user_name, password, updata_pdf_path, login_url, userid, updata_pdf_name
from paga.AIEditingRoomPage import AIER
from paga.AiPrequalificationPage import Aiprequalification
from paga.LoginPage import Login


# AI预审ui自动化测试
class TestPrequalification:
    # 类前置
    def setup_class(self):
        self.login = Login()
        self.AI = AIER()
        self.aiprequailification = Aiprequalification()
        self.dbtuils = DButils()

    def setup_method(self):
        self.driver = DriverTools.get_driver().get(login_url)
        self.login.login(user_name, password)

    # 类后置
    def teardown_class(self):
        DriverTools.quit_driver()

    # AI预审流程
    @allure.feature("AI预审流程")
    def test_uodate_file(self):
        self.AI.to_AI_Prequalification()
        time.sleep(3)
        self.aiprequailification.update_pdf(updata_pdf_path)
        time.sleep(300)
        data = self.dbtuils.select_sql(
            f"SELECT file_name,status FROM aireview.assistant_task where create_user ={userid} and assistant_code "
            "='preliminarytrial' order by biz_id desc limit 1;")
        assert data[0][0] == updata_pdf_name
        assert data[0][1] == 99
