Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_result_show_backup_error(self, capsys):
# mock the backup ext info
msg = 'test error message'
ext_info = mock_backup_ext_info(status=BackupInfo.FAILED, error=msg)
writer = output.ConsoleOutputWriter()
# test minimal
writer.result_show_backup(ext_info)
writer.close()
(out, err) = capsys.readouterr()
assert ext_info['server_name'] in out
assert ext_info['backup_id'] in out
assert ext_info['status'] in out
assert str(ext_info['end_time']) not in out
assert msg in out
assert err == ''
def test_colored_warning(self, capsys, monkeypatch):
monkeypatch.setattr(output, 'ansi_colors_enabled', True)
writer = output.ConsoleOutputWriter()
msg = 'test message'
writer.warning(msg)
(out, err) = capsys.readouterr()
assert out == ''
assert err == YELLOW + 'WARNING: ' + msg + RESET + '\n'
msg = 'test arg %s'
args = ('1st',)
writer.warning(msg, *args)
(out, err) = capsys.readouterr()
assert out == ''
assert err == YELLOW + 'WARNING: ' + msg % args + RESET + '\n'
msg = 'test args %d %s'
args = (1, 'two')
def test_result_check_failed(self, capsys):
writer = output.ConsoleOutputWriter()
output.error_occurred = False
server = 'test'
check = 'test check'
writer.result_check(server, check, False)
(out, err) = capsys.readouterr()
assert out == '\t%s: FAILED\n' % check
assert err == ''
assert output.error_occurred
# Test an inactive server
# Shows error, but does not change error_occurred
output.error_occurred = False
writer.init_check(server, False, False)
(out, err) = capsys.readouterr()
def test_result_check_failed_hint_color(self, capsys, monkeypatch):
monkeypatch.setattr(output, 'ansi_colors_enabled', True)
writer = output.ConsoleOutputWriter()
output.error_occurred = False
server = 'test'
check = 'test check'
hint = 'do something'
writer.result_check(server, check, False, hint)
(out, err) = capsys.readouterr()
assert out == '\t%s: %sFAILED%s (%s)\n' % (check, RED, RESET, hint)
assert err == ''
assert output.error_occurred
def test_debug(self, capsys):
writer = output.ConsoleOutputWriter(debug=True)
msg = 'test message'
writer.debug(msg)
(out, err) = capsys.readouterr()
assert out == ''
assert err == 'DEBUG: ' + msg + '\n'
msg = 'test arg %s'
args = ('1st',)
writer.debug(msg, *args)
(out, err) = capsys.readouterr()
assert out == ''
assert err == 'DEBUG: ' + msg % args + '\n'
msg = 'test args %d %s'
args = (1, 'two')
def test_debug_disabled(self, capsys):
writer = output.ConsoleOutputWriter(debug=False)
msg = 'test message'
writer.debug(msg)
(out, err) = capsys.readouterr()
assert out == ''
assert err == ''
msg = 'test arg %s'
args = ('1st',)
writer.debug(msg, *args)
(out, err) = capsys.readouterr()
assert out == ''
assert err == ''
msg = 'test args %d %s'
args = (1, 'two')
def test_readact_passwords_in_json(self, capsys):
writer = output.ConsoleOutputWriter()
msg = '{"conninfo": "dbname=t password=SHAME_ON_ME", "a": "b"}'
writer.info(msg)
(out, err) = capsys.readouterr()
json_out = '{"conninfo": "dbname=t password=*REDACTED*", "a": "b"}\n'
assert out == json_out
assert err == ''
def test_info_quiet(self, capsys):
writer = output.ConsoleOutputWriter(quiet=True)
msg = 'test message'
writer.info(msg)
(out, err) = capsys.readouterr()
assert out == ''
assert err == ''
msg = 'test arg %s'
args = ('1st',)
writer.info(msg, *args)
(out, err) = capsys.readouterr()
assert out == ''
assert err == ''
msg = 'test args %d %s'
args = (1, 'two')
def test_error(self, capsys):
writer = output.ConsoleOutputWriter()
msg = 'test message'
writer.error(msg)
(out, err) = capsys.readouterr()
assert out == ''
assert err == 'ERROR: ' + msg + '\n'
msg = 'test arg %s'
args = ('1st',)
writer.error(msg, *args)
(out, err) = capsys.readouterr()
assert out == ''
assert err == 'ERROR: ' + msg % args + '\n'
msg = 'test args %d %s'
args = (1, 'two')
:param str server_name: the server we are displaying
"""
self.info("Server %s:" % server_name)
def result_show_server(self, server_name, server_info):
"""
Output the results of the show-server command
:param str server_name: the server we are displaying
:param dict server_info: a dictionary containing the info to display
"""
for status, message in sorted(server_info.items()):
self.info("\t%s: %s", status, message)
class JsonOutputWriter(ConsoleOutputWriter):
def __init__(self, *args, **kwargs):
"""
Output writer that writes on standard output using JSON.
When closed, it dumps all the collected results as a JSON object.
"""
super(JsonOutputWriter, self).__init__(*args, **kwargs)
#: Store JSON data
self.json_output = {}
def _mangle_key(self, value):
"""
Mangle a generic description to be used as dict key