Beispiel #1
0
def test_evaluate_ruling_cancel_fail_state_change(
        workspace: Workspace,
        monkeypatch: _pytest.monkeypatch.MonkeyPatch) -> None:
    patch(monkeypatch, workspace, 'handle_success')

    mock_error: tft.artemis.tasks.DoerReturnType = Error(
        tft.artemis.Failure('mock error'))

    def mock_update_guest_state(*args: Any, **kwargs: Any) -> None:
        workspace.result = mock_error

    patch(monkeypatch, workspace,
          'update_guest_state').side_effect = mock_update_guest_state

    workspace.ruling = tft.artemis.routing_policies.PolicyRuling(
        cancel=True,
        allowed_pools=[MagicMock(name='pool1'),
                       MagicMock(name='pool2')])

    assert workspace.evaluate_ruling() is workspace

    assert workspace.result is mock_error
    assert workspace.new_pool is None

    cast(MagicMock, workspace.update_guest_state).assert_called_once_with(
        tft.artemis.guest.GuestState.ERROR,
        current_state=tft.artemis.guest.GuestState.ROUTING)

    cast(MagicMock,
         workspace.handle_success).assert_called_once_with('routing-cancelled')
Beispiel #2
0
def test_evaluate_ruling(workspace: Workspace) -> None:
    workspace.ruling = tft.artemis.routing_policies.PolicyRuling(
        allowed_pools=[MagicMock(
            name='pool1'), MagicMock(name='pool2')])

    assert workspace.evaluate_ruling() is workspace

    assert workspace.result is None
    assert workspace.new_pool is workspace.ruling.allowed_pools[0]
Beispiel #3
0
def test_evaluate_ruling_empty(
        workspace: Workspace,
        monkeypatch: _pytest.monkeypatch.MonkeyPatch) -> None:
    patch(monkeypatch, workspace, 'handle_success')
    patch(monkeypatch, workspace, 'update_guest_state')

    workspace.ruling = tft.artemis.routing_policies.PolicyRuling()

    assert workspace.evaluate_ruling() is workspace

    assert workspace.result is tft.artemis.tasks.RESCHEDULE
    assert workspace.new_pool is None

    cast(MagicMock, workspace.handle_success).assert_not_called()
    cast(MagicMock, workspace.update_guest_state).assert_not_called()
Beispiel #4
0
def test_evaluate_ruling_cancel(
        workspace: Workspace,
        monkeypatch: _pytest.monkeypatch.MonkeyPatch) -> None:
    patch(monkeypatch, workspace,
          'handle_success').return_value = tft.artemis.tasks.SUCCESS
    patch(monkeypatch, workspace, 'update_guest_state')

    workspace.ruling = tft.artemis.routing_policies.PolicyRuling(
        cancel=True,
        allowed_pools=[MagicMock(name='pool1'),
                       MagicMock(name='pool2')])

    assert workspace.evaluate_ruling() is workspace

    assert workspace.result is tft.artemis.tasks.SUCCESS
    assert workspace.new_pool is None

    cast(MagicMock, workspace.update_guest_state).assert_called_once_with(
        tft.artemis.guest.GuestState.ERROR,
        current_state=tft.artemis.guest.GuestState.ROUTING)

    cast(MagicMock,
         workspace.handle_success).assert_any_call('routing-cancelled')
    cast(MagicMock, workspace.handle_success).assert_any_call('finished-task')