def test_select_room_type_fail(service: CalculateNewReservation, context: Context, house): service._roomtypes_repo = Mock(get=Mock(return_value=Nothing)) context.house = house result = service.select_room_type(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.missed_roomtype
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
def test_select_room_type_error(service: CalculateNewReservation, context: Context, house): service._roomtypes_repo = Mock(get=Mock(side_effect=RuntimeError("ERR"))) context.house = house result = service.select_room_type(context) assert not is_successful(result) assert result.failure().failure == ReservationErrors.error assert str(result.failure().exc) == "ERR"
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")}