Exemple #1
0
    def setUpTestData(cls):
        cls.client = APIClient()

        instructor = Instructor(id="name")
        instructor.save()
        cls.sections = [
            Section(id=1,
                    crn=1,
                    subject='CSCE',
                    course_num='121',
                    section_num='501',
                    term_code='201931',
                    min_credits=0,
                    honors=False,
                    remote=False,
                    current_enrollment=0,
                    max_enrollment=0,
                    instructor=instructor,
                    asynchronous=False),
            Section(id=2,
                    crn=2,
                    subject='CSCE',
                    course_num='221',
                    section_num='501',
                    term_code='201931',
                    min_credits=0,
                    honors=False,
                    remote=False,
                    current_enrollment=0,
                    max_enrollment=0,
                    instructor=instructor,
                    asynchronous=False),
        ]
        Section.objects.bulk_create(cls.sections)
 def setUpTestData(cls):
     instructor = Instructor(id="Akash Tyagi")
     instructor.save()
     cls.sections = [
         Section(crn=12345, id=1, 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=instructor),
         Section(crn=12346, id=2, 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=instructor),
         Section(crn=12347, id=3, subject='CSCE', course_num='310',
                 section_num='503', term_code='201911', min_credits='3',
                 honors=False, web=False, max_enrollment=50,
                 current_enrollment=40, instructor=instructor),
         Section(crn=12348, id=4, subject='CSCE', course_num='121',
                 section_num='501', term_code='201931', min_credits='3',
                 honors=False, web=False, max_enrollment=50,
                 current_enrollment=40, instructor=instructor),
         Section(crn=12349, id=5, subject='CSCE', course_num='121',
                 section_num='502', term_code='201931', min_credits='3',
                 honors=False, web=True, max_enrollment=50,
                 current_enrollment=50, instructor=instructor),
         Section(crn=12350, id=6, subject='CSCE', course_num='121',
                 section_num='201', term_code='201931', min_credits='3',
                 honors=True, web=False, max_enrollment=50,
                 current_enrollment=40, instructor=instructor),
     ]
     Section.objects.bulk_create(cls.sections)
    def setUpTestData(cls):
        term = "201911"

        instructor = Instructor(id="Name Name", email_address="*****@*****.**")
        instructor.save()

        cls.section = Section(id=1, subject="CSCE", course_num="121",
                              section_num="500", term_code=term, min_credits=0,
                              current_enrollment=0, max_enrollment=0,
                              instructor=instructor)

        cls.section.save()
    def test_parse_section_gets_instructional_method(self):
        """ Tests that parse_section correctly sets the instructional method.
            It can still error if the value is invalid, but this tests the value is set.
        """
        # Arrange
        fake_instructor = Instructor(id="Fake", email_address="[email protected]")
        fake_instructor.save()

        # Act
        section, _ = parse_section(self.acct_section_json, fake_instructor)
        section.save()

        # Assert
        # We don't care if it gets the other fields right
        Section.objects.get(instructional_method=Section.F2F)
    def test_parse_section_gets_not_asynchronous(self):
        """ Test that parse_section does not assign asynchronous=True when there are
            meetings with meeting times
        """
        # Arrange
        fake_instructor = Instructor(id="Fake", email_address="[email protected]")
        fake_instructor.save()

        # Act
        section, _ = parse_section(self.acct_section_json, fake_instructor)
        section.save()

        # Assert
        # We don't care if it gets the other fields right - just that it gets asynchronous
        Section.objects.get(asynchronous=False)
    def test_parse_course_fills_instructor_and_meeting(self):
        """ Tests if parse_course also adds an instructor and meeting to the database """

        # Arrange
        instructor_id = "John M. Moore"
        instructor_email = "*****@*****.**"
        instructor = Instructor(id=instructor_id,
                                email_address=instructor_email)

        meeting_id = 4972230
        crn = 12323
        building = "ZACH"
        begin_time = datetime.time(13, 50, 0)
        end_time = datetime.time(14, 40, 0)
        meeting_type = "LEC"
        meeting_days = [True, False, True, False, True, False, False]
        section = Section(id=497223,
                          subject="CSCE",
                          course_num=121,
                          section_num=501,
                          term_code=0,
                          crn=crn,
                          min_credits=0,
                          current_enrollment=0,
                          max_enrollment=0,
                          instructor=instructor,
                          asynchronous=False)

        #Act
        course, instructor, (section,
                             meetings) = parse_course(self.csce_section_json,
                                                      set(), set())
        instructor.save()
        section.save()
        Meeting.objects.bulk_create(meetings)
        course.save()

        # Assert
        Instructor.objects.get(id=instructor_id,
                               email_address=instructor_email)
        Meeting.objects.get(id=meeting_id,
                            building=building,
                            meeting_days=meeting_days,
                            start_time=begin_time,
                            end_time=end_time,
                            meeting_type=meeting_type,
                            section=section)
    def test_parse_meeting_does_save_model_correct(self):
        """ Tests if parse_meetings correctly saves the model to the database
            correctly
        """

        # Arrange
        meeting_id = 4972230
        crn = 12323
        building = "ZACH"
        begin_time = datetime.time(13, 50, 0)
        end_time = datetime.time(14, 40, 0)
        meeting_type = "LEC"
        meeting_days = [True, False, True, False, True, False, False]

        instructor = Instructor(id="First Last", email_address="[email protected]")
        instructor.save()

        # Course num is gonna be a character field
        section = Section(id=497223,
                          subject="CSCE",
                          course_num=121,
                          section_num=501,
                          term_code=0,
                          crn=crn,
                          min_credits=0,
                          current_enrollment=0,
                          max_enrollment=0,
                          instructor=instructor,
                          asynchronous=False)
        section.save()  # Must be saved for the assert query to work

        # Act
        meeting = parse_meeting(self.csce_section_json["meetingsFaculty"][0],
                                section, 0)
        meeting.save()

        # Assert
        # If parse_meeting doesn't save the model correctly, then this query
        # will throw an error, thus failing the test
        Meeting.objects.get(id=meeting_id,
                            building=building,
                            meeting_days=meeting_days,
                            start_time=begin_time,
                            end_time=end_time,
                            meeting_type=meeting_type,
                            section=section)
    def tests_parse_section_gets_asynchronous(self):
        """ Tests that parse_section correctly assigns asynchronous sections,
            which is a section where all of its meetings don't have meeting times
        """

        # Arrange
        fake_instructor = Instructor(id="Fake", email_address="[email protected]")
        fake_instructor.save()

        # Act
        section, _ = parse_section(self.csce_remote_section_json,
                                   fake_instructor)
        section.save()

        # Assert
        # We don't care if it gets the other fields right - just that it gets asynchronous
        Section.objects.get(asynchronous=True)
