def test_format_file_results_binary_blob(skeleton_row): blob = b"\xaa\xdb\xe3\xdc\xfd\x19\xdc\x12\xc3\x0f\x07\x03\x89\xe0\xde" row = skeleton_row row["file_contents"] = blob row["is_binary"] = "Y" formatted = configFilesHandler.format_file_results(row) assert formatted["file_contents"] == base64.encodestring(blob).decode( "utf8")
def test_format_file_results_utf8(skeleton_row): utf8_string = "Hello I am an UTF-8 string. Look at me¡¡¡" row = skeleton_row row["file_contents"] = utf8_string.encode("utf8") row["is_binary"] = "N" formatted = configFilesHandler.format_file_results(row) assert formatted["file_contents"] == base64.encodestring( utf8_string.encode("utf8")).decode("utf8")
def test_format_file_results_latin1(skeleton_row): latin1_string = "Hello I am a Latin-1 string. Don't look at me¡¡¡" row = skeleton_row row["file_contents"] = latin1_string.encode("latin-1") row["is_binary"] = "N" formatted = configFilesHandler.format_file_results(row) assert formatted["file_contents"] == base64.encodestring( # NOTE: currently the original encoding is lost before encoding in base64 # this test keeps the behaviour as is latin1_string.encode("utf8")).decode("utf8")
def _get_files(server_id, action_id): h = rhnSQL.prepare(_query_get_files) h.execute(action_id=action_id, server_id=server_id) server = rhnServer.search(server_id) server = var_interp_prep(server) files = [] while 1: row = h.fetchone_dict() if not row: break files.append(format_file_results(row, server=server)) result = {"files": files} return result
def _get_files(server_id, action_id): h = rhnSQL.prepare(_query_get_files) h.execute(action_id=action_id, server_id=server_id) server = rhnServer.search(server_id) server = var_interp_prep(server) files = [] while 1: row = h.fetchone_dict() if not row: break files.append(format_file_results(row, server=server)) result = { 'files': files, } return result