Beispiel #1
0
def test__given_copied_file_not_on_target_fs__when_rolling_back__should_remove_remaining_copied_files_from_target_fs(
):
    source_fs_spy = new_mock_filesystem(["file.txt", "funny.gif"])
    target_fs = new_mock_filesystem()

    sut = EnvironmentPreparation(source_fs_spy, target_fs)
    sut.files_to_copy([
        CopyInstruction("file.txt", "filecopy.txt"),
        CopyInstruction("funny.gif", "evenfunnier.gif")
    ])

    sut.prepare()
    target_fs.delete("filecopy.txt")

    sut.rollback()

    assert target_fs.exists("evenfunnier.gif") is False
Beispiel #2
0
def test__given_rollback_done__when_rolling_back_again__should_not_do_anything(
):
    source_fs_spy = new_mock_filesystem(["file.txt", "funny.gif"])
    target_fs = MagicMock(wraps=new_mock_filesystem())

    sut = EnvironmentPreparation(source_fs_spy, target_fs)
    sut.files_to_copy([
        CopyInstruction("file.txt", "filecopy.txt"),
        CopyInstruction("funny.gif", "evenfunnier.gif")
    ])
    sut.prepare()
    sut.rollback()
    target_fs.reset_mock()

    sut.rollback()

    target_fs.delete.assert_not_called()
Beispiel #3
0
def test__given_files_to_copy_with_non_existing_file__when_preparing_then_rollback__should_remove_copied_files_from_target_fs(
):
    source_fs_spy = new_mock_filesystem(["funny.gif"])
    target_fs = new_mock_filesystem()

    sut = EnvironmentPreparation(source_fs_spy, target_fs)

    sut.files_to_copy([
        CopyInstruction("file.txt", "filecopy.txt"),
        CopyInstruction("funny.gif", "evenfunnier.gif")
    ])

    with pytest.raises(FileNotFoundError):
        sut.prepare()

    sut.rollback()

    assert target_fs.exists("filecopy.txt") is False
Beispiel #4
0
def test__given_rollback_done_with_file_not_found__when_rolling_back_again__should_try_to_delete_remaining_files(
):
    source_fs_spy = new_mock_filesystem(["file.txt", "funny.gif"])
    target_fs_spy = MagicMock(wraps=new_mock_filesystem())

    sut = EnvironmentPreparation(source_fs_spy, target_fs_spy)
    sut.files_to_copy([
        CopyInstruction("file.txt", "filecopy.txt"),
        CopyInstruction("funny.gif", "evenfunnier.gif")
    ])

    sut.prepare()
    target_fs_spy.delete("filecopy.txt")
    sut.rollback()

    target_fs_spy.reset_mock()
    sut.rollback()

    target_fs_spy.delete.assert_has_calls([call("filecopy.txt")])
Beispiel #5
0
 def _do_rollback(env_prep: EnvironmentPreparation, err: Exception,
                  ui: UI) -> None:
     ui.error(get_error_message(err))
     ui.info("Performing rollback")
     env_prep.rollback()
     ui.success("Done")