def test_crns(self): course = CourseFactory.create() section1 = SectionFactory.create(crn=123, course=course) section2 = SectionFactory.create(crn=124, course=course) SectionPeriodFactory.create(section=section1) SectionPeriodFactory.create(section=section2) self.assertEqual([123, 124], list(course.crns))
def test_conflicts_with_section_with_conflicting_periods(self): def period(): m = Mock() m.conflicts_with = Mock(return_value=True) return m section1, section2 = SectionFactory.create(), SectionFactory.create() section1.get_periods = Mock(return_value=[period()]) section2.get_periods = Mock(return_value=[period()]) self.assertTrue(section1.conflicts_with(section2))
def test_full_crns(self): course = CourseFactory.create() section1 = SectionFactory.create( crn=123, course=course, seats_total=1, seats_taken=0) section2 = SectionFactory.create( crn=124, course=course, seats_total=1, seats_taken=5) SectionPeriodFactory.create(section=section1) SectionPeriodFactory.create(section=section2) self.assertEqual([124], list(course.full_crns))
def test_kinds(self): course = CourseFactory.create() section1 = SectionFactory.create(crn=123, course=course) section2 = SectionFactory.create(crn=124, course=course, seats_total=1) SectionPeriodFactory.create(section=section1, kind='foo') SectionPeriodFactory.create(section=section1, kind='foobar') SectionPeriodFactory.create(section=section1, kind='fizzbuzz') SectionPeriodFactory.create(section=section2, kind='fizz') self.assertEqual(set(['foo', 'foobar', 'fizzbuzz', 'fizz']), set(course.kinds))
def test_full_crns(self): course = CourseFactory.create() section1 = SectionFactory.create(crn=123, course=course, seats_total=1, seats_taken=0) section2 = SectionFactory.create(crn=124, course=course, seats_total=1, seats_taken=5) SectionPeriodFactory.create(section=section1) SectionPeriodFactory.create(section=section2) self.assertEqual([124], list(course.full_crns))
def setUp(self): semester = SemesterFactory.create(year=2011, month=1) course = CourseFactory.create(pk=2) OfferedForFactory.create(semester=semester, course=course) section = SectionFactory.create(number=1, course=course, semester=semester) sa_section = SectionFactory.create(number=models.Section.STUDY_ABROAD, course=course, semester=semester) crn_section = SectionFactory.create(crn=13337, course=course, semester=semester) cs_dept = DepartmentFactory.create(code='CSCI') SemesterDepartmentFactory.create(semester=semester, department=cs_dept) ecse_dept = DepartmentFactory.create(code='ECSE') SemesterDepartmentFactory.create(semester=semester, department=ecse_dept) self.semester, self.course, self.cs_dept, self.ecse_dept = semester, course, cs_dept, ecse_dept
def setUp(self): super(SearchTest, self).setUp() course = CourseFactory.create(department=self.cs_dept, number=4230, name='Intro to Computing') OfferedForFactory.create(course=course, semester=self.semester) course2 = CourseFactory.create(department=self.cs_dept, number=4231, name='Skynet 101') OfferedForFactory.create(course=course2, semester=self.semester) # another department course3 = CourseFactory.create(department=self.ecse_dept, number=4230, name='Imaginary Power') OfferedForFactory.create(course=course3, semester=self.semester) section = SectionFactory.create(course=course, semester=self.semester) period = PeriodFactory.create(start=datetime.time(hour=12), end=datetime.time(hour=13), days_of_week_flag=1) SectionPeriodFactory.create(section=section, period=period, instructor='Moorthy', semester=self.semester) self.course1, self.course2, self.course3 = course, course2, course3
def test_saving_and_loading(self): course1 = CourseFactory.create() course2 = CourseFactory.create() section1 = SectionFactory.create(course=course1) section2 = SectionFactory.create(course=course1) section3 = SectionFactory.create(course=course2) json = self.json_post('v4:saved-selections', data={ 'section_ids': ','.join([ str(section1.id), str(section2.id), str(section3.id), ]), 'blocked_times': ','.join( ['Wednesday_12:0:0', 'Thursday_14:0:0']) }, status_code=200) selection = SavedSelection.objects.all()[0] expected_json = { u"version": 4, u"success": True, u"result": { u'id': selection.id, u'selection': { unicode(course1.id): [ section1.id, section2.id, ], unicode(course2.id): [section3.id] }, u'blocked_times': [ u'Thursday_14:0:0', u'Wednesday_12:0:0', ] } } self.assertEqual(json, expected_json) json = self.json_post('v4:saved-selection', id=selection.id, status_code=200) self.assertEqual(json, expected_json)
def test_ics(self): # FIXME: remove http request dependency semester = SemesterFactory.create(year=2012, month=9) sections = SectionFactory.create_batch(3, semester=semester) crns = [str(s.crn) for s in sections] response = self.get('ics', get='?crn=' + '&crn='.join(crns), status_code=200)
def test_days_of_week(self): section = SectionFactory.create() period1 = PeriodFactory.create(days_of_week_flag=models.Period.TUESDAY) period2 = PeriodFactory.create(days_of_week_flag=models.Period.MONDAY) SectionPeriodFactory.create(period=period1, section=section) SectionPeriodFactory.create(period=period2, section=section) expected = ['Monday', 'Tuesday'] self.assertEqual(expected, section.days_of_week)
def setUp(self): self.sem = SemesterFactory.create(year=2011, month=1) self.dept = DepartmentFactory.create(code='CSCI') SemesterDepartmentFactory.create(department=self.dept, semester=self.sem) self.course = CourseFactory.create(number=2222, department=self.dept) OfferedForFactory.create(course=self.course, semester=self.sem) self.section = SectionFactory.create(course=self.course, semester=self.sem) SectionPeriodFactory.create(section=self.section)
def test_saving_and_loading(self): course1 = CourseFactory.create() course2 = CourseFactory.create() section1 = SectionFactory.create(course=course1) section2 = SectionFactory.create(course=course1) section3 = SectionFactory.create(course=course2) json = self.json_post('v4:saved-selections', data={ 'section_ids': ','.join([ str(section1.id), str(section2.id), str(section3.id), ]), 'blocked_times': ','.join(['Wednesday_12:0:0', 'Thursday_14:0:0']) }, status_code=200) selection = SavedSelection.objects.all()[0] expected_json = { u"version": 4, u"success": True, u"result": { u'id': selection.id, u'selection': { unicode(course1.id): [ section1.id, section2.id, ], unicode(course2.id): [ section3.id ] }, u'blocked_times': [ u'Thursday_14:0:0', u'Wednesday_12:0:0', ] } } self.assertEqual(json, expected_json) json = self.json_post('v4:saved-selection', id=selection.id, status_code=200) self.assertEqual(json, expected_json)
def test_search_instructor(self): c1, c2 = CourseFactory.create_batch(2) c3 = CourseFactory.create() sec = SectionFactory.create(course=c3) sp = SectionPeriodFactory.create(section=sec, instructor='Moorthy') json = self.json_get('v4:courses', get='?search=moor', status_code=200) self.maxDiff = None self.assertEqual(json, { u"version": 4, u"success": True, u"result": [ self.to_dict(c3), ] })
def test_to_json(self): section = SectionFactory.create( number=1, crn=2, seats_taken=3, seats_total=4 ) expected = { 'number': 1, 'crn': 2, 'periods': [], 'seats_taken': 3, 'seats_total': 4, 'seats_left': 1, 'notes': [], } result = section.toJSON() self.assertEqual(expected, result)
def test_get_sections_by_course(self): c1 = CourseFactory.create() sec1, sec2 = SectionFactory.create_batch(2, course=c1) s1 = SectionPeriodFactory.create(section=sec1) s2 = SectionPeriodFactory.create(section=sec2) s3, s4 = SectionPeriodFactory.create_batch(2) json = self.json_get( 'v4:sections', get='?course_id=%d' % c1.id, status_code=200) self.assertEqual(json, { u"version": 4, u"success": True, u"result": [ self.to_dict(s1), self.to_dict(s2), ] })
def test_to_json(self): section = SectionFactory.create(number=1, crn=2, seats_taken=3, seats_total=4) expected = { 'number': 1, 'crn': 2, 'periods': [], 'seats_taken': 3, 'seats_total': 4, 'seats_left': 1, 'notes': [], } result = section.toJSON() self.assertEqual(expected, result)
def test_conflicts_with_self(self): section = SectionFactory.build() self.assertTrue(section.conflicts_with(section))
def test_is_not_study_abroad(self): section = SectionFactory.build() self.assertFalse(section.is_study_abroad)
def test_seats_left_should_never_be_negative(self): section = SectionFactory.build(seats_taken=7, seats_total=5) self.assertEqual(section.seats_left, 0)
def test_seats_left(self): section = SectionFactory.build(seats_taken=4, seats_total=5) self.assertEqual(section.seats_left, 1)
def test_is_full(self): section = SectionFactory.build(seats_taken=2, seats_total=2) self.assertTrue(section.is_full)
def test_is_not_full(self): section = SectionFactory.build() self.assertFalse(section.is_full)
def test_conflicts_with_using_cache(self): section1, section2 = SectionFactory.create(), SectionFactory.create() section1.conflicts = set([section2.id]) self.assertTrue(section1.conflicts_with(section2))
def test_is_study_abroad(self): section = SectionFactory.build(number=models.Section.STUDY_ABROAD) self.assertTrue(section.is_study_abroad)
def test_no_conflicts_using_cache(self): section1, section2 = SectionFactory.create(), SectionFactory.create() section1.conflicts = set() self.assertFalse(section1.conflicts_with(section2))