From 5f8145e3d1ead46def801b608b51cf953456e3d7 Mon Sep 17 00:00:00 2001 From: Shreya Date: Tue, 11 May 2021 19:06:38 +0530 Subject: [PATCH] Add tests for console logging (test_island_logger.py) --- .../cc/server_utils/test_island_logger.py | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py b/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py index 9bcdf71f1..241d7b584 100644 --- a/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py +++ b/monkey/tests/monkey_island/cc/server_utils/test_island_logger.py @@ -36,3 +36,31 @@ def test_setup_logging_log_level_info(tmpdir): with open(LOG_FILE, "r") as f: line = f.readline() assert TEST_STRING not in line + + +def test_setup_logging_console_log_level_debug(capsys, tmpdir): + DATA_DIR = tmpdir + LOG_LEVEL = "DEBUG" + TEST_STRING = "Hello, Monkey! (Log level: debug)" + + setup_logging(DATA_DIR, LOG_LEVEL) + + logger = logging.getLogger("TestLogger") + logger.debug(TEST_STRING) + + captured = capsys.readouterr() + assert TEST_STRING in captured.out + + +def test_setup_logging_console_log_level_info(capsys, tmpdir): + DATA_DIR = tmpdir + LOG_LEVEL = "INFO" + TEST_STRING = "Hello, Monkey! (Log level: info)" + + setup_logging(DATA_DIR, LOG_LEVEL) + + logger = logging.getLogger("TestLogger") + logger.debug(TEST_STRING) + + captured = capsys.readouterr() + assert TEST_STRING not in captured.out