def test_decode_db_to_file(mock_db_helper, mock_cryptography, tmp_path): mocked_cryptography = mock.MagicMock(Cryptography) mocked_cryptography.decode.return_value = b"test" mocked_db_helper = mock.MagicMock(DBHelper) mocked_db_helper.select_from_db.return_value = b"test" mock_cryptography.return_value = mocked_cryptography mock_db_helper.return_value = mocked_db_helper file_path = tmp_path / "test.txt" code_helper = CodeHelper() code_helper.decode_db_to_file(1, file_path) mocked_cryptography.decode.assert_called_with(b"test") mocked_db_helper.select_from_db.assert_called_with(1) assert file_path.read_text() == "test"
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)