Exemple #1
0
def test_check_los_discounts(service: CalculateNewReservation,
                             context: Context, house, room_type, rate,
                             los_discount):
    period = [
        context.start_date,
        context.start_date + datetime.timedelta(days=1),
        context.start_date + datetime.timedelta(days=2),
        context.start_date + datetime.timedelta(days=3),
    ]
    context.end_date = context.start_date + datetime.timedelta(days=4)
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.prices = {
        period[0]: Decimal(100),
        period[1]: Decimal(100),
        period[2]: Decimal(100),
        period[3]: Decimal(100),
    }
    context.discounts = {DiscountTypes.LOS: [los_discount]}

    result = service.check_los_discounts(context)
    assert is_successful(result)

    assert result.unwrap().prices == {
        period[0]: Decimal(85),
        period[1]: Decimal(85),
        period[2]: Decimal(85),
        period[3]: Decimal(85),
    }
Exemple #2
0
def test_missed_plan_id(service: CalculateNewReservation, context: Context,
                        house):
    context.house = house
    context.plan_id = None

    result = service.select_rate_plan(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_rateplan
Exemple #3
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
Exemple #4
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
Exemple #5
0
def test_select_room_type_ok(service: CalculateNewReservation,
                             context: Context, house, room_type):
    service._roomtypes_repo = Mock(get=Mock(return_value=Some(room_type)))
    context.house = house

    result = service.select_room_type(context)
    assert is_successful(result), result.failure()
    assert result.unwrap().room_type == room_type
Exemple #6
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"
Exemple #7
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]
Exemple #8
0
def test_select_rate_by_guest_count_fail(service: CalculateNewReservation,
                                         context: Context, house, room_type,
                                         rate_plan, rate):
    context.house = house
    context.room_type = room_type
    context.rate_plan = rate_plan
    context.rates = []

    result = service.select_rate_by_guest_count(context)
    assert is_successful(result)
    assert result.unwrap().rate is None
Exemple #9
0
def test_missed_rate_id(service: CalculateNewReservation, context: Context,
                        house, room_type, rate_plan, rate):
    context.house = house
    context.room_type = room_type
    context.rate_plan = rate_plan
    context.rate_id = None
    context.rates = [rate]

    result = service.select_rate_by_id(context)
    assert is_successful(result)
    assert result.unwrap().rate is None
Exemple #10
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"
Exemple #11
0
def test_select_rate_by_guest_count_only_less(service: CalculateNewReservation,
                                              context: Context, house,
                                              room_type, rate_plan, rate):
    rate_with_1 = attr.evolve(rate, id=401, occupancy=1)
    context.house = house
    context.room_type = room_type
    context.rate_plan = rate_plan
    context.rates = [rate_with_1]

    result = service.select_rate_by_guest_count(context)
    assert is_successful(result)
    assert result.unwrap().rate == rate_with_1
Exemple #12
0
def test_select_occupancy_no_discounts(service: CalculateNewReservation,
                                       context: Context, house, room_type,
                                       rate):
    service._occupancy_repo = Mock(get=Mock(side_effect=RuntimeError("ERR")))
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.discounts = {DiscountTypes.AVAILABILITY: []}

    result = service.select_occupancies(context)
    assert is_successful(result)
    assert result.unwrap().occupancies == {}
Exemple #13
0
def test_select_occupancy_error(service: CalculateNewReservation,
                                context: Context, house, room_type, rate,
                                availability_discount):
    service._occupancy_repo = Mock(get=Mock(side_effect=RuntimeError("ERR")))
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.discounts = {DiscountTypes.AVAILABILITY: [availability_discount]}

    result = service.select_occupancies(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == "ERR"
Exemple #14
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,
    }
Exemple #15
0
def test_check_los_discounts_empty(service: CalculateNewReservation,
                                   context: Context, house, room_type, rate):
    period = [
        context.start_date, context.start_date + datetime.timedelta(days=1)
    ]
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.prices = {period[0]: Decimal(100), period[1]: Decimal(110)}
    context.discounts = {DiscountTypes.LOS: []}

    result = service.check_los_discounts(context)
    assert is_successful(result)
    assert result.unwrap().prices == context.prices
