def test_select_rate_plans_ok(service: UpdateReservationCache,
                              context: Context, house, reservation, rate_plan,
                              user):
    service._prices_repo = Mock(select_plans=Mock(return_value=[rate_plan]))
    context.house = house
    context.reservations = [reservation]
    context.user = user

    result = service.select_rate_plans(context)
    assert is_successful(result), result.failure()
    assert result.unwrap().rate_plans == {rate_plan.id: rate_plan}
def test_select_rate_plans_error(service: UpdateReservationCache,
                                 context: Context, house, reservation, user):
    service._prices_repo = Mock(select_plans=Mock(
        side_effect=RuntimeError('ERR')))
    context.house = house
    context.reservations = [reservation]
    context.user = user

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