Exemplo n.º 1
0
def test_configure_logging(homedir, mocker):
    """
    Ensure logging directory is created and logging is configured in the
    expected (rotating logs) manner.
    """
    mock_log_conf = mocker.patch("securedrop_client.app.TimedRotatingFileHandler")
    mock_log_conf_sys = mocker.patch("securedrop_client.app.SysLogHandler")
    mock_logging = mocker.patch("securedrop_client.app.logging")
    mock_log_file = os.path.join(homedir, "logs", "client.log")
    configure_logging(homedir)
    mock_log_conf.assert_called_once_with(
        mock_log_file, when="midnight", backupCount=5, delay=0, encoding=ENCODING
    )
    mock_log_conf_sys.assert_called_once_with(address="/dev/log")
    mock_logging.getLogger.assert_called_once_with()
    assert sys.excepthook == excepthook
Exemplo n.º 2
0
def test_configure_logging(homedir, mocker):
    """
    Ensure logging directory is created and logging is configured in the
    expected (rotating logs) manner.
    """
    mock_log_conf = mocker.patch(
        'securedrop_client.app.TimedRotatingFileHandler')
    mocker.patch('securedrop_client.app.os.path.exists', return_value=False)
    mock_logging = mocker.patch('securedrop_client.app.logging')
    mock_log_file = os.path.join(homedir, 'logs', 'client.log')
    configure_logging(homedir)
    mock_log_conf.assert_called_once_with(mock_log_file,
                                          when='midnight',
                                          backupCount=5,
                                          delay=0,
                                          encoding=ENCODING)
    mock_logging.getLogger.assert_called_once_with()
    assert sys.excepthook == excepthook
Exemplo n.º 3
0
def test_configure_logging(safe_tmpdir):
    """
    Ensure logging directory is created and logging is configured in the
    expected (rotating logs) manner.
    """
    with mock.patch('securedrop_client.app.TimedRotatingFileHandler') as \
            log_conf, \
            mock.patch('securedrop_client.app.os.path.exists',
                       return_value=False), \
            mock.patch('securedrop_client.app.logging') as logging:
        log_file = safe_tmpdir.mkdir('logs').join('client.log')
        configure_logging(str(safe_tmpdir))
        log_conf.assert_called_once_with(log_file,
                                         when='midnight',
                                         backupCount=5,
                                         delay=0,
                                         encoding=ENCODING)
        logging.getLogger.assert_called_once_with()
        assert sys.excepthook == excepthook
Exemplo n.º 4
0
def test_configure_logging():
    """
    Ensure logging directory is created and logging is configured in the
    expected (rotating logs) manner.
    """
    with mock.patch('securedrop_client.app.TimedRotatingFileHandler') as \
            log_conf, \
            mock.patch('securedrop_client.app.os.path.exists',
                       return_value=False),\
            mock.patch('securedrop_client.app.logging') as logging, \
            mock.patch('securedrop_client.app.os.makedirs',
                       return_value=None) as mkdir:
        configure_logging()
        mkdir.assert_called_once_with(LOG_DIR)
        log_conf.assert_called_once_with(LOG_FILE,
                                         when='midnight',
                                         backupCount=5,
                                         delay=0,
                                         encoding=ENCODING)
        logging.getLogger.assert_called_once_with()
        assert sys.excepthook == excepthook