示例#1
0
def test_decode_file_to_file(mock_db_helper, mock_cryptography, tmp_path):
    mocked_cryptography = mock.MagicMock(Cryptography)
    mocked_cryptography.decode.return_value = b"test"
    mock_cryptography.return_value = mocked_cryptography
    file_path_in = tmp_path / "test"
    file_path_in.write_text("test")
    file_path_out = tmp_path / "test.txt"
    assert file_path_in.read_text() == "test"

    code_helper = CodeHelper()
    code_helper.decode_file_to_file(file_path_in, file_path_out)

    assert file_path_out.read_text() == "test"
    mocked_cryptography.decode.assert_called_with(b"test")
示例#2
0
def main(text: str, path_file_input: str) -> None:

    code_helper = CodeHelper()
    file_input_ext = os.path.splitext(path_file_input)[1]
    output_dir = "output"
    os.makedirs(output_dir, exist_ok=True)

    path_file_code = f"{output_dir}/text_code_file"
    code_helper.code_text_to_file(text, path_file_code)

    text_decode = code_helper.decode_file_to_text(path_file_code)
    print(f"wyjściowy tekst: {text_decode}")

    path_file_code = f"{output_dir}/file_code_file"
    code_helper.code_file_to_file(path_file_input, path_file_code)

    path_file_output = f"{output_dir}/file_decode_file{file_input_ext}"
    code_helper.decode_file_to_file(path_file_code, path_file_output)

    file_id = code_helper.code_file_to_db(path_file_input)

    path_file_output = f"{output_dir}//db_decode_file{file_input_ext}"
    code_helper.decode_db_to_file(file_id, path_file_output)