def test_logger_replace_strs(mocker): mocker.patch.object(demisto, 'params', return_value={ 'apikey': 'my_apikey', }) ilog = IntegrationLogger() ilog.add_replace_strs('special_str', '') # also check that empty string is not added by mistake ilog('my_apikey is special_str and b64: ' + b64_encode('my_apikey')) assert ('' not in ilog.replace_strs) assert ilog.messages[0] == '<XX_REPLACED> is <XX_REPLACED> and b64: <XX_REPLACED>'
def test_override_print(mocker): mocker.patch.object(demisto, 'info') int_logger = IntegrationLogger() int_logger.set_buffering(False) int_logger.print_override("test", "this") assert demisto.info.call_count == 1 assert demisto.info.call_args[0][0] == "test this" demisto.info.reset_mock() int_logger.print_override("test", "this", file=sys.stderr) assert demisto.info.call_count == 1 assert demisto.info.call_args[0][0] == "test this" buf = StringIO() # test writing to custom file (not stdout/stderr) int_logger.print_override("test", "this", file=buf) assert buf.getvalue() == 'test this\n'
def test_logger_write(mocker): mocker.patch.object(demisto, 'params', return_value={ 'credentials': {'password': '******'}, }) mocker.patch.object(demisto, 'info') ilog = IntegrationLogger() ilog.write("This is a test with my_password") ilog.print_log() # assert that the print doesn't contain my_password # call_args is tuple (args list, kwargs). we only need the args args = demisto.info.call_args[0] assert 'This is a test' in args[0] assert 'my_password' not in args[0] assert '<XX_REPLACED>' in args[0]