def test_select_cancellation_policy_for_plan_without_policy(
        service: CreateReservation, context: Context, house, rate_plan):
    context.rate_plan = attr.evolve(rate_plan, policy_id=0)
    context.house = house

    result = service.select_cancellation_policy(context)
    assert is_successful(result)
    assert result.unwrap().rate_plan.policy is None
def test_select_cancellation_policy_fail(service: CreateReservation,
                                         context: Context, house, rate_plan):
    service._policies_repo = Mock(get=Mock(return_value=Nothing))
    context.house = house
    context.rate_plan = rate_plan

    result = service.select_cancellation_policy(context)
    assert is_successful(result)
    assert result.unwrap().rate_plan.policy is None
def test_select_cancellation_policy_error(service: CreateReservation,
                                          context: Context, house, rate_plan):
    service._policies_repo = Mock(get=Mock(side_effect=RuntimeError('ERR')))
    context.house = house
    context.rate_plan = rate_plan

    result = service.select_cancellation_policy(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == 'ERR'