Beispiel #1
0
    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))
Beispiel #2
0
    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))
Beispiel #3
0
    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))
Beispiel #4
0
    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))
Beispiel #5
0
    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))
Beispiel #6
0
    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))
Beispiel #7
0
    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))
Beispiel #8
0
    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))
Beispiel #9
0
    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
Beispiel #10
0
    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
Beispiel #11
0
    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)
Beispiel #12
0
 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)
Beispiel #13
0
    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)
Beispiel #14
0
    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)
Beispiel #15
0
    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)
Beispiel #16
0
    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)
Beispiel #17
0
    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)
Beispiel #18
0
    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
Beispiel #19
0
 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),
         ]
     })
Beispiel #20
0
 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),
         ]
     })
Beispiel #21
0
 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)
Beispiel #22
0
 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),
         ]
     })
Beispiel #23
0
 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)
Beispiel #24
0
 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),
         ]
     })
Beispiel #25
0
    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
Beispiel #26
0
 def test_conflicts_with_self(self):
     section = SectionFactory.build()
     self.assertTrue(section.conflicts_with(section))
Beispiel #27
0
 def test_is_not_study_abroad(self):
     section = SectionFactory.build()
     self.assertFalse(section.is_study_abroad)
Beispiel #28
0
 def test_seats_left_should_never_be_negative(self):
     section = SectionFactory.build(seats_taken=7, seats_total=5)
     self.assertEqual(section.seats_left, 0)
Beispiel #29
0
 def test_seats_left(self):
     section = SectionFactory.build(seats_taken=4, seats_total=5)
     self.assertEqual(section.seats_left, 1)
Beispiel #30
0
 def test_is_full(self):
     section = SectionFactory.build(seats_taken=2, seats_total=2)
     self.assertTrue(section.is_full)
Beispiel #31
0
 def test_is_not_full(self):
     section = SectionFactory.build()
     self.assertFalse(section.is_full)
Beispiel #32
0
 def test_conflicts_with_using_cache(self):
     section1, section2 = SectionFactory.create(), SectionFactory.create()
     section1.conflicts = set([section2.id])
     self.assertTrue(section1.conflicts_with(section2))
Beispiel #33
0
 def test_conflicts_with_self(self):
     section = SectionFactory.build()
     self.assertTrue(section.conflicts_with(section))
Beispiel #34
0
 def test_seats_left_should_never_be_negative(self):
     section = SectionFactory.build(seats_taken=7, seats_total=5)
     self.assertEqual(section.seats_left, 0)
Beispiel #35
0
 def test_seats_left(self):
     section = SectionFactory.build(seats_taken=4, seats_total=5)
     self.assertEqual(section.seats_left, 1)
Beispiel #36
0
 def test_is_study_abroad(self):
     section = SectionFactory.build(number=models.Section.STUDY_ABROAD)
     self.assertTrue(section.is_study_abroad)
Beispiel #37
0
 def test_conflicts_with_using_cache(self):
     section1, section2 = SectionFactory.create(), SectionFactory.create()
     section1.conflicts = set([section2.id])
     self.assertTrue(section1.conflicts_with(section2))
Beispiel #38
0
 def test_is_not_full(self):
     section = SectionFactory.build()
     self.assertFalse(section.is_full)
Beispiel #39
0
 def test_no_conflicts_using_cache(self):
     section1, section2 = SectionFactory.create(), SectionFactory.create()
     section1.conflicts = set()
     self.assertFalse(section1.conflicts_with(section2))
Beispiel #40
0
 def test_is_full(self):
     section = SectionFactory.build(seats_taken=2, seats_total=2)
     self.assertTrue(section.is_full)
Beispiel #41
0
 def test_is_not_study_abroad(self):
     section = SectionFactory.build()
     self.assertFalse(section.is_study_abroad)
Beispiel #42
0
 def test_is_study_abroad(self):
     section = SectionFactory.build(number=models.Section.STUDY_ABROAD)
     self.assertTrue(section.is_study_abroad)
Beispiel #43
0
 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)
Beispiel #44
0
 def test_no_conflicts_using_cache(self):
     section1, section2 = SectionFactory.create(), SectionFactory.create()
     section1.conflicts = set()
     self.assertFalse(section1.conflicts_with(section2))