Exemple #9
0
    def test_parse_section_does_save_model(self):
        """ Tests if parse sections saves the model to the database correctly
            Does so by calling parse_section on the section_input, and queries for
            a Section with the expected attributes
        """

        # Arrange
        subject = "CSCE"
        course_num = "121"
        section_num = "501"
        term_code = 202011
        crn = 12323
        min_credits = 4
        max_enroll = curr_enroll = 22
        section_id = 497223

        # Section model requires an Instructor
        fake_instructor = Instructor(id="Fake", email_address="[email protected]")
        fake_instructor.save()

        # Act
        section, meetings = parse_section(self.csce_section_json,
                                          fake_instructor)
        section.save()
        Meeting.objects.bulk_create(meetings)

        # Assert

        # If this query fails then the section doesn't exist, and thus the section
        # model wasn't saved correctly

        Section.objects.get(id=section_id,
                            subject=subject,
                            course_num=course_num,
                            section_num=section_num,
                            term_code=term_code,
                            crn=crn,
                            current_enrollment=curr_enroll,
                            min_credits=min_credits,
                            max_enrollment=max_enroll,
                            instructor=fake_instructor)
Exemple #10
0
    def test_parse_section_does_save_multiple_meetings(self):
        """ Tests if parse_sections correctly creates both meetings for this section
            It does not test if the meetings that it saves are correct
        """

        # Arrange
        expected_num_meetings = 2

        fake_instructor = Instructor(id="Fake", email_address="[email protected]")
        fake_instructor.save()

        # Act
        section, meetings = parse_section(self.csce_section_json,
                                          fake_instructor)
        section.save()
        Meeting.objects.bulk_create(meetings)

        # Assert
        count = Meeting.objects.count()

        self.assertEqual(count, expected_num_meetings)
Exemple #11
0
def parse_instructor(course_data) -> Instructor:
    """ Parses the instructor data and saves it as a Instructor model.
        Called from parse_course.
    """

    # Can have multiple instructor entries, although most will have 0-1
    for faculty_data in course_data['faculty']:
        # We only care about the primary instructor, so skip all of the other ones
        if not faculty_data['primaryIndicator']:
            continue

        name = faculty_data.get("displayName")

        if name is None:
            return None

        email = faculty_data['emailAddress']

        return Instructor(id=name, email_address=email)

    return None
    def test_parse_section_gets_remote(self):
        """ Tests if parse_section correctly sets remote to True for an online course """

        # Arrange
        subject = "CSCE"
        course_num = "121"
        section_num = "M99"
        term_code = 201931
        crn = 40978
        min_credits = 4
        honors = False
        remote = True
        max_enroll = 10
        curr_enroll = 10
        section_id = 515269

        # Section model requires an Instructor
        fake_instructor = Instructor(id="Fake", email_address="[email protected]")
        fake_instructor.save()

        # Act
        section, _ = parse_section(self.csce_remote_section_json,
                                   fake_instructor)
        section.save()

        # Assert
        Section.objects.get(id=section_id,
                            subject=subject,
                            course_num=course_num,
                            section_num=section_num,
                            term_code=term_code,
                            crn=crn,
                            current_enrollment=curr_enroll,
                            min_credits=min_credits,
                            max_enrollment=max_enroll,
                            instructor=fake_instructor,
                            honors=honors,
                            remote=remote)
