from common.dataHandle import DataHandle
import unittest
from common.log import Log
from cases.login import Login
from cases.downloadfile import DownloadFile
from cases.userinfo import UserInfo


class TestDownloadLogFileBB(unittest.TestCase):
    """日志部分-下载log文件"""

    @classmethod
    def setUpClass(cls):
        Log.info('TestDownloadLogFileBB START BB端')
        cls.node = 2
        cls.dh = DataHandle()
        # 布里端
        cls.L = Login(node=cls.node)
        cls.admin_cookies = cls.L.get_cookie()
        cls.df = DownloadFile(node=cls.node)
        cls.ui = UserInfo(node=cls.node)
        # auto登录cookie
        cls.AUTO_cookies = cls.ui.modify_cookies(data_id=3001, node=cls.node)

    def setUp(self):
        Log.debug('---------')
        pass

    def test_download_log_file_success(self):
        """BB 日志部分-下载log文件 成功"""
        Log.debug('test_download_log_file_success start')
        para_id = 43
        data_id = 43004
        res = self.df.base_download_log_file(para_id=para_id, data_id=data_id, cookies=self.admin_cookies,
                                             flag=True)
        self.assertTrue(res, msg='result check fail')
        Log.debug('test_download_log_file_success end')
        pass

    def test_download_log_file_no_session_fail(self):
        """BB 日志部分-下载log文件 未登录，失败"""
        Log.debug('test_download_log_file_no_session_fail start')
        para_id = 43
        data_id = 43005
        res = self.df.base_download_log_file(para_id=para_id, data_id=data_id, cookies=None,
                                             flag=False)
        self.assertTrue(res, msg='result check fail')
        Log.debug('test_download_log_file_no_session_fail end')
        pass

    def test_download_log_file_not_admin_fail(self):
        """BB 普通用户下载log失败"""
        Log.debug('test_download_log_file_not_admin_fail start')
        para_id = 43
        data_id = 43006
        res = self.df.base_download_log_file(para_id=para_id, data_id=data_id, cookies=self.AUTO_cookies,
                                             flag=False)
        self.assertTrue(res, msg='result check fail')
        Log.debug('test_download_log_file_not_admin_fail end')
        pass

    def tearDown(self):
        Log.debug('---------')
        pass

    @classmethod
    def tearDownClass(cls):
        Log.info('TestDownloadLogFileBB END BB端')
