def test__schedule_valid_false_for_invalid_schedule(self):
        """ Tests that _schedule_valid returns false for an invalid schedule """
        # Test a schedule for 201931 containing CSCE 310-501 CSCE 121-501
        # Arrange
        meetings = [
            # Meetings for CSCE 310-501
            Meeting(id=10, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[0]),
            Meeting(id=11, meeting_days=[True] * 7, start_time=time(9),
                    end_time=time(9, 50), meeting_type='LEC', section=self.sections[0]),
            # Meetings for CSCE 121-501
            Meeting(id=40, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[3]),
            Meeting(id=41, meeting_days=[True] * 7, start_time=time(9, 10),
                    end_time=time(10), meeting_type='LAB', section=self.sections[3]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Convert meetings to expected format (set of days they meet)
        for meeting in meetings:
            meeting.meeting_days = set(i for i, day in enumerate(meeting.meeting_days)
                                       if day)
        meetings = ({"501": meetings[0:2]}, {"501": meetings[2:]})
        schedule = ("501", "501")

        # Act
        valid = _schedule_valid(meetings, schedule)

        # Assert
        self.assertFalse(valid)
    def test__get_meetings_handles_unavailability(self):
        """ Tests that _get_meetings filters sections with meetings conflicting
            with the given unavailable_times
        """
        # Arrange
        course = CourseFilter("CSCE", "310")
        term = "201931"
        include_full = True
        unavailable_times = (UnavailableTime(time(8), time(8, 30), 4),)
        meetings = [
            # Meetings for CSCE 310-501
            Meeting(id=10, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[0]),
            Meeting(id=11, meeting_days=[True] * 7, start_time=time(9),
                    end_time=time(9, 50), meeting_type='LEC', section=self.sections[0]),
            # Meetings for CSCE 310-502
            Meeting(id=20, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[1]),
            Meeting(id=21, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[1]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Section 502 should be filtered because of the unavailable time
        valid_sections = set((1,))
        meetings_for_sections = {1: meetings[0:2]}
        # Act
        meetings = _get_meetings(course, term, include_full, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
Esempio n. 3
0
    def test_create_schedules_throws_when_no_schedules_are_possible(self):
        """ Tests that create_schedules throws an appropriate error message when all
            sections for the chosen courses overlap, meaning no schedules are possible.
        """
        # Arrange
        courses = (
            CourseFilter('CSCE', '221', include_full=True),
            CourseFilter('CSCE', '310', section_nums=['501']),
        )
        term = '201931'

        unavailable_times = []
        meetings = [
            Meeting(id=10,
                    meeting_days=[True] * 7,
                    start_time=time(0, 0),
                    end_time=time(23, 59),
                    meeting_type='LEC',
                    section=self.sections[0]),
            Meeting(id=80,
                    meeting_days=[True] * 7,
                    start_time=time(0, 0),
                    end_time=time(23, 59),
                    meeting_type='LEC',
                    section=self.sections[7]),
        ]
        Meeting.objects.bulk_create(meetings)
        expected_error = _NO_SCHEDULES_POSSIBLE

        # Act + Assert
        with self.assertRaisesMessage(NoSchedulesError, expected_error):
            create_schedules(courses, term, unavailable_times)
    def test__get_meetings_filters_full(self):
        """ Tests that _get_meetings filters sections with no available seats if the
            include_full attribute of the CourseFilter is False
        """
        # Arrange
        course = CourseFilter("CSCE", "121")
        term = "201931"
        include_full = False
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 121-501
            Meeting(id=40, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[3]),
            Meeting(id=41, meeting_days=[True] * 7, start_time=time(9, 10),
                    end_time=time(10), meeting_type='LAB', section=self.sections[3]),
            # Meetings for CSCE 121-502
            Meeting(id=50, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[4]),
            Meeting(id=51, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[4]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Section 502 should be filtered because it has no available seats
        valid_sections = set((4,))
        meetings_for_sections = {4: meetings[0:2]}

        # Act
        meetings = _get_meetings(course, term, include_full, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
    def test__schedule_valid_true_for_valid_schedule(self):
        """ Tests that _schedule_valid returns true for a valid schedule """
        # Test a schedule for 201931 containing CSCE 310-501 and CSCE 121-501
        # Arrange
        meetings = [
            # Meetings for CSCE 310-502
            Meeting(id=20, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[1]),
            Meeting(id=21, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[1]),
            # Meetings for CSCE 121-502
            Meeting(id=50, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[4]),
            Meeting(id=51, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[4]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Convert meetings to expected format (set of days they meet)
        for meeting in meetings:
            meeting.meeting_days = set(i for i, day in enumerate(meeting.meeting_days)
                                       if day)
        meetings = ({"502": meetings[0:2]}, {"502": meetings[2:]})
        schedule = ("502", "502")

        # Act
        valid = _schedule_valid(meetings, schedule)

        # Assert
        self.assertTrue(valid)
    def test__get_meetings_filters_non_web(self):
        """ Tests that _get_meetings filters non-web sections if the web attribute
            of the CourseFilter is 'only'
        """
        # Arrange
        course = CourseFilter("CSCE", "121", web=BasicFilter.ONLY)
        term = "201931"
        include_full = True
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 121-501
            Meeting(id=40, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[3]),
            Meeting(id=41, meeting_days=[True] * 7, start_time=time(9, 10),
                    end_time=time(10), meeting_type='LAB', section=self.sections[3]),
            # Meetings for CSCE 121-502
            Meeting(id=50, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[4]),
            Meeting(id=51, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[4]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Section 501 should be filtered because it isn't a web section
        valid_sections = set((5,))
        meetings_for_sections = {5: meetings[2:]}

        # Act
        meetings = _get_meetings(course, term, include_full, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
    def test__get_meetings_filters_honors(self):
        """ Tests that _get_meetings filters honors sections if the honors attribute
            of the CourseFilter is 'exclude'
        """
        # Arrange
        course = CourseFilter("CSCE", "121",
                              honors=BasicFilter.EXCLUDE,
                              web=BasicFilter.NO_PREFERENCE)
        term = "201931"
        include_full = True
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 121-502
            Meeting(id=50, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[4]),
            Meeting(id=51, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[4]),
            # Meetings for CSCE 121-201
            Meeting(id=60, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[5]),
            Meeting(id=61, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[5]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Section 201 should be filtered because it is an honors section
        valid_sections = set((5,))
        meetings_for_sections = {5: meetings[0:2]}

        # Act
        meetings = _get_meetings(course, term, include_full, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
    def test__get_meetings_filters_section_nums(self):
        """ Tests that _get_meetings filters sections not in the CourseFilter's
            section_nums
        """
        # Arrange
        course = CourseFilter("CSCE", "310", section_nums=[501])
        term = "201931"
        include_full = True
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 310-501
            Meeting(id=10, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[0]),
            Meeting(id=11, meeting_days=[True] * 7, start_time=time(9),
                    end_time=time(9, 50), meeting_type='LEC', section=self.sections[0]),
            # Meetings for CSCE 310-502
            Meeting(id=20, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[1]),
            Meeting(id=21, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[1]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Section 502 should be filtered because it isn't in section_nums
        valid_sections = set((1,))
        meetings_for_sections = {1: meetings[0:2]}
        # Act
        meetings = _get_meetings(course, term, include_full, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
Esempio n. 9
0
    def test__get_meetings_filters_asynchronous(self):
        """ Tests that _get_meetings filters asynchronous sections if the
            asynchrnous filter is 'exclude'
        """
        # Arrange
        course = CourseFilter("CSCE",
                              "121",
                              asynchronous=BasicFilter.EXCLUDE,
                              include_full=True)
        term = "201931"
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 121-501
            Meeting(id=40,
                    meeting_days=[True] * 7,
                    start_time=time(11, 30),
                    end_time=time(12, 20),
                    meeting_type='LEC',
                    section=self.sections[3]),
            Meeting(id=41,
                    meeting_days=[True] * 7,
                    start_time=time(9, 10),
                    end_time=time(10),
                    meeting_type='LAB',
                    section=self.sections[3]),
            # Meetings for CSCE 121-M99
            Meeting(id=70,
                    meeting_days=[False] * 7,
                    start_time=None,
                    end_time=None,
                    meeting_type='LEC',
                    section=self.sections[6]),
            Meeting(id=71,
                    meeting_days=[False] * 7,
                    start_time=None,
                    end_time=None,
                    meeting_type='LAB',
                    section=self.sections[6]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Section 501 should be filtered because it isn't a remote section
        valid_sections = set((4, ))
        meetings_for_sections = {4: meetings[:2]}

        # Act
        result_meetings = _get_meetings(course, term, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(result_meetings, valid_sections,
                                            meetings_for_sections)
Esempio n. 10
0
    def test__get_meetings_filters_non_honors(self):
        """ Tests that _get_meetings filters out non-honors sections if the honors
            attribute of the CourseFilter is 'only'
        """
        # Arrange
        course = CourseFilter("CSCE",
                              "121",
                              honors=BasicFilter.ONLY,
                              include_full=True)
        term = "201931"
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 121-502
            Meeting(id=50,
                    meeting_days=[True] * 7,
                    start_time=time(12, 30),
                    end_time=time(1, 20),
                    meeting_type='LEC',
                    section=self.sections[4]),
            Meeting(id=51,
                    meeting_days=[True] * 7,
                    start_time=time(10),
                    end_time=time(10, 50),
                    meeting_type='LAB',
                    section=self.sections[4]),
            # Meetings for CSCE 121-201
            Meeting(id=60,
                    meeting_days=[True] * 7,
                    start_time=time(12, 30),
                    end_time=time(1, 20),
                    meeting_type='LEC',
                    section=self.sections[5]),
            Meeting(id=61,
                    meeting_days=[True] * 7,
                    start_time=time(10),
                    end_time=time(10, 50),
                    meeting_type='LAB',
                    section=self.sections[5]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Section 502 should be filtered because it isn't an honors section
        valid_sections = set((6, ))
        meetings_for_sections = {6: meetings[2:]}

        # Act
        meetings = _get_meetings(course, term, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
def parse_meeting(meetings_data, section: Section,
                  meeting_count: int) -> Meeting:
    """ Parses the meeting data and saves it as a Meeting model.
        Called by parse_section on each of the section's meeting times.
    """

    meeting_id = generate_meeting_id(str(section.id), str(meeting_count))

    class_days = parse_meeting_days(meetings_data)

    start_time = convert_meeting_time(
        meetings_data['meetingTime']['beginTime'])
    end_time = convert_meeting_time(meetings_data['meetingTime']['endTime'])

    building = meetings_data['meetingTime']['building']
    if building is not None:  # Must be escaped for O&M building
        building = unescape(building)

    class_type = meetings_data['meetingTime']['meetingType']

    meeting_model = Meeting(id=meeting_id,
                            building=building,
                            meeting_days=class_days,
                            start_time=start_time,
                            end_time=end_time,
                            meeting_type=class_type,
                            section=section)
    return meeting_model
    def test__get_meetings_gets_all_meetings(self):
        """ Tests that _get_meetings gets all sections/meetings for the specified term
            and groups them correctly
        """
        # Arrange
        course = CourseFilter("CSCE", "310")
        term = "201931"
        include_full = True
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 310-501
            Meeting(id=10, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[0]),
            Meeting(id=11, meeting_days=[True] * 7, start_time=time(9),
                    end_time=time(9, 50), meeting_type='LEC', section=self.sections[0]),
            # Meetings for CSCE 310-502
            Meeting(id=20, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[1]),
            Meeting(id=21, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[1]),
            # Meetings for CSCE 310-503
            Meeting(id=30, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[2]),
            Meeting(id=31, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[2]),
        ]
        Meeting.objects.bulk_create(meetings)
        valid_sections = set((1, 2))
        meetings_for_sections = {1: meetings[0:2], 2: meetings[2:4]}
        # Act
        meetings = _get_meetings(course, term, include_full, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
Esempio n. 13
0
    def test__get_meetings_manually_selected_sections_override_include_full(
            self):
        """ Tests that _get_meetings does not filter full sections selected in section
            select when include_full is false
        """
        # Arrange
        # section chosen because it is full
        section_nums = ["502"]
        course = CourseFilter("CSCE",
                              "121",
                              section_nums=section_nums,
                              include_full=False)
        term = "201931"
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 121-502
            Meeting(id=1,
                    meeting_days=[True] * 7,
                    start_time=time(12, 30),
                    end_time=time(1, 20),
                    meeting_type='LEC',
                    section=self.sections[4]),
            Meeting(id=51,
                    meeting_days=[True] * 7,
                    start_time=time(10),
                    end_time=time(10, 50),
                    meeting_type='LAB',
                    section=self.sections[4]),
        ]
        Meeting.objects.bulk_create(meetings)
        valid_sections = set((5, ))
        meetings_for_sections = {5: meetings[0:]}

        # Act
        meetings = _get_meetings(course, term, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
    def test_create_schedules_uses_unavailable_times(self):
        """ Tests that create_schedule filters out the provided unavailable_times. """
        # There are 4 possible schedules to generate, 1 is valid given the
        # unavailable times
        # Arrange
        courses = (
            CourseFilter("CSCE", "310"),
            CourseFilter("CSCE", "121",
                         honors=BasicFilter.NO_PREFERENCE,
                         web=BasicFilter.NO_PREFERENCE)
        )
        term = "201931"
        include_full = True
        unavailable_times = [UnavailableTime(time(9, 1), time(9, 2), 4)]
        meetings = [
            # Meetings for CSCE 310-501
            Meeting(id=10, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[0]),
            Meeting(id=11, meeting_days=[True] * 7, start_time=time(9),
                    end_time=time(9, 50), meeting_type='LEC', section=self.sections[0]),
            # Meetings for CSCE 310-502
            Meeting(id=20, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[1]),
            Meeting(id=21, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[1]),
            # Meetings for CSCE 121-501
            Meeting(id=40, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[3]),
            Meeting(id=41, meeting_days=[True] * 7, start_time=time(9, 10),
                    end_time=time(10), meeting_type='LAB', section=self.sections[3]),
            # Meetings for CSCE 121-502
            Meeting(id=50, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[4]),
            Meeting(id=51, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[4]),
        ]
        Meeting.objects.bulk_create(meetings)
        expected_schedules = set(((2, 5),))

        # Act
        schedules = set(create_schedules(courses, term, unavailable_times, include_full,
                                         num_schedules=10))

        # Act
        print('calculator')
        print(schedules)
        print(expected_schedules)
        self.assertEqual(schedules, expected_schedules)
    def test_create_schedules_creates_all_valid_schedules(self):
        """ Tests that create_schedules makes all valid schedules and doesn't
            return any invalid ones
        """
        # There are 4 possible schedules to generate, 2 are valid
        # Arrange
        courses = (
            CourseFilter("CSCE", "310"),
            CourseFilter("CSCE", "121",
                         honors=BasicFilter.NO_PREFERENCE,
                         web=BasicFilter.NO_PREFERENCE)
        )
        term = "201931"
        include_full = True
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 310-501
            Meeting(id=10, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[0]),
            Meeting(id=11, meeting_days=[True] * 7, start_time=time(9),
                    end_time=time(9, 50), meeting_type='LEC', section=self.sections[0]),
            # Meetings for CSCE 310-502
            Meeting(id=20, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[1]),
            Meeting(id=21, meeting_days=[True] * 7, start_time=time(8),
                    end_time=time(8, 50), meeting_type='LAB', section=self.sections[1]),
            # Meetings for CSCE 121-501
            Meeting(id=40, meeting_days=[True] * 7, start_time=time(11, 30),
                    end_time=time(12, 20), meeting_type='LEC', section=self.sections[3]),
            Meeting(id=41, meeting_days=[True] * 7, start_time=time(9, 10),
                    end_time=time(10), meeting_type='LAB', section=self.sections[3]),
            # Meetings for CSCE 121-502
            Meeting(id=50, meeting_days=[True] * 7, start_time=time(12, 30),
                    end_time=time(1, 20), meeting_type='LEC', section=self.sections[4]),
            Meeting(id=51, meeting_days=[True] * 7, start_time=time(10),
                    end_time=time(10, 50), meeting_type='LAB', section=self.sections[4]),
        ]
        Meeting.objects.bulk_create(meetings)
        expected_schedules = set(((1, 5), (2, 5)))

        # Act
        schedules = set(create_schedules(courses, term, unavailable_times, include_full,
                                         num_schedules=10))

        # Act
        self.assertEqual(schedules, expected_schedules)
    def test__parse_meeting__normalInput__formsCorrectly(self):
        """ Given a normal section meeting input, ensure it formats correctly """
        expected = Meeting(id="CSCE110-501-0",
                           crn="10915",
                           building="ZACH",
                           meeting_days="TR",
                           start_time=time(12, 45, 0),
                           end_time=time(14, 0, 0),
                           meeting_type="LEC")

        actual = scrape_courses.parse_meeting(
            self.section_input['meetingsFaculty'][0]['meetingTime'],
            'CSCE110-501')
        print(expected.crn)
        print(actual.crn)

        self.assertEqual(expected, actual)
Esempio n. 17
0
    def test_create_schedules_throws_when_no_sections_match_availability(self):
        """ Tests that create_schedules throws an appropriate error message when no
            sections match the selected availabilities.
        """
        # Arrange
        subject = 'CSCE'
        course_num = '221'
        courses = (CourseFilter(subject, course_num, include_full=True), )
        term = '201931'
        unavailable_times = [UnavailableTime(time(0, 0), time(23, 59), 0)]
        Meeting(id=80,
                meeting_days=[True, *[False] * 6],
                start_time=time(0, 0),
                end_time=time(23, 59),
                meeting_type='LEC',
                section=self.sections[7]).save()
        expected_error = _NO_SECTIONS_MATCH_AVAILABILITIES.format(
            subject=subject, course_num=course_num)

        # Act + Assert
        with self.assertRaisesMessage(NoSchedulesError, expected_error):
            create_schedules(courses, term, unavailable_times)
Esempio n. 18
0
    def test_get_saved_schedules_gets_schedules_for_term(self):
        """ Tests that /sessions/get_saved_schedules correctly fetches the sections
            and meetings for a given schedule
        """
        # Arrange
        term = '202031'

        # Create the models
        ins = Instructor(id='fake name', email_address='[email protected]')
        ins.save()
        sec = Section(id=1,
                      subject='CSCE',
                      course_num='121',
                      section_num='500',
                      term_code=term,
                      crn=0,
                      min_credits=0,
                      max_credits=0,
                      max_enrollment=0,
                      current_enrollment=0,
                      instructor=ins,
                      asynchronous=False)
        sec.save()
        meeting = Meeting(id=11,
                          section=sec,
                          start_time=time(11, 0),
                          end_time=time(12, 0),
                          meeting_days=[True] * 7,
                          meeting_type='LEC',
                          building='ONLINE')
        meeting.save()

        # Add the schedule to the session
        session = self.client.session
        session_input = [{'name': 'Schedule 1', 'sections': [1]}]
        session[term] = {'schedules': session_input}
        session.save()

        expected = [{
            'name':
            'Schedule 1',
            'sections': [{
                'id':
                1,
                'subject':
                'CSCE',
                'course_num':
                '121',
                'section_num':
                '500',
                'crn':
                0,
                'min_credits':
                0,
                'max_credits':
                0,
                'max_enrollment':
                0,
                'current_enrollment':
                0,
                'instructor_name':
                'fake name',
                'honors':
                None,
                'remote':
                None,
                'grades':
                None,
                'asynchronous':
                False,
                'instructional_method':
                '',
                'meetings': [{
                    'id': '11',
                    'start_time': '11:00',
                    'end_time': '12:00',
                    'days': [True] * 7,
                    'type': 'LEC',
                    'building': 'ONLINE',
                }]
            }]
        }]

        # Act
        response = self.client.get(
            f'/sessions/get_saved_schedules?term={term}')

        # Assert
        self.assertEqual(response.json(), expected)
        self.assertEqual(response.status_code, 200)
Esempio n. 19
0
    def test__get_meetings_filters_remote(self):
        """ Tests that _get_meetings filters remote sections if the honors attribute
            of the CourseFilter is 'exclude'
        """
        # Arrange
        course = CourseFilter("CSCE",
                              "121",
                              remote=BasicFilter.EXCLUDE,
                              include_full=True)
        term = "201931"
        unavailable_times = []
        meetings = [
            # Meetings for CSCE 121-501
            Meeting(id=40,
                    meeting_days=[True] * 7,
                    start_time=time(11, 30),
                    end_time=time(12, 20),
                    meeting_type='LEC',
                    section=self.sections[3]),
            Meeting(id=41,
                    meeting_days=[True] * 7,
                    start_time=time(9, 10),
                    end_time=time(10),
                    meeting_type='LAB',
                    section=self.sections[3]),
            # Meetings for CSCE 121-502
            Meeting(id=50,
                    meeting_days=[True] * 7,
                    start_time=time(12, 30),
                    end_time=time(1, 20),
                    meeting_type='LEC',
                    section=self.sections[4]),
            Meeting(id=51,
                    meeting_days=[True] * 7,
                    start_time=time(10),
                    end_time=time(10, 50),
                    meeting_type='LAB',
                    section=self.sections[4]),
            # Meetings for CSCE 121-M99
            Meeting(id=70,
                    meeting_days=[False] * 7,
                    start_time=None,
                    end_time=None,
                    meeting_type='LEC',
                    section=self.sections[6]),
            Meeting(id=71,
                    meeting_days=[False] * 7,
                    start_time=None,
                    end_time=None,
                    meeting_type='LAB',
                    section=self.sections[6]),
        ]
        Meeting.objects.bulk_create(meetings)
        # Section M99 should be filtered because it's a remote section
        valid_sections = set((4, 5))
        meetings_for_sections = {4: meetings[0:2], 5: meetings[2:4]}

        # Act
        meetings = _get_meetings(course, term, unavailable_times)

        # Assert
        self.assert_meetings_match_expected(meetings, valid_sections,
                                            meetings_for_sections)
Esempio n. 20
0
 def setUpTestData(cls):
     cls.client = APIClient()
     cls.courses = [
         Course(id='CSCE181-201931', dept='CSCE', course_num='181',
                title='INTRODUCTION TO COMPUTING', term='201931', credit_hours=3),
         Course(id='CSCE315-201931', dept='CSCE', course_num='315',
                title='PROGRAMMING STUDIO', term='201931', credit_hours=3),
         Course(id='COMM203-201831', dept='COMM', course_num='203',
                title='PUBLIC SPEAKING', term='201831', credit_hours=3),
         Course(id='COMM203-201931', dept='COMM', course_num='203',
                title='PUBLIC SPEAKING', term='201931', credit_hours=3),
         Course(id='LAW7500S-202031', dept='LAW', course_num='7500S',
                title='SPORTS LAW', term='202031', credit_hours=None),
         Course(id='CSCE181-201731', dept='CSCE', course_num='181',
                title='INTRODUCTION TO COMPUTING', term='201731', credit_hours=3),
         Course(id='CSCE310-201731', dept='CSCE', course_num='310',
                title='DATABASE SYSTEMS', term='201731', credit_hours=3),
         Course(id='CSCE315-201731', dept='CSCE', course_num='315',
                title='PROGRAMMING STUDIO', term='201731', credit_hours=3)
     ]
     cls.instructors = [
         Instructor(id='Akash Tyagi'),
         Instructor(id='John Moore'),
     ]
     Instructor.objects.bulk_create(cls.instructors)
     cls.sections = [
         Section(crn=12345, id='000001', subject='CSCE', course_num='310',
                 section_num='501', term_code='201931', min_credits='3',
                 honors=False, web=False, max_enrollment=50,
                 current_enrollment=40, instructor=cls.instructors[0]),
         Section(crn=12346, id='000002', subject='CSCE', course_num='310',
                 section_num='502', term_code='201931', min_credits='3',
                 honors=False, web=False, max_enrollment=50,
                 current_enrollment=40, instructor=cls.instructors[1]),
         Section(crn=35304, id='000003', subject='ASCC', course_num='101',
                 section_num='502', term_code='201911', min_credits='0',
                 honors=False, web=False, max_enrollment=25,
                 current_enrollment=24, instructor=cls.instructors[0]),
         Section(crn=36169, id='000004', subject='ASCC', course_num='101',
                 section_num='502', term_code='201931', min_credits='0',
                 honors=False, web=False, max_enrollment=25,
                 current_enrollment=11, instructor=cls.instructors[0]),
         Section(crn=36168, id='000005', subject='ASCC', course_num='101',
                 section_num='502', term_code='201831', min_credits='0',
                 honors=False, web=False, max_enrollment=25,
                 current_enrollment=17, instructor=cls.instructors[0]),
         Section(crn=27357, id='000006', subject='CSCE', course_num='310',
                 section_num='500', term_code='201911', min_credits='3',
                 honors=False, web=False, max_enrollment=59,
                 current_enrollment=59, instructor=cls.instructors[1]),
         Section(crn=24813, id='000007', subject='BIMS', course_num='110',
                 section_num='501', term_code='201831', min_credits='1',
                 honors=False, web=False, max_enrollment=100,
                 current_enrollment=101, instructor=cls.instructors[0]),
         Section(crn=24814, id='000008', subject='BIMS', course_num='110',
                 section_num='500', term_code='201911', min_credits='1',
                 honors=False, web=False, max_enrollment=100,
                 current_enrollment=100, instructor=cls.instructors[0]),
     ]
     cls.meetings = [
         Meeting(id='0000010', building='ZACH', meeting_days=[True] * 7,
                 start_time=time(11, 30), end_time=time(12, 20), meeting_type='LEC',
                 section=cls.sections[0]),
         Meeting(id='0000011', building='ZACH', meeting_days=[True] * 7,
                 start_time=time(9, 10), end_time=time(10), meeting_type='LEC',
                 section=cls.sections[0]),
         Meeting(id='0000020', building='ZACH', meeting_days=[True] * 7,
                 start_time=time(11, 30), end_time=time(12, 20), meeting_type='LEC',
                 section=cls.sections[1]),
         Meeting(id='0000021', building='ZACH', meeting_days=[False] * 7,
                 start_time=time(9, 10), end_time=time(10), meeting_type='LAB',
                 section=cls.sections[1]),
     ]
     cls.grades = [
         Grades(section_id='000003', gpa=3.0, A=0, B=1, C=0, D=0, F=0, I=0, S=0,
                U=0, Q=0, X=0),
         Grades(section_id='000004', gpa=4.0, A=1, B=0, C=0, D=0, F=0, I=0, S=0, U=0,
                Q=0, X=0),
         Grades(section_id='000005', gpa=2, A=0, B=0, C=1, D=0, F=0, I=0, S=0, U=0,
                Q=0, X=0),
         Grades(section_id='000006', gpa=1, A=0, B=0, C=0, D=0, F=0, I=0, S=0,
                U=0, Q=0, X=0),
         Grades(section_id='000007', gpa=3, A=1, B=0, C=1, D=0, F=0, I=0, S=0,
                U=0, Q=0, X=0),
         Grades(section_id='000008', gpa=2, A=0, B=0, C=1, D=0, F=0, I=0, S=0,
                U=0, Q=0, X=0),
     ]
     Course.objects.bulk_create(cls.courses)
     Section.objects.bulk_create(cls.sections)
     Meeting.objects.bulk_create(cls.meetings)
     Grades.objects.bulk_create(cls.grades)