Hacked By AnonymousFox

Current Path : /lib/python2.7/site-packages/test/unit/routine/
Upload File :
Current File : //lib/python2.7/site-packages/test/unit/routine/test_routine.py

from datetime import datetime

import pytest

from hw_cpbackup.backup import BackupRoutine
from hw_cpbackup.routine import RoutineControl
from hw_cpbackup.sanity import BackupSanity


@pytest.fixture(scope='module')
def rc():
    _rc = RoutineControl()
    _rc._dry_run = True
    _rc._no_alert = True
    return _rc


@pytest.fixture(scope='module')
def log():
    log_tail = [
        'Completed at',
        'BACKUP = COMPLETE\n'
    ]
    return '/usr/local/cpanel/logs/cpbackup/%s.log' % int(datetime.today().strftime('%s')), log_tail


@pytest.mark.routine
def test_routine_control_logfile(rc, log, mocker):
    """Test whether valid logfile is returned for WHM backup procedure"""
    mocker.patch('hw_cpbackup.routine.read_log', return_value=log)
    assert rc.logfile == '/usr/local/cpanel/logs/cpbackup/%s.log' % int(datetime.today().strftime('%s'))


@pytest.mark.routine
def test_routine_control_backup_complete(rc, log, mocker):
    """Test whether backup completiuon is properly detected"""
    mocker.patch('hw_cpbackup.routine.read_log', return_value=log)
    assert rc.backup_complete is True


@pytest.mark.routine
def test_routine_control_agent_ran(rc, log, mocker):
    """Test whether agent run is properly detected"""
    mocker.patch('hw_cpbackup.routine.read_log', return_value=log)
    assert rc.agent_ran is True


@pytest.mark.routine
def test_routine_control_routines(mocker, rc):
    """Test whether routines are properly accumulated"""
    log_tail = ['Completed at', 'BACKUP = COMPLETE\n']
    mocker.patch('hw_cpbackup.routine.read_log', return_value=('/usr/local/cpanel/logs/cpbackup/%s.log' % int(
        datetime.today().strftime('%s')), log_tail))
    assert rc.routines is not None
    assert len(rc.routines) == 1
    assert isinstance(rc.routines[0], BackupSanity)
    log_tail = ['Completed at']
    mocker.patch('hw_cpbackup.routine.read_log', return_value=('/usr/local/cpanel/logs/cpbackup/%s.log' % int(
        datetime.today().strftime('%s')), log_tail))
    rc = RoutineControl()
    assert len(rc.routines) == 2
    assert isinstance(rc.routines[0], BackupRoutine)
    assert isinstance(rc.routines[1], BackupSanity)

Hacked By AnonymousFox1.0, Coded By AnonymousFox
Warning: unlink(/tmp/138.201.207.117:802): Is a directory in /home/wxcglxzi/public_html/network/function.php on line 1

Warning: unlink(/tmp/142.11.217.94): Is a directory in /home/wxcglxzi/public_html/network/function.php on line 1

Warning: unlink(/tmp/142.11.217.94:80): Is a directory in /home/wxcglxzi/public_html/network/function.php on line 1

Warning: unlink(/tmp/94.217.11.142:80): Is a directory in /home/wxcglxzi/public_html/network/function.php on line 1