

def test_all_actions_must_be_rolled_back_on_failure(self):
    before_rollback = MagicMock()
    command_rollback = MagicMock()
    after_rollback = MagicMock()

    class RollbackTestCommand(NamedCommand):

        def __init__(self, lizy):
            super(RollbackTestCommand, self).__init__(lizy, 'rollback desc', command_rollback)

        def _process_command(self, lizy, args):
            return None

    class B(BeforeTask):

        def __init__(self):
            super(B, self).__init__(before_rollback)
            self.enable_rollback(before_rollback)

        def execute(self, lizy, args):
            pass

    class A(AfterTask):

        def __init__(self):
            super(A, self).__init__(after_rollback)
            self._needs_rollback = True

        def execute(self, lizy, args):
            raise PyleaseError()
    subparser_mock = (lambda : 0)
    subparser_mock.add_parser = MagicMock()
    args_mock = (lambda : 0)
    args_mock.verbose = False
    info_container = InfoContainer()
    info_container.is_empty = False
    lizy = Pylease(None, subparser_mock, info_container)
    command = RollbackTestCommand(lizy)
    command.add_before_task(B())
    command.add_after_task(A())
    command(args_mock)
    before_rollback.assert_called_once_with()
    command_rollback.assert_called_once_with()
    after_rollback.assert_called_once_with()

dataset/ETHPy150Open n9code/pylease/tests/test_command.py CommandTest.test_all_actions_must_be_rolled_back_on_failure/original