Ejemplo n.º 1
0
def handle_teacher_hours(
    teacher: Teacher,
    date: datetime,
    duration: int,
    type_: Optional[AppointmentType],
    appointment: Optional[Appointment],
):
    """check if there are existing lessons in the date given.
    If so - is test? - delete all existing lessons.
    NO - raise RouteError"""

    # check if there's another lesson that ends or starts within this time
    end_date = date + timedelta(minutes=duration)
    existing_lessons = Appointment.query.filter_by(teacher=teacher).filter(
        Appointment.appointments_between(date, end_date)
    )
    if appointment:
        existing_lessons = existing_lessons.filter(Appointment.id != appointment.id)

    existing_lessons = existing_lessons.all()
    logger.debug(f"For {date}, found existing lessons: {existing_lessons}")
    if existing_lessons:
        if type_ == AppointmentType.LESSON or date < datetime.utcnow():
            raise RouteError("This hour is not available.")
        # delete all lessons and send FCMs
        for existing_appointment in existing_lessons:
            if existing_appointment.type == AppointmentType.LESSON:
                delete_appointment_with_fcm(existing_appointment)
Ejemplo n.º 2
0
def test_appointments_between(teacher, student, requester, meetup, dropoff,
                              date, end_date, result):
    """1. get lessons with the same starting hour
    2. get lessons with the same ending hour
    3. get lessons that end within existing hours
    4. get lessons that start within existing hours
    5. lessons that start when existing lesson ends
    6. lesson that ends when existing lesson starts
    7. exactly the same hours
    """
    lesson = create_lesson(teacher, student, meetup, dropoff, tomorrow)
    existing_lessons = Appointment.query.filter(
        Appointment.appointments_between(date, end_date)).all()
    assert (lesson in existing_lessons) == result