# Time    : 2024/7/23 18:02
# Author  : wangchao
# File    : Test_HistoryLibraryManagement.py
# Description : 历史库管理测试类
import os.path

import allure
import pytest
from playwright.sync_api import expect

from BasePage.BasePage import BasePage
from Common.AllurePretty import PrettyAllure
from Config import Config
from Pages.HistoryLibraryPage.HistoryLibraryManagement import HistoryLibraryManagement
from Utils.ReadYaml import ReadYaml


@allure.epic("CMS2.0UI自动化测试")
@allure.feature("历史库管理")
class TestHistoryLibraryManagement:

	@allure.story("历史库数据备份")
	@pytest.mark.run(order=1)
	@PrettyAllure.PrettyAllureCaseWarpper
	@pytest.mark.parametrize("CaseData", ReadYaml(os.path.join(Config.test_datas_dir, "HistoryLibraryManagementData/TestHistoryLibraryBackup.yaml")).read())
	def test_history_library_backup(self, page, CaseData: dict):
		bp = BasePage(page)
		hlp = HistoryLibraryManagement(page)
		bp._goto_url_history_management()
		hlp.history_library_backup()
		expect(hlp.history_library_backup_success_toast_locator).to_have_text("数据备份成功") #断言备份成功

	@allure.story("历史库数据清除")
	@pytest.mark.run(order=1)
	@PrettyAllure.PrettyAllureCaseWarpper
	@pytest.mark.parametrize("CaseData", ReadYaml(os.path.join(Config.test_datas_dir, "HistoryLibraryManagementData/TestHistoryLibraryClear.yaml")).read())
	def test_history_library_clear(self, page, CaseData: dict):
		bp = BasePage(page)
		hlp = HistoryLibraryManagement(page)
		bp._goto_url_history_management()
		hlp.history_library_clear()
		expect(hlp.history_library_clear_success_toast_locator).to_have_text("数据清除成功") #断言清除成功
