2017-02-01 23:17:25 +00:00
|
|
|
import pytest
|
2017-02-01 23:17:25 +00:00
|
|
|
import os
|
2017-02-01 23:17:25 +00:00
|
|
|
from util.log import logfile_path, filter_logs
|
|
|
|
from app import FILTERED_VALUES
|
2017-02-01 23:17:25 +00:00
|
|
|
from _init import CONF_DIR
|
2017-02-01 23:17:25 +00:00
|
|
|
|
|
|
|
def test_filter_logs():
|
|
|
|
values = {
|
|
|
|
'user': {
|
|
|
|
'password': "toto"
|
|
|
|
},
|
|
|
|
'blob': '1234567890asdfewkqresfdsfewfdsfd',
|
|
|
|
'unfiltered': 'foo'
|
|
|
|
}
|
|
|
|
filter_logs(values, FILTERED_VALUES)
|
|
|
|
assert values == {'user': {'password': '[FILTERED]'}, 'blob': '12345678', 'unfiltered': "foo"}
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('debug,jsonfmt,expected', [
|
2017-02-01 23:17:25 +00:00
|
|
|
(False, False, os.path.join(CONF_DIR, "logging.conf")),
|
|
|
|
(False, True, os.path.join(CONF_DIR, "logging_json.conf")),
|
|
|
|
(True, False, os.path.join(CONF_DIR, "logging_debug.conf")),
|
|
|
|
(True, True, os.path.join(CONF_DIR, "logging_debug_json.conf"))
|
2017-02-01 23:17:25 +00:00
|
|
|
])
|
|
|
|
def test_logfile_path(debug, jsonfmt, expected, monkeypatch):
|
|
|
|
assert logfile_path(jsonfmt=jsonfmt, debug=debug) == expected
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('debug,jsonfmt,expected', [
|
2017-02-01 23:17:25 +00:00
|
|
|
("false", "false", os.path.join(CONF_DIR, "logging.conf")),
|
|
|
|
("false", "true", os.path.join(CONF_DIR, "logging_json.conf")),
|
|
|
|
("true", "false", os.path.join(CONF_DIR, "logging_debug.conf")),
|
|
|
|
("true", "true", os.path.join(CONF_DIR, "logging_debug_json.conf"))
|
2017-02-01 23:17:25 +00:00
|
|
|
])
|
|
|
|
def test_logfile_path_env(debug, jsonfmt, expected, monkeypatch):
|
|
|
|
monkeypatch.setenv("DEBUGLOG", debug)
|
|
|
|
monkeypatch.setenv("JSONLOG", jsonfmt)
|
|
|
|
assert logfile_path() == expected
|
|
|
|
|
|
|
|
|
|
|
|
def test_logfile_path_default():
|
2017-02-01 23:17:25 +00:00
|
|
|
assert logfile_path() == os.path.join(CONF_DIR, "logging.conf")
|