Esempio n. 1
0
def test_code_text_to_file(mock_db_helper, mock_cryptography, tmp_path):
    mocked_cryptography = mock.MagicMock(Cryptography)
    mocked_cryptography.code.return_value = b"test"
    mock_cryptography.return_value = mocked_cryptography
    file_path = tmp_path / "test"

    code_helper = CodeHelper()
    code_helper.code_text_to_file("test", file_path)

    assert file_path.read_text() == "test"
    mocked_cryptography.code.assert_called_with(b"test")
Esempio n. 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)