Пример #1
0
 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
Пример #2
0
 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
Пример #3
0
 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"]
Пример #4
0
 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
Пример #5
0
 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"
Пример #6
0
 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
Пример #7
0
 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