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): 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): 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)
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)
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)
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)
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)
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)
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)
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)