def owlc_full(monkeypatch, debug):
    mock_hostname(monkeypatch)
    options = Mock_Options(syslog_port=1337,
                           syslog_server="localhost",
                           protocol="udp",
                           log_file="/dev/null",
                           stdout=None,
                           debug=debug,
                           dirs=None,
                           perms_mask=None)
    return owlc.OWWatcherLoggerConfigurer(options)
def owlc_tcp(monkeypatch):
    mock_hostname(monkeypatch)
    mock_socket_connect(monkeypatch)
    options = Mock_Options(syslog_port=1337,
                           syslog_server="localhost",
                           protocol="tcp",
                           log_file="/dev/null",
                           stdout=None,
                           debug=False,
                           dirs=None,
                           perms_mask=None)

    return owlc.OWWatcherLoggerConfigurer(options)
def test_owwatcher_file_only(monkeypatch):
    options = Mock_Options(syslog_port=None,
                           syslog_server=None,
                           protocol="tcp",
                           log_file="/dev/null",
                           stdout=False,
                           debug=False,
                           dirs=None,
                           perms_mask=None)

    owlc_null_syslog = owlc.OWWatcherLoggerConfigurer(options)
    l = owlc_null_syslog.get_owwatcher_logger()

    assert len(l.handlers) == 1
    assert isinstance(l.handlers[0], logging.FileHandler)
def test_syslog_logger_invalid_protocol(monkeypatch):
    mock_hostname(monkeypatch)
    options = Mock_Options(syslog_port=1337,
                           syslog_server="localhost",
                           protocol="icmp",
                           log_file="/dev/null",
                           stdout=None,
                           debug=False,
                           dirs=None,
                           perms_mask=None)
    with pytest.raises(ValueError) as ve:
        owlc.OWWatcherLoggerConfigurer(options)

    assert "Unexpected protocol 'icmp'. Valid protocols are 'tcp' or 'udp'." in str(
        ve)
def test_owwatcher_stdout_only_by_default(monkeypatch):
    options = Mock_Options(
        syslog_port=None,
        syslog_server=None,
        protocol="tcp",
        log_file=None,
        stdout=False,
        debug=False,
        dirs=None,
        perms_mask=None,
    )

    owlc_null_syslog = owlc.OWWatcherLoggerConfigurer(options)
    logger = owlc_null_syslog.get_owwatcher_logger()

    assert len(logger.handlers) == 1
    assert isinstance(logger.handlers[0], logging.StreamHandler)