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_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_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 test_conflicts_with_uses_period_conflict(self): period1 = PeriodFactory.build() period1.conflicts_with = Mock(return_value=False) period2 = PeriodFactory.build() sp1 = SectionPeriodFactory.build(period=period1) sp2 = SectionPeriodFactory.build(period=period2) self.assertFalse(sp1.conflicts_with(sp2)) period1.conflicts_with.assert_called_with(period2)
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_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_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_get_sections_by_semester(self): sem = SemesterFactory.create() s1, s2 = SectionPeriodFactory.create_batch(2, semester=sem) s3, s4 = SectionPeriodFactory.create_batch(2) json = self.json_get( 'v4:sections', get='?semester_id=%d' % sem.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_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_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_get_section_by_id(self): s1, s2 = SectionPeriodFactory.create_batch(2) json = self.json_get('v4:sections', id=s1.id, status_code=200) self.maxDiff = None self.assertEqual(json, { u"version": 4, u"success": True, u"result": self.to_dict(s1), })
def test_get_sections(self): s1, s2, s3, s4 = SectionPeriodFactory.create_batch(4) json = self.json_get('v4:sections', status_code=200) self.assertEqual(json, { u"version": 4, u"success": True, u"result": [ self.to_dict(s1), self.to_dict(s2), self.to_dict(s3), self.to_dict(s4), ] })
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_get_sections_by_crn(self): s1, s2, s3, s4 = SectionPeriodFactory.create_batch(4) json = self.json_get( 'v4:sections', get='?crn=%d&crn=%d' % (s1.section.crn, s3.section.crn), status_code=200) self.assertEqual(json, { u"version": 4, u"success": True, u"result": [ self.to_dict(s1), self.to_dict(s3), ] })
def test_to_json(self): period = PeriodFactory.create() period.toJSON = Mock(return_value={'lol': 1}) sp = SectionPeriodFactory.create( instructor='foo', location='bar', kind='fizz', period=period, ) expected = { 'instructor': 'foo', 'location': 'bar', 'kind': 'fizz', 'lol': 1, 'id': sp.id, } self.assertEqual(expected, sp.toJSON())