Exemple #13
0
    def test_parse_section_gets_honors(self):
        """ Tests if parse_section correctly sets honors to True for an honors course """

        # Arrange
        subject = "ACCT"
        course_num = "229"
        section_num = "202"
        term_code = 201931
        crn = 10004
        min_credits = 3
        honors = True
        web = False
        max_enroll = 0
        curr_enroll = 24
        section_id = 467471

        # Section model requires an Instructor
        fake_instructor = Instructor(id="Fake", email_address="[email protected]")
        fake_instructor.save()

        # Act
        section, _ = parse_section(self.acct_section_json, fake_instructor)
        section.save()

        # Assert
        Section.objects.get(id=section_id,
                            subject=subject,
                            course_num=course_num,
                            section_num=section_num,
                            term_code=term_code,
                            crn=crn,
                            current_enrollment=curr_enroll,
                            min_credits=min_credits,
                            max_enrollment=max_enroll,
                            instructor=fake_instructor,
                            honors=honors,
                            web=web)
Exemple #14
0
    def test_parse_section_handles_alphanumeric_section_num(self):
        """ Tests if parse_section accepts an alphanumeric section_num """

        # Arrange
        subject = "ENGL"
        course_num = "210"
        section_num = "M99"
        term_code = 202011
        crn = 36167
        min_credits = 3
        honors = False
        web = False
        max_enroll = 25
        curr_enroll = 3
        section_id = 511984

        # Section model requires an Instructor
        fake_instructor = Instructor(id="Fake", email_address="[email protected]")
        fake_instructor.save()

        # Act
        section, _ = parse_section(self.engl_section_json, fake_instructor)
        section.save()

        # Assert
        Section.objects.get(id=section_id,
                            subject=subject,
                            course_num=course_num,
                            section_num=section_num,
                            term_code=term_code,
                            crn=crn,
                            current_enrollment=curr_enroll,
                            min_credits=min_credits,
                            max_enrollment=max_enroll,
                            instructor=fake_instructor,
                            honors=honors,
                            web=web)
Exemple #15
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)
Exemple #16
0
 def setUpTestData(cls):
     instructor = Instructor(id="Akash Tyagi")
     instructor.save()
     cls.sections = [
         # Sections for CSCE 310
         Section(crn=12345,
                 id=1,
                 subject='CSCE',
                 course_num='310',
                 section_num='501',
                 term_code='201931',
                 min_credits='3',
                 honors=False,
                 remote=False,
                 max_enrollment=50,
                 asynchronous=False,
                 current_enrollment=40,
                 instructor=instructor),
         Section(crn=12346,
                 id=2,
                 subject='CSCE',
                 course_num='310',
                 section_num='502',
                 term_code='201931',
                 min_credits='3',
                 honors=False,
                 remote=False,
                 max_enrollment=50,
                 asynchronous=False,
                 current_enrollment=40,
                 instructor=instructor),
         Section(crn=12347,
                 id=3,
                 subject='CSCE',
                 course_num='310',
                 section_num='503',
                 term_code='201911',
                 min_credits='3',
                 honors=False,
                 remote=False,
                 max_enrollment=50,
                 asynchronous=False,
                 current_enrollment=40,
                 instructor=instructor),
         # Sections for CSCE 121
         Section(crn=12348,
                 id=4,
                 subject='CSCE',
                 course_num='121',
                 section_num='501',
                 term_code='201931',
                 min_credits='3',
                 honors=False,
                 remote=False,
                 max_enrollment=50,
                 asynchronous=False,
                 current_enrollment=40,
                 instructor=instructor),
         Section(crn=12349,
                 id=5,
                 subject='CSCE',
                 course_num='121',
                 section_num='502',
                 term_code='201931',
                 min_credits='3',
                 honors=False,
                 remote=True,
                 max_enrollment=50,
                 asynchronous=False,
                 current_enrollment=50,
                 instructor=instructor,
                 instructional_method=Section.F2F_REMOTE_OPTION),
         Section(crn=12350,
                 id=6,
                 subject='CSCE',
                 course_num='121',
                 section_num='201',
                 term_code='201931',
                 min_credits='3',
                 honors=True,
                 remote=False,
                 max_enrollment=50,
                 asynchronous=False,
                 current_enrollment=40,
                 instructor=instructor),
         Section(
             crn=12351,
             id=7,
             subject='CSCE',
             course_num='121',  # Async section
             section_num='M99',
             term_code='201931',
             min_credits='3',
             honors=False,
             remote=True,
             max_enrollment=50,
             asynchronous=True,
             current_enrollment=40,
             instructor=instructor),
         # Sections for CSCE 221 (note that none have available seats)
         Section(crn=12351,
                 id=8,
                 subject='CSCE',
                 course_num='221',
                 section_num='501',
                 term_code='201931',
                 min_credits='3',
                 honors=False,
                 remote=False,
                 max_enrollment=50,
                 asynchronous=False,
                 current_enrollment=50,
                 instructor=instructor),
     ]
     Section.objects.bulk_create(cls.sections)
 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)