Ejemplo n.º 1
0
def test_select_rate_plan_ok(service: CalculateNewReservation,
                             context: Context, house, rate_plan):
    service._prices_repo = Mock(get_plan=Mock(return_value=Some(rate_plan)))
    context.house = house

    result = service.select_rate_plan(context)
    assert is_successful(result)
    assert result.unwrap().rate_plan == rate_plan
Ejemplo n.º 2
0
def test_select_rate_plan_fail(service: CalculateNewReservation,
                               context: Context, house):
    service._prices_repo = Mock(get_plan=Mock(return_value=Nothing))
    context.house = house

    result = service.select_rate_plan(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_rateplan
Ejemplo n.º 3
0
def test_select_rate_plan_error(service: CalculateNewReservation,
                                context: Context, house):
    service._prices_repo = Mock(get_plan=Mock(side_effect=RuntimeError("ERR")))
    context.house = house

    result = service.select_rate_plan(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == "ERR"
Ejemplo n.º 4
0
def test_select_rates_ok(service: CalculateNewReservation, context: Context,
                         house, room_type, rate_plan, rate):
    service._prices_repo = Mock(select_rates=Mock(return_value=[rate]))
    context.house = house
    context.room_type = room_type
    context.rate_plan = rate_plan

    result = service.select_rates(context)
    assert is_successful(result)
    assert result.unwrap().rates == [rate]
Ejemplo n.º 5
0
def test_success(
    service: CalculateNewReservation,
    context: Context,
    house,
    room_type,
    rate_plan,
    rate,
    user,
    last_min_discount,
    availability_discount,
    los_discount,
):
    rates = [rate, attr.evolve(rate, id=101, occupancy=3)]
    period = [
        context.start_date, context.start_date + datetime.timedelta(days=1)
    ]

    service._houses_repo = Mock(get=Mock(return_value=Some(house)))
    service._roomtypes_repo = Mock(get=Mock(return_value=Some(room_type)))
    service._prices_repo = Mock(
        get_plan=Mock(return_value=Some(rate_plan)),
        select_rates=Mock(return_value=rates),
        select_prices=Mock(return_value={
            period[0]: Decimal(100),
            period[1]: Decimal(110)
        }),
        select_restrictions=Mock(return_value={
            period[0]: Decimal(80),
            period[1]: Decimal(80)
        }),
    )
    service._discounts_repo = Mock(select=Mock(
        return_value={
            DiscountTypes.LAST_MINUTE: [last_min_discount],
            DiscountTypes.AVAILABILITY: [availability_discount],
            DiscountTypes.LOS: [los_discount],
        }))
    service._occupancy_repo = Mock(get=Mock(return_value={
        period[0]: 3,
        period[1]: 1
    }))

    result = service.execute(house.id, room_type.id, rate_plan.id,
                             context.start_date, context.end_date, 2, user)
    assert is_successful(result), result.failure()

    ctx = result.unwrap()
    assert isinstance(ctx, ReservationCalcContext)
    assert ctx.room_type == room_type
    assert ctx.rate_plan == rate_plan
    assert ctx.rates == rates
    assert ctx.rate == rate
    assert ctx.prices == {period[0]: Decimal(80), period[1]: Decimal("93.50")}
Ejemplo n.º 6
0
def test_select_daily_prices_error(service: CalculateNewReservation,
                                   context: Context, house, room_type, rate):
    service._prices_repo = Mock(select_prices=Mock(
        side_effect=RuntimeError("ERR")))
    context.house = house
    context.room_type = room_type
    context.rate = rate

    result = service.select_daily_prices(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == "ERR"
Ejemplo n.º 7
0
def test_select_daily_prices_fail(service: CalculateNewReservation,
                                  context: Context, house, room_type, rate):
    service._prices_repo = Mock(select_prices=Mock(return_value={}))
    context.house = house
    context.room_type = room_type
    context.rate = rate

    result = service.select_daily_prices(context)
    assert is_successful(result)
    assert result.unwrap().prices == {
        datetime.date.today(): None,
        datetime.date.today() + datetime.timedelta(days=1): None,
    }
Ejemplo n.º 8
0
def test_select_daily_prices_ok(service: CalculateNewReservation,
                                context: Context, house, room_type, rate):
    prices = {
        context.start_date: Decimal(100),
        context.start_date + datetime.timedelta(days=1): Decimal(110)
    }
    service._prices_repo = Mock(select_prices=Mock(return_value=prices))
    context.house = house
    context.room_type = room_type
    context.rate = rate

    result = service.select_daily_prices(context)
    assert is_successful(result)
    assert result.unwrap().prices == prices
Ejemplo n.º 9
0
def test_select_price_restrictions_ok(service: CalculateNewReservation,
                                      context: Context, house, room_type,
                                      rate_plan, rate):
    period = [
        datetime.date.today(),
        datetime.date.today() + datetime.timedelta(days=1)
    ]

    service._prices_repo = Mock(select_restrictions=Mock(return_value={
        period[0]: Decimal(50),
        period[1]: Decimal(50)
    }))
    context.house = house
    context.room_type = room_type
    context.rate_plan = rate_plan
    context.rate = rate

    result = service.select_price_restrictions(context)
    assert is_successful(result)
    assert result.unwrap().price_restrictions == {
        period[0]: Decimal(50),
        period[1]: Decimal(50)
    }