コード例 #1
0
def test_check_reservation_ok(service: UpdateRoomClose, context: Context,
                              house, reservation):
    context.house = house
    context.source = reservation

    result = service.check_reservation(context)
    assert is_successful(result)
コード例 #2
0
def test_check_room_is_free_ok(service: UpdateRoomClose, context: Context,
                               house, room, reservation):
    service._reservations_repo = Mock(is_room_busy=Mock(return_value=False))
    context.house = house
    context.room = room
    context.source = reservation

    result = service.check_room_is_free(context)
    assert is_successful(result), result.failure()
コード例 #3
0
def test_check_reservation_not_close_room(service: UpdateRoomClose,
                                          context: Context, house,
                                          reservation):
    context.house = house
    context.source = attr.evolve(reservation, status=ReservationStatuses.NEW)

    result = service.check_reservation(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.missed_reservation
コード例 #4
0
def test_check_room_is_free_error(service: UpdateRoomClose, context: Context,
                                  house, room, reservation):
    service._reservations_repo = Mock(is_room_busy=Mock(
        side_effect=RuntimeError("ERR")))
    context.house = house
    context.room = room
    context.source = reservation

    result = service.check_room_is_free(context)
    assert not is_successful(result)
    assert result.failure().failure == ReservationErrors.error
    assert str(result.failure().exc) == "ERR"
コード例 #5
0
def test_make_reservation_from_data_change_period(service: UpdateRoomClose,
                                                  context: Context, house,
                                                  room, reservation):
    context.house = house
    context.room = room
    context.source = reservation
    context.start_date = reservation.checkin + datetime.timedelta(days=10)
    context.end_date = reservation.checkout + datetime.timedelta(days=10)

    result = service.make_reservation_from_data(context)
    assert is_successful(result), result.failure()

    _reservation = result.unwrap().reservation
    assert _reservation.id == reservation.id
    assert _reservation.checkin == context.start_date
    assert _reservation.checkout == context.end_date
    assert _reservation.status == ReservationStatuses.CLOSE
    assert _reservation.close_reason == RoomCloseReasons.MAINTENANCE

    assert len(_reservation.rooms) == 1

    _room = _reservation.rooms[0]
    assert _room.id == reservation.rooms[0].id
    assert _room.checkin == context.start_date
    assert _room.checkout == context.end_date
    assert _room.notes_info == "Comment"

    assert len(_room.day_prices) == 2

    price = _room.day_prices[0]
    assert price.id is None
    assert price.day == context.start_date
    assert price.roomtype_id == room.roomtype_id
    assert price.room_id == room.id

    price = _room.day_prices[1]
    assert price.id is None
    assert price.day == context.start_date + datetime.timedelta(days=1)
    assert price.roomtype_id == room.roomtype_id
    assert price.room_id == room.id