Exemple #16
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
Exemple #17
0
def test_select_occupancy_ok(service: CalculateNewReservation,
                             context: Context, house, room_type, rate,
                             availability_discount):
    occupancies = {
        context.start_date: 1,
        context.start_date + datetime.timedelta(days=1): 2
    }
    service._occupancy_repo = Mock(get=Mock(return_value=occupancies))
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.discounts = {DiscountTypes.AVAILABILITY: [availability_discount]}

    result = service.select_occupancies(context)
    assert is_successful(result)
    assert result.unwrap().occupancies == occupancies
Exemple #18
0
def test_select_discounts_no_rate(service: CalculateNewReservation,
                                  context: Context, house, room_type,
                                  rate_plan):
    service._discounts_repo = Mock(select=Mock(
        side_effect=RuntimeError("ERR")))
    context.house = house
    context.room_type = room_type
    context.rate = None
    context.rate_plan = rate_plan
    context.prices = {
        context.start_date: None,
        context.start_date + datetime.timedelta(days=1): None
    }

    result = service.select_discounts(context)
    assert is_successful(result)
    assert result.unwrap().discounts == {}
Exemple #19
0
def test_select_discounts_missed_rate_plan(service: CalculateNewReservation,
                                           context: Context, house, room_type,
                                           rate, rate_plan, last_min_discount):
    service._discounts_repo = Mock(select=Mock(
        return_value={DiscountTypes.LAST_MINUTE: [last_min_discount]}))
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.rate_plan = attr.evolve(rate_plan, id=999)
    context.prices = {
        context.start_date: Decimal(100),
        context.start_date + datetime.timedelta(days=1): Decimal(110)
    }

    result = service.select_discounts(context)
    assert is_successful(result)
    assert result.unwrap().discounts == {DiscountTypes.LAST_MINUTE: []}
Exemple #20
0
def test_select_discounts_error(service: CalculateNewReservation,
                                context: Context, house, room_type, rate,
                                rate_plan):
    service._discounts_repo = Mock(select=Mock(
        side_effect=RuntimeError("ERR")))
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.rate_plan = rate_plan
    context.prices = {
        context.start_date: Decimal(100),
        context.start_date + datetime.timedelta(days=1): Decimal(110)
    }

    result = service.select_discounts(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == "ERR"
Exemple #21
0
def test_check_availability_discounts(service: CalculateNewReservation,
                                      context: Context, house, room_type, rate,
                                      availability_discount):
    period = [
        context.start_date, context.start_date + datetime.timedelta(days=1)
    ]
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.prices = {period[0]: Decimal(100), period[1]: Decimal(110)}
    context.discounts = {DiscountTypes.AVAILABILITY: [availability_discount]}
    context.occupancies = {period[0]: 3, period[1]: 1}

    result = service.check_availability_discounts(context)
    assert is_successful(result)

    assert result.unwrap().prices == {
        period[0]: Decimal(85),
        period[1]: Decimal(110)
    }
Exemple #22
0
def test_check_last_minute_discounts(service: CalculateNewReservation,
                                     context: Context, house, room_type, rate,
                                     last_min_discount):
    period = [
        context.start_date + datetime.timedelta(days=5),
        context.start_date + datetime.timedelta(days=6)
    ]
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.prices = {period[0]: Decimal(100), period[1]: Decimal(110)}
    context.discounts = {DiscountTypes.LAST_MINUTE: [last_min_discount]}

    result = service.check_last_minute_discounts(context)
    assert is_successful(result)

    assert result.unwrap().prices == {
        period[0]: Decimal(85),
        period[1]: Decimal(110)
    }
Exemple #23
0
def test_check_min_prices(service: CalculateNewReservation, context: Context,
                          house, room_type, rate_plan, rate):
    period = [
        datetime.date.today(),
        datetime.date.today() + datetime.timedelta(days=1)
    ]
    context.house = house
    context.room_type = room_type
    context.rate = rate
    context.prices = {period[0]: Decimal(80), period[1]: Decimal(110)}
    context.price_restrictions = {
        period[0]: Decimal(100),
        period[1]: Decimal(100)
    }

    result = service.check_min_prices(context)
    assert is_successful(result)
    assert result.unwrap().prices == {
        period[0]: Decimal(100),
        period[1]: Decimal(110)
    }
Exemple #24
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)
    }