示例#1
0
    def _try_prepare(self, env_prep: EnvironmentPreparation, ui: UI) -> bool:
        try:
            ui.info("Copying files...")
            env_prep.prepare()
            ui.success("Done")
        except (FileExistsError, FileNotFoundError) as err:
            self._do_rollback(env_prep, err, ui)
            return False

        return True
示例#2
0
def test__given_files_to_copy__when_preparing__should_copy_files():
    source_fs = new_mock_filesystem(["file.txt", "funny.gif"])
    target_fs = new_mock_filesystem(["evenfunnier.gif"])

    sut = EnvironmentPreparation(source_fs, target_fs)

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

    sut.prepare()

    assert target_fs.exists("filecopy.txt")
    assert target_fs.exists("evenfunnier.gif")
示例#3
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()
示例#4
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
示例#5
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
示例#6
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")])