def test__checks_state_items_for_rollback_failure_missing(): action = StatefullAction() action.rollback_action(["input"], lambda state: 10) action._state = {} with pytest.raises(ActionException): with action._checks_state_items_for_rollback(): pass
def test_get_prepared_action_rollback(monkeypatch): monkeypatch.setattr(InfoStreamer, "send_info", MagicMock()) monkeypatch.setattr(StatefullAction, "_check_kwargs_for_action", MagicMock()) monkeypatch.setattr(StatefullAction, "add_context_manager", MagicMock()) action = StatefullAction(["input"], lambda state: 10) action.rollback_action(fct=lambda state: state["input"]) prepared = action.get_prepared_action(input=20) assert prepared.undo() == 20
def test__checks_state_items_for_rollback_failure_exception(): action = StatefullAction() action.rollback_action(["input"], lambda state: 10) action._state = {} try: with action._checks_state_items_for_rollback(): raise Exception() except Exception: pass assert action._state["action_failed"]
def test__checks_state_items_for_rollback(): action = StatefullAction() action.rollback_action(["input"], lambda state: 10) action._state = {} with action._checks_state_items_for_rollback(): action._state["input"] = 10
def test_rollback_action_with_name(monkeypatch): monkeypatch.setattr(StatefullAction, "_check_fct", MagicMock()) action = StatefullAction(name="better_name") decorator = action.rollback_action(name="better_rollback_name") decorator(lambda state: 10) assert action.rollback_name == "better_rollback_name"
def test_rollback_action_with_fct(monkeypatch): monkeypatch.setattr(StatefullAction, "_check_fct", MagicMock()) action = StatefullAction() action.rollback_action(fct=lambda state: 10) assert action._rollback_fct({}) == 10
def test_rollback_action(monkeypatch): monkeypatch.setattr(StatefullAction, "_check_fct", MagicMock()) action = StatefullAction() decorator = action.rollback_action() decorator(lambda state: 10) assert action._rollback_fct({}) == 10