def test_appointment_init(self):
     """
     Tests models.Appointment.__init__ to ensure that it correctly checks input
     """
     for test in self.appointment_init_test_cases:
         if issubclass(test[KEY_EXPECTED_TYPE], Exception):
             with self.assertRaises(test[KEY_EXPECTED_TYPE]):
                 result = models.Appointment(**test[KEY_INPUT])
         else:
             result = models.Appointment(**test[KEY_INPUT])
             self.assertTrue(isinstance(result, test[KEY_EXPECTED_TYPE]))
Ejemplo n.º 2
0
def create_appointment(db: Session, appointment: schemas.AppointmentBase):
    temp = appointment.dict()
    db_obj = models.Appointment(**temp)
    db.add(db_obj)
    db.commit()
    db.refresh(db_obj)
    return db_obj
Ejemplo n.º 3
0
def create_reservation(room_id, start_time, end_time, organizer_id, attendee_ids=None):
    """
    Creates and stores a reservation with the provided information
    """
    existing_reservation = (
        DB.session.query(models.Appointment)
        .filter(
            and_(
                models.Appointment.room_id == room_id,
                models.Appointment.start_time == start_time,
            )
        )
        .first()
    )
    if existing_reservation:
        print("A reservation already exists for this room at the given time")
        DB.session.commit()
        return False, None, None

    # TODO: jlh29, eventually check to make sure all attendee IDs are valid
    new_reservation = models.Appointment(
        room_id=room_id,
        start_time=start_time,
        end_time=end_time,
        organizer_id=organizer_id,
        attendee_ids=attendee_ids,
    )
    possible_characters = string.ascii_letters + string.digits
    new_check_in_code = "".join(
        random.choice(possible_characters) for i in range(CHECK_IN_CODE_LENGTH)
    )
    DB.session.add(new_reservation)
    DB.session.flush()
    new_check_in = models.CheckIn(
        reservation_id=new_reservation.id,
        validation_code=new_check_in_code,
    )
    DB.session.add(new_check_in)
    DB.session.commit()
    reservation_obj = models.AppointmentInfo(
        id=new_reservation.id,
        room=get_room_obj_by_id(new_reservation.room_id, True),
        start_time=new_reservation.start_time.timestamp() * 1000.0,
        end_time=new_reservation.end_time.timestamp() * 1000.0,
        organizer=get_user_obj_from_id(new_reservation.organizer_id, True),
        attendees=None
        if new_reservation.attendee_ids is None
        else [
            get_attendee_obj_from_id(id, True) for id in new_reservation.attendee_ids
        ],
        status=new_reservation.status,
    )
    return True, new_check_in_code, reservation_obj._asdict()
        ucid="lr123",
        role=models.UserRole.LIBRARIAN,
        name="Libra Rian",
    ),
}
MOCK_ATTENDEE_DB_ENTRIES = {
    1: models.Attendee(ucid="jd123"),
    2: models.Attendee(ucid="johnny.appleseed"),
    3: models.Attendee(ucid="lr123"),
}
MOCK_APPOINTMENT_DB_ENTRIES = {
    1:
    models.Appointment(
        room_id=1,
        start_time=datetime.datetime(2020, 1, 1, 12, 0, 0),
        end_time=datetime.datetime(2020, 1, 1, 13, 0, 0),
        organizer_id=1,
        attendee_ids=[1, 2, 3],
    ),
}
MOCK_ROOM_DB_ENTRIES = {
    1: models.Room(
        room_number=100,
        capacity=10,
        size=models.RoomSize.MEDIUM,
    ),
}
MOCK_UNAVAILABLE_DATE_DB_ENTRIES = {
    1: models.UnavailableDate(
        date=datetime.datetime(2020, 1, 1),
        reason=None,