mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Set loglevel for unit test
This commit is contained in:
parent
9cc0635ed3
commit
729cf37b79
3 changed files with 27 additions and 17 deletions
|
@ -1,3 +1,5 @@
|
|||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.modules.win_file as win_file
|
||||
|
@ -158,11 +160,14 @@ def test_set_value_log_messages(caplog):
|
|||
mock_set_file_data = MagicMock(return_value=True)
|
||||
mock_set_pol_data = MagicMock(return_value=False)
|
||||
mock_context = {"lgpo.adv_audit_data": {"test_option": "test_value"}}
|
||||
with patch.object(
|
||||
win_lgpo, "_set_advaudit_file_data", mock_set_file_data
|
||||
), patch.object(win_lgpo, "_set_advaudit_pol_data", mock_set_pol_data), patch.dict(
|
||||
win_lgpo.__context__, mock_context
|
||||
):
|
||||
win_lgpo._set_advaudit_value("test_option", None)
|
||||
assert "Failed to apply audit setting:" in caplog.text
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
with patch.object(
|
||||
win_lgpo, "_set_advaudit_file_data", mock_set_file_data
|
||||
), patch.object(
|
||||
win_lgpo, "_set_advaudit_pol_data", mock_set_pol_data
|
||||
), patch.dict(
|
||||
win_lgpo.__context__, mock_context
|
||||
):
|
||||
win_lgpo._set_advaudit_value("test_option", None)
|
||||
assert "Failed to apply audit setting:" in caplog.text
|
||||
assert "LGPO: Removing Advanced Audit data:" in caplog.text
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.modules.cmdmod as cmd
|
||||
|
@ -69,15 +71,17 @@ def test_write_secedit_data_import_fail(caplog):
|
|||
patch_cmd_retcode = patch.dict(
|
||||
win_lgpo.__salt__, {"cmd.retcode": MagicMock(return_value=1)}
|
||||
)
|
||||
with patch_cmd_retcode:
|
||||
assert win_lgpo._write_secedit_data("spongebob") is False
|
||||
assert "Secedit failed to import template data" in caplog.text
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
with patch_cmd_retcode:
|
||||
assert win_lgpo._write_secedit_data("spongebob") is False
|
||||
assert "Secedit failed to import template data" in caplog.text
|
||||
|
||||
|
||||
def test_write_secedit_data_configure_fail(caplog):
|
||||
patch_cmd_retcode = patch.dict(
|
||||
win_lgpo.__salt__, {"cmd.retcode": MagicMock(side_effect=[0, 1])}
|
||||
)
|
||||
with patch_cmd_retcode:
|
||||
assert win_lgpo._write_secedit_data("spongebob") is False
|
||||
assert "Secedit failed to apply security database" in caplog.text
|
||||
with caplog.at_level(logging.DEBUG):
|
||||
with patch_cmd_retcode:
|
||||
assert win_lgpo._write_secedit_data("spongebob") is False
|
||||
assert "Secedit failed to apply security database" in caplog.text
|
||||
|
|
|
@ -42,10 +42,11 @@ def test_format_log_list(caplog):
|
|||
"""
|
||||
Test running format_log when ret is not a dictionary
|
||||
"""
|
||||
ret = ["test1", "test2"]
|
||||
salt.state.format_log(ret)
|
||||
assert "INFO" in caplog.text
|
||||
assert f"{ret}" in caplog.text
|
||||
with caplog.at_level(logging.INFO):
|
||||
ret = ["test1", "test2"]
|
||||
salt.state.format_log(ret)
|
||||
assert "INFO" in caplog.text
|
||||
assert f"{ret}" in caplog.text
|
||||
|
||||
|
||||
def test_render_error_on_invalid_requisite(minion_opts):
|
||||
|
|
Loading…
Add table
Reference in a new issue