def test_ongoing_bookings_are_not_split(create_reservation, start_dt, end_dt): from indico.modules.rb.operations.bookings import split_booking reservation = create_reservation(start_dt=start_dt, end_dt=end_dt, repeat_frequency=RepeatFrequency.DAY) assert split_booking(reservation, {}) is None
def _process(self, args): new_booking_data = { 'booking_reason': args['booking_reason'], 'booked_for_user': args.get('booked_for_user', self.booking.booked_for_user), 'start_dt': args['start_dt'], 'end_dt': args['end_dt'], 'repeat_frequency': args['repeat_frequency'], 'repeat_interval': args['repeat_interval'], } additional_booking_attrs = {} if not should_split_booking(self.booking, new_booking_data): has_slot_changed = not has_same_slots(self.booking, new_booking_data) room = self.booking.room self.booking.modify(new_booking_data, session.user) if (has_slot_changed and not room.can_book(session.user, allow_admin=False) and room.can_prebook(session.user, allow_admin=False) and self.booking.is_accepted): self.booking.reset_approval(session.user) else: new_booking = split_booking(self.booking, new_booking_data) additional_booking_attrs['new_booking_id'] = new_booking.id db.session.flush() today = date.today() calendar = get_room_calendar(args['start_dt'] or today, args['end_dt'] or today, [args['room_id']]) return jsonify(booking=dict(serialize_booking_details(self.booking), **additional_booking_attrs), room_calendar=serialize_availability(calendar).values())
def _process(self, args): new_booking_data = { 'booking_reason': args['booking_reason'], 'booked_for_user': args.get('booked_for_user', self.booking.booked_for_user), 'start_dt': args['start_dt'], 'end_dt': args['end_dt'], 'repeat_frequency': args['repeat_frequency'], 'repeat_interval': args['repeat_interval'], } additional_booking_attrs = {} if not should_split_booking(self.booking, new_booking_data): has_date_changed = not has_same_dates(self.booking, new_booking_data) room = self.booking.room self.booking.modify(new_booking_data, session.user) if (has_date_changed and not room.can_book(session.user, allow_admin=False) and room.can_prebook(session.user, allow_admin=False) and self.booking.is_accepted): self.booking.reset_approval(session.user) else: new_booking = split_booking(self.booking, new_booking_data) additional_booking_attrs['new_booking_id'] = new_booking.id db.session.flush() today = date.today() calendar = get_room_calendar(args['start_dt'] or today, args['end_dt'] or today, [args['room_id']]) return jsonify(booking=dict(serialize_booking_details(self.booking), **additional_booking_attrs), room_calendar=serialize_availability(calendar).values())
def past_booking_occurrences_are_cancelled(dummy_user, create_reservation): from indico.modules.rb.operations.bookings import split_booking start_dt = datetime.today().replace(hour=8, minutes=30) - timedelta(days=2) end_dt = datetime.today().replace(hour=17, minutes=30) + timedelta(days=4) reservation = create_reservation(start_dt=start_dt, end_dt=end_dt, repeat_frequency=RepeatFrequency.DAY) new_reservation = split_booking(reservation, { 'booking_reason': 'test reason', 'booked_for_user': dummy_user, 'start_dt': start_dt, 'end_dt': end_dt, 'repeat_frequency': RepeatFrequency.DAY, 'repeat_interval': reservation.repeat_interval }) number_of_cancelled_occurrences = [occ for occ in reservation.occurrences if occ.is_cancelled] assert number_of_cancelled_occurrences == 2 assert len(new_reservation.occurrences) == 4
def past_booking_occurrences_are_cancelled(dummy_user, create_reservation): from indico.modules.rb.operations.bookings import split_booking start_dt = datetime.today().replace(hour=8, minutes=30) - timedelta(days=2) end_dt = datetime.today().replace(hour=17, minutes=30) + timedelta(days=4) reservation = create_reservation(start_dt=start_dt, end_dt=end_dt, repeat_frequency=RepeatFrequency.DAY) new_reservation = split_booking(reservation, { 'booking_reason': 'test reason', 'booked_for_user': dummy_user, 'start_dt': start_dt, 'end_dt': end_dt, 'repeat_frequency': RepeatFrequency.DAY, 'repeat_interval': reservation.repeat_interval }) number_of_cancelled_occurrences = [occ for occ in reservation.occurrences if occ.is_cancelled] assert number_of_cancelled_occurrences == 2 assert len(new_reservation.occurrences) == 4
def test_ongoing_bookings_are_not_split(create_reservation, start_dt, end_dt): from indico.modules.rb.operations.bookings import split_booking reservation = create_reservation(start_dt=start_dt, end_dt=end_dt, repeat_frequency=RepeatFrequency.DAY) assert split_booking(reservation, {}) is None