import time

import allure

from common.DButils import DButils
from common.untils import DriverTools
from config import user_name, password, word_text, \
    updata_traditional_path, updata_music_path, updata_qrcode_path, updata_video_path, updata_picture_path, \
    knowledge_text, login_url, userid, updata_pdf_path, updata_pdf_name
from paga.AIEditingRoomPage import AIER
from paga.AiPrequalificationPage import Aiprequalification
from paga.AiReviewPage import Aireview
from paga.LoginPage import Login


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

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

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

    # 图书审校流程
    @allure.feature("图书审校流程")
    def test_book_review(self):
        self.aireview.book_review(updata_pdf_path)
        time.sleep(3)
        data = self.dbtuils.select_sql(
            f'SELECT file_name ,status  FROM aireview.assistant_task where create_user ={userid} and assistant_code '
            '="diction" order by biz_id desc limit 1;')

        assert data[0][0] == updata_pdf_name

    # 文本审校流程
    @allure.feature("文本审校流程")
    def test_text_revierw(self):
        self.aireview.text_revierw(word_text)
        time.sleep(5)
        data = self.dbtuils.select_sql(f"SELECT file_type  FROM aireview.assistant_task where create_user ={userid}  "
                                       "order by biz_id desc limit 1;")
        assert data[0][0] == "text"

    # 繁体字审校流程
    @allure.feature("繁体字审校流程")
    def test_traditional_review(self):
        self.aireview.traditional_review(updata_traditional_path)
        time.sleep(5)
        data = self.dbtuils.select_sql(f"SELECT assistant_code  FROM aireview.assistant_task where create_user ={userid} "
                                       "order by biz_id desc limit 1;")
        assert data[0][0] == "unsimplified"

    # 多媒体审校流程
    @allure.feature("多媒体审校流程")
    def test_media_review(self):
        self.aireview.media_review([updata_picture_path, updata_video_path, updata_qrcode_path, updata_music_path])
        time.sleep(5)

    # 查词查术语流程
    @allure.feature("查词查术语流程")
    def test_find_word(self):
        self.aireview.find_word(knowledge_text)
        time.sleep(5)

    # 知识查证流程
    @allure.feature("知识查证流程")
    def test_find_knowledge(self):
        self.aireview.find_knowledge(knowledge_text)
        time.sleep(5)
