Exemplo n.º 1
0
 def test_timestamps(self):
     """Epoch timestamp in PST timezone."""
     with override_config(app, 'CURRENT_TERM_BEGIN', _get_wednesday_august_26()):
         first_day_start = get_first_matching_datetime_of_term(
             meeting_days=['TU', 'TH'],
             start_date=datetime.strptime(app.config['CURRENT_TERM_BEGIN'], '%Y-%m-%d'),
             time_hours=9,
             time_minutes=37,
         )
         assert first_day_start.timestamp() == 1598546220.0
Exemplo n.º 2
0
 def test_first_meeting_is_day_after_term_begin(self):
     """First meeting is the day after start of term."""
     with override_config(app, 'CURRENT_TERM_BEGIN', _get_wednesday_august_26()):
         first_day_start = get_first_matching_datetime_of_term(
             meeting_days=['TU', 'TH'],
             start_date=datetime.strptime(app.config['CURRENT_TERM_BEGIN'], '%Y-%m-%d'),
             time_hours=13,
             time_minutes=30,
         )
         assert first_day_start.day == 27
Exemplo n.º 3
0
 def test_first_meeting_is_week_after_term_begin(self):
     """First meeting is the Monday following first week of term."""
     with override_config(app, 'CURRENT_TERM_BEGIN', _get_wednesday_august_26()):
         first_day_start = get_first_matching_datetime_of_term(
             meeting_days=['MO', 'TU'],
             start_date=datetime.strptime(app.config['CURRENT_TERM_BEGIN'], '%Y-%m-%d'),
             time_hours=8,
             time_minutes=45,
         )
         assert first_day_start.day == 31
Exemplo n.º 4
0
 def test_first_meeting_is_different_month(self):
     """First meeting is in week after start of term, in a new month."""
     with override_config(app, 'CURRENT_TERM_BEGIN', _get_wednesday_august_26()):
         first_day_start = get_first_matching_datetime_of_term(
             meeting_days=['TU'],
             start_date=datetime.strptime(app.config['CURRENT_TERM_BEGIN'], '%Y-%m-%d'),
             time_hours=9,
             time_minutes=15,
         )
         assert first_day_start.month == 9
         assert first_day_start.day == 1
Exemplo n.º 5
0
    def _schedule_recurring_events_in_kaltura(
        self,
        category_ids,
        course_label,
        instructors,
        meeting,
        publish_type,
        recording_type,
        room,
        term_id,
    ):
        # Recording starts X minutes before/after official start; it ends Y minutes before/after official end time.
        days = format_days(meeting['days'])
        start_time = _adjust_time(meeting['startTime'],
                                  app.config['KALTURA_RECORDING_OFFSET_START'])
        end_time = _adjust_time(meeting['endTime'],
                                app.config['KALTURA_RECORDING_OFFSET_END'])

        app.logger.info(f"""
            Prepare to schedule recordings for {course_label}:
                Room: {room.location}
                Instructor UIDs: {[instructor['uid'] for instructor in instructors]}
                Schedule: {days}, {start_time} to {end_time}
                Recording: {recording_type}; {publish_type}
        """)

        term_name = term_name_for_sis_id(term_id)
        recording_start_date = get_recording_start_date(
            meeting, return_today_if_past_start=True)
        recording_end_date = get_recording_end_date(meeting)
        summary = f'{course_label} ({term_name})'
        app.logger.info(f"""
            {course_label} ({term_name}) meets in {room.location},
            between {start_time.strftime('%H:%M')} and {end_time.strftime('%H:%M')}, on {days}.
            Recordings of type {recording_type} will be published to {publish_type}.
        """)

        first_day_start = get_first_matching_datetime_of_term(
            meeting_days=days,
            start_date=recording_start_date,
            time_hours=start_time.hour,
            time_minutes=start_time.minute,
        )
        first_day_end = get_first_matching_datetime_of_term(
            meeting_days=days,
            start_date=recording_start_date,
            time_hours=end_time.hour,
            time_minutes=end_time.minute,
        )
        description = get_series_description(course_label, instructors,
                                             term_name)
        base_entry = self._create_kaltura_base_entry(
            description=description,
            instructors=instructors,
            name=f'{summary} in {room.location}',
        )
        for category_id in category_ids or []:
            self.add_to_kaltura_category(category_id=category_id,
                                         entry_id=base_entry.id)

        until = datetime.combine(
            recording_end_date,
            time(end_time.hour, end_time.minute),
            tzinfo=default_timezone(),
        )
        recurring_event = KalturaRecordScheduleEvent(
            # https://developer.kaltura.com/api-docs/General_Objects/Objects/KalturaScheduleEvent
            classificationType=KalturaScheduleEventClassificationType.
            PUBLIC_EVENT,
            comment=f'{summary} in {room.location}',
            contact=','.join(instructor['uid'] for instructor in instructors),
            description=description,
            duration=(end_time - start_time).seconds,
            endDate=first_day_end.timestamp(),
            organizer=app.config['KALTURA_EVENT_ORGANIZER'],
            ownerId=app.config['KALTURA_KMS_OWNER_ID'],
            partnerId=self.kaltura_partner_id,
            recurrence=KalturaScheduleEventRecurrence(
                # https://developer.kaltura.com/api-docs/General_Objects/Objects/KalturaScheduleEventRecurrence
                byDay=','.join(days),
                frequency=KalturaScheduleEventRecurrenceFrequency.WEEKLY,
                # 'interval' is not documented. When scheduling manually, the value was 1 in each individual event.
                interval=1,
                name=summary,
                timeZone='US/Pacific',
                until=until.timestamp(),
                weekStartDay=days[0],
            ),
            recurrenceType=KalturaScheduleEventRecurrenceType.RECURRING,
            startDate=first_day_start.timestamp(),
            status=KalturaScheduleEventStatus.ACTIVE,
            summary=summary,
            tags=CREATED_BY_DIABLO_TAG,
            templateEntryId=base_entry.id,
        )
        return self.kaltura_client.schedule.scheduleEvent.add(recurring_event)