Пример #1
0
def test_code_file_to_db(mock_db_helper, mock_cryptography, tmp_path):
    mocked_cryptography = mock.MagicMock(Cryptography)
    mocked_cryptography.code.return_value = b"test"
    mocked_db_helper = mock.MagicMock(DBHelper)
    mocked_db_helper.insert_into_db.return_value = 1
    mock_cryptography.return_value = mocked_cryptography
    mock_db_helper.return_value = mocked_db_helper
    file_path = tmp_path / "test.txt"
    file_path.write_text("test")
    assert file_path.read_text() == "test"

    code_helper = CodeHelper()
    id_in_db = code_helper.code_file_to_db(file_path)

    mocked_cryptography.code.assert_called_with(b"test")
    mocked_db_helper.insert_into_db.assert_called_with(b"test")
    assert id_in_db == 1
Пример #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)