Beispiel #1
0
 def setUp(self):
     self.dept_cs = Department(long_name="Computer Science", short_name="CS", abbreviation="COMPSCI")
     self.dept_cs.save()
     self.dept_ee = Department(long_name="Electrical Engineering", short_name="EE", abbreviation="EL ENG")
     self.dept_ee.save()
     self.course_cs_1 = Course(department=self.dept_cs, number="1")
     self.course_cs_1.save()
     self.course_ee_1 = Course(department=self.dept_ee, number="1")
     self.course_ee_1.save()
     self.instructor_cs = Instructor(first_name="Tau", last_name="Bate", department=self.dept_cs)
     self.instructor_cs.save()
     self.instructor_ee = Instructor(first_name="Pi", last_name="Bent", department=self.dept_ee)
     self.instructor_ee.save()
     self.term = Term(term="sp", year=2013, current=True)
     self.term.save()
     self.course_instance_cs_1 = CourseInstance(term=self.term, course=self.course_cs_1)
     self.course_instance_cs_1.save()
     self.course_instance_cs_1.instructors.add(self.instructor_cs)
     self.course_instance_cs_1.save()
     self.course_instance_ee_1 = CourseInstance(term=self.term, course=self.course_ee_1)
     self.course_instance_ee_1.save()
     self.course_instance_ee_1.instructors.add(self.instructor_ee)
     self.course_instance_ee_1.save()
     self.user = get_user_model().objects.create_user(
         username="******", email="tbp.berkeley.edu", password="******", first_name="tbp", last_name="user"
     )
     self.user.save()
     self.survey_cs_1 = Survey(
         course=self.course_cs_1,
         term=self.term,
         instructor=self.instructor_cs,
         prof_rating=5,
         course_rating=5,
         time_commitment=5,
         comments="Test comments",
         submitter=self.user,
         published=True,
     )
     self.survey_cs_1.save()
     self.survey_cs_1_b = Survey(
         course=self.course_cs_1,
         term=self.term,
         instructor=self.instructor_cs,
         prof_rating=0,
         course_rating=5,
         time_commitment=0,
         comments="Test comments",
         submitter=self.user,
         published=True,
     )
     self.survey_cs_1_b.save()
     self.exam_ee_1 = Exam(
         course_instance=self.course_instance_ee_1,
         submitter=self.user,
         exam_number=Exam.FINAL,
         exam_type=Exam.EXAM,
         file_ext=".pdf",
         verified=True,
     )
     self.exam_ee_1.save()
Beispiel #2
0
 def setUp(self):
     self.department_cs = Department(long_name='Computer Science',
                                     short_name='CS',
                                     abbreviation='COMP SCI')
     self.department_cs.save()
     self.department_me = Department(long_name='Mechanical Engineering',
                                     short_name='ME',
                                     abbreviation='MEC ENG')
     self.department_me.save()
     self.course_cs1 = Course(department=self.department_cs, number='1')
     self.course_cs1.save()
     self.course_me50 = Course(department=self.department_me, number='50')
     self.course_me50.save()
     self.instructor_test = Instructor(first_name='Tau',
                                       last_name='Bate',
                                       department=self.department_cs)
     self.instructor_test.save()
     self.term_test = Term(term=Term.SPRING, year=2013, current=True)
     self.term_test.save()
     self.user_test = get_user_model().objects.create_user(
         username='******',
         email='tbp.berkeley.edu',
         password='******',
         first_name='Tau',
         last_name='Bate')
     self.user_test.save()
Beispiel #3
0
    def setUp(self):
        self.test_exam1 = make_test_exam(10000)
        self.test_exam2 = make_test_exam(20000)
        self.test_exam3 = make_test_exam(30000)

        self.permission1 = InstructorPermission.objects.get(pk=100000)
        self.permission2 = InstructorPermission.objects.get(pk=200000)
        self.permission3 = InstructorPermission.objects.get(pk=300000)

        self.dept_cs = Department(long_name='Computer Science',
                                  short_name='CS',
                                  abbreviation='COMPSCI')
        self.dept_cs.save()
        self.course_cs_1 = Course(department=self.dept_cs, number='1')
        self.course_cs_1.save()
        self.instructor_cs = Instructor(first_name='Tau',
                                        last_name='Bate',
                                        department=self.dept_cs)
        self.instructor_cs.save()
        self.term = Term(term='sp', year=2016, current=True)
        self.term.save()
        self.course_instance_cs_1 = CourseInstance(term=self.term,
                                                   course=self.course_cs_1)
        self.course_instance_cs_1.save()
        self.course_instance_cs_1.instructors.add(self.instructor_cs)
        self.course_instance_cs_1.save()

        self.permission4 = InstructorPermission(instructor=self.instructor_cs,
                                                permission_allowed=True)
        self.permission4.save()
Beispiel #4
0
class SurveyFormTest(TestCase):
    def setUp(self):
        self.department_cs = Department(long_name='Computer Science',
                                        short_name='CS',
                                        abbreviation='COMP SCI')
        self.department_cs.save()
        self.department_me = Department(long_name='Mechanical Engineering',
                                        short_name='ME',
                                        abbreviation='MEC ENG')
        self.department_me.save()
        self.course_cs1 = Course(department=self.department_cs, number='1')
        self.course_cs1.save()
        self.course_me50 = Course(department=self.department_me, number='50')
        self.course_me50.save()
        self.instructor_test = Instructor(first_name='Tau',
                                          last_name='Bate',
                                          department=self.department_cs)
        self.instructor_test.save()
        self.term_test = Term(term=Term.SPRING, year=2013, current=True)
        self.term_test.save()
        self.user_test = get_user_model().objects.create_user(
            username='******',
            email='tbp.berkeley.edu',
            password='******',
            first_name='Tau',
            last_name='Bate')
        self.user_test.save()

    def test_courses_as_optgroups(self):
        optgroups = courses_as_optgroups()
        # optgrous[i] returns [dept.long_name, list of courses in dept]
        # optgroups[i][1] returns a list of tuples in the form of
        # (Course, Course.abbreviation())
        self.assertEqual(optgroups[0][0], self.department_cs.long_name)
        self.assertEqual(optgroups[1][1][0][0], self.course_me50)

    def test_valid_form(self):
        test_form = SurveyForm()
        self.assertFalse(test_form.is_valid())
        form_data = {
            'course': self.course_me50.pk,
            'term': self.term_test.pk,
            'instructor': self.instructor_test.pk,
            'prof_rating': 1,
            'course_rating': 2,
            'time_commitment': 3,
            'comments': 'Test Comment',
            'submitter': self.user_test.pk
        }
        test_form = SurveyForm(form_data)
        self.assertTrue(test_form.is_valid())
Beispiel #5
0
 def setUp(self):
     self.department_cs = Department(
         long_name='Computer Science',
         short_name='CS',
         abbreviation='COMP SCI')
     self.department_cs.save()
     self.department_me = Department(
         long_name='Mechanical Engineering',
         short_name='ME',
         abbreviation='MEC ENG')
     self.department_me.save()
     self.course_cs1 = Course(
         department=self.department_cs,
         number='1')
     self.course_cs1.save()
     self.course_me50 = Course(
         department=self.department_me,
         number='50')
     self.course_me50.save()
     self.instructor_test = Instructor(
         first_name='Tau',
         last_name='Bate',
         department=self.department_cs)
     self.instructor_test.save()
     self.term_test = Term(
         term=Term.SPRING,
         year=2013,
         current=True)
     self.term_test.save()
     self.user_test = get_user_model().objects.create_user(
         username='******',
         email='tbp.berkeley.edu',
         password='******',
         first_name='Tau',
         last_name='Bate')
     self.user_test.save()
Beispiel #6
0
 def setUp(self):
     self.test_department = make_test_department()
     self.test_department_2 = Department(
         long_name="Test Department 2", short_name="Tst Dep 2", abbreviation="TEST DEPT 2"
     )
     self.test_department_2.save()
     self.test_course_1 = Course(department=self.test_department, number="61a", title="TestDept1 61a")
     self.test_course_1.save()
     self.test_course_2 = Course(department=self.test_department, number="h61a", title="Honors TestDept1 61a")
     self.test_course_2.save()
     self.test_course_3 = Course(department=self.test_department, number="61b", title="TestDept1 61b")
     self.test_course_3.save()
     self.test_course_4 = Course(department=self.test_department, number="70", title="TestDept1 70")
     self.test_course_4.save()
     self.test_course_5 = Course(department=self.test_department_2, number="C30", title="TestDept2 C30")
     self.test_course_5.save()
     self.test_course_6 = Course(department=self.test_department_2, number="70", title="TestDept2 70")
     self.test_course_6.save()
     self.test_course_7 = Course(department=self.test_department_2, number="130AC", title="TestDept2 130AC")
     self.test_course_7.save()
     self.test_course_8 = Course(department=self.test_department_2, number="C130AC", title="TestDept2 C130AC")
     self.test_course_8.save()
     self.test_course_9 = Course(department=self.test_department_2, number="H130AC", title="TestDept2 Honors 130AC")
     self.test_course_9.save()
Beispiel #7
0
 def setUp(self):
     self.dept_cs = Department(long_name='Computer Science',
                               short_name='CS',
                               abbreviation='COMPSCI')
     self.dept_cs.save()
     self.dept_ee = Department(long_name='Electrical Engineering',
                               short_name='EE',
                               abbreviation='EL ENG')
     self.dept_ee.save()
     self.course_cs_1 = Course(department=self.dept_cs, number='1')
     self.course_cs_1.save()
     self.course_ee_1 = Course(department=self.dept_ee, number='1')
     self.course_ee_1.save()
     self.instructor_cs = Instructor(first_name='Tau',
                                     last_name='Bate',
                                     department=self.dept_cs)
     self.instructor_cs.save()
     self.instructor_ee = Instructor(first_name='Pi',
                                     last_name='Bent',
                                     department=self.dept_ee)
     self.instructor_ee.save()
     self.term = Term(term='sp', year=2013, current=True)
     self.term.save()
     self.course_instance_cs_1 = CourseInstance(term=self.term,
                                                course=self.course_cs_1)
     self.course_instance_cs_1.save()
     self.course_instance_cs_1.instructors.add(self.instructor_cs)
     self.course_instance_cs_1.save()
     self.course_instance_ee_1 = CourseInstance(term=self.term,
                                                course=self.course_ee_1)
     self.course_instance_ee_1.save()
     self.course_instance_ee_1.instructors.add(self.instructor_ee)
     self.course_instance_ee_1.save()
     self.user = get_user_model().objects.create_user(
         username='******',
         email='tbp.berkeley.edu',
         password='******',
         first_name='tbp',
         last_name='user')
     self.user.save()
     self.survey_cs_1 = Survey(course=self.course_cs_1,
                               term=self.term,
                               instructor=self.instructor_cs,
                               prof_rating=5,
                               course_rating=5,
                               time_commitment=5,
                               comments='Test comments',
                               submitter=self.user,
                               published=True)
     self.survey_cs_1.save()
     self.survey_cs_1_b = Survey(course=self.course_cs_1,
                                 term=self.term,
                                 instructor=self.instructor_cs,
                                 prof_rating=0,
                                 course_rating=5,
                                 time_commitment=0,
                                 comments='Test comments',
                                 submitter=self.user,
                                 published=True)
     self.survey_cs_1_b.save()
     self.exam_ee_1 = Exam(course_instance=self.course_instance_ee_1,
                           submitter=self.user,
                           exam_number=Exam.FINAL,
                           exam_type=Exam.EXAM,
                           file_ext='.pdf',
                           verified=True)
     self.exam_ee_1.save()
Beispiel #8
0
 def setUp(self):
     self.test_department = make_test_department()
     self.test_department_2 = Department(long_name='Test Department 2',
                                         short_name='Tst Dep 2',
                                         abbreviation='TEST DEPT 2')
     self.test_department_2.save()
     self.test_course_1 = Course(department=self.test_department,
                                 number='61a',
                                 title='TestDept1 61a')
     self.test_course_1.save()
     self.test_course_2 = Course(department=self.test_department,
                                 number='h61a',
                                 title='Honors TestDept1 61a')
     self.test_course_2.save()
     self.test_course_3 = Course(department=self.test_department,
                                 number='61b',
                                 title='TestDept1 61b')
     self.test_course_3.save()
     self.test_course_4 = Course(department=self.test_department,
                                 number='70',
                                 title='TestDept1 70')
     self.test_course_4.save()
     self.test_course_5 = Course(department=self.test_department_2,
                                 number='C30',
                                 title='TestDept2 C30')
     self.test_course_5.save()
     self.test_course_6 = Course(department=self.test_department_2,
                                 number='70',
                                 title='TestDept2 70')
     self.test_course_6.save()
     self.test_course_7 = Course(department=self.test_department_2,
                                 number='130AC',
                                 title='TestDept2 130AC')
     self.test_course_7.save()
     self.test_course_8 = Course(department=self.test_department_2,
                                 number='C130AC',
                                 title='TestDept2 C130AC')
     self.test_course_8.save()
     self.test_course_9 = Course(department=self.test_department_2,
                                 number='H130AC',
                                 title='TestDept2 Honors 130AC')
     self.test_course_9.save()
Beispiel #9
0
class CourseTest(TestCase):
    def setUp(self):
        self.test_department = make_test_department()
        self.test_department_2 = Department(long_name='Test Department 2',
                                            short_name='Tst Dep 2',
                                            abbreviation='TEST DEPT 2')
        self.test_department_2.save()
        self.test_course_1 = Course(department=self.test_department,
                                    number='61a',
                                    title='TestDept1 61a')
        self.test_course_1.save()
        self.test_course_2 = Course(department=self.test_department,
                                    number='h61a',
                                    title='Honors TestDept1 61a')
        self.test_course_2.save()
        self.test_course_3 = Course(department=self.test_department,
                                    number='61b',
                                    title='TestDept1 61b')
        self.test_course_3.save()
        self.test_course_4 = Course(department=self.test_department,
                                    number='70',
                                    title='TestDept1 70')
        self.test_course_4.save()
        self.test_course_5 = Course(department=self.test_department_2,
                                    number='C30',
                                    title='TestDept2 C30')
        self.test_course_5.save()
        self.test_course_6 = Course(department=self.test_department_2,
                                    number='70',
                                    title='TestDept2 70')
        self.test_course_6.save()
        self.test_course_7 = Course(department=self.test_department_2,
                                    number='130AC',
                                    title='TestDept2 130AC')
        self.test_course_7.save()
        self.test_course_8 = Course(department=self.test_department_2,
                                    number='C130AC',
                                    title='TestDept2 C130AC')
        self.test_course_8.save()
        self.test_course_9 = Course(department=self.test_department_2,
                                    number='H130AC',
                                    title='TestDept2 Honors 130AC')
        self.test_course_9.save()

    def tearDown(self):
        self.test_department.full_clean()

    def test_save(self):
        self.assertEquals(self.test_course_2.number, 'H61A')

    def test_abbreviation(self):
        self.assertEquals(self.test_course_2.abbreviation(), 'Tst Dep 1 H61A')

    def test_get_display_name(self):
        self.assertEquals(self.test_course_2.get_display_name(),
                          'Test Department 1 H61A')

    def test_lessthan(self):
        self.assertFalse(self.test_course_1 < self.test_course_1)
        self.assertTrue(self.test_course_1 < self.test_course_2)
        self.assertTrue(self.test_course_1 < self.test_course_3)
        self.assertTrue(self.test_course_1 < self.test_course_4)
        self.assertTrue(self.test_course_1 < self.test_course_5)
        self.assertTrue(self.test_course_1 < self.test_course_6)
        self.assertTrue(self.test_course_2 < self.test_course_3)
        self.assertTrue(self.test_course_2 < self.test_course_4)
        self.assertTrue(self.test_course_4 < self.test_course_5)
        self.assertTrue(self.test_course_4 < self.test_course_6)
        self.assertTrue(self.test_course_4 < self.test_course_7)
        self.assertTrue(self.test_course_4 < self.test_course_8)
        self.assertTrue(self.test_course_7 < self.test_course_8)
        self.assertTrue(self.test_course_7 < self.test_course_9)
        self.assertTrue(self.test_course_8 < self.test_course_9)
        self.assertFalse(self.test_course_1 < self.test_department)

    def test_equals(self):
        self.assertTrue(self.test_course_1 == self.test_course_1)
        self.assertFalse(self.test_course_4 == self.test_course_6)
        self.assertFalse(self.test_course_7 == self.test_course_8)
        self.assertFalse(self.test_course_8 == self.test_course_9)
        self.assertFalse(self.test_course_1 == self.test_department)

    def test_other_comparison_methods(self):
        self.assertTrue(self.test_course_2 <= self.test_course_2)
        self.assertTrue(self.test_course_2 <= self.test_course_3)
        self.assertTrue(self.test_course_2 != self.test_course_3)
        self.assertTrue(self.test_course_4 > self.test_course_1)
        self.assertTrue(self.test_course_4 >= self.test_course_4)
        self.assertTrue(self.test_course_4 >= self.test_course_3)
        self.assertFalse(self.test_course_1 <= self.test_department)
        self.assertFalse(self.test_course_1 > self.test_department)
        self.assertFalse(self.test_course_1 >= self.test_department)
        self.assertTrue(self.test_course_1 != self.test_department)

    def test_sort(self):
        sorted_list = [
            self.test_course_1, self.test_course_2, self.test_course_3,
            self.test_course_4, self.test_course_5, self.test_course_6,
            self.test_course_7, self.test_course_8, self.test_course_9
        ]
        test_list = [
            self.test_course_1, self.test_course_3, self.test_course_5,
            self.test_course_7, self.test_course_9, self.test_course_4,
            self.test_course_6, self.test_course_8, self.test_course_2
        ]
        self.assertNotEqual(test_list, sorted_list)
        test_list.sort()
        # Correct ordering:
        # TD1 61A, TD1 H61A, TD1 61B, TD1 70, TD2 C30,
        # TD2 70, TD2 130AC, TD2 C130AC, TD2 H130AC
        self.assertEquals(test_list, sorted_list)
Beispiel #10
0
class SurveyFormTest(TestCase):
    def setUp(self):
        self.department_cs = Department(
            long_name='Computer Science',
            short_name='CS',
            abbreviation='COMP SCI')
        self.department_cs.save()
        self.department_me = Department(
            long_name='Mechanical Engineering',
            short_name='ME',
            abbreviation='MEC ENG')
        self.department_me.save()
        self.course_cs1 = Course(
            department=self.department_cs,
            number='1')
        self.course_cs1.save()
        self.course_me50 = Course(
            department=self.department_me,
            number='50')
        self.course_me50.save()
        self.instructor_test = Instructor(
            first_name='Tau',
            last_name='Bate',
            department=self.department_cs)
        self.instructor_test.save()
        self.term_test = Term(
            term=Term.SPRING,
            year=2013,
            current=True)
        self.term_test.save()
        self.user_test = get_user_model().objects.create_user(
            username='******',
            email='tbp.berkeley.edu',
            password='******',
            first_name='Tau',
            last_name='Bate')
        self.user_test.save()

    def test_courses_as_optgroups(self):
        optgroups = courses_as_optgroups()
        # optgrous[i] returns [dept.long_name, list of courses in dept]
        # optgroups[i][1] returns a list of tuples in the form of
        # (Course, Course.abbreviation())
        self.assertEqual(optgroups[0][0], self.department_cs.long_name)
        self.assertEqual(optgroups[1][1][0][0], self.course_me50)

    def test_valid_form(self):
        test_form = SurveyForm()
        self.assertFalse(test_form.is_valid())
        form_data = {
            'course': self.course_me50.pk,
            'term': self.term_test.pk,
            'instructor': self.instructor_test.pk,
            'prof_rating': 1,
            'course_rating': 2,
            'time_commitment': 3,
            'comments': 'Test Comment',
            'submitter': self.user_test.pk
        }
        test_form = SurveyForm(form_data)
        self.assertTrue(test_form.is_valid())
Beispiel #11
0
class CourseTest(TestCase):
    def setUp(self):
        self.test_department = make_test_department()
        self.test_department_2 = Department(
            long_name="Test Department 2", short_name="Tst Dep 2", abbreviation="TEST DEPT 2"
        )
        self.test_department_2.save()
        self.test_course_1 = Course(department=self.test_department, number="61a", title="TestDept1 61a")
        self.test_course_1.save()
        self.test_course_2 = Course(department=self.test_department, number="h61a", title="Honors TestDept1 61a")
        self.test_course_2.save()
        self.test_course_3 = Course(department=self.test_department, number="61b", title="TestDept1 61b")
        self.test_course_3.save()
        self.test_course_4 = Course(department=self.test_department, number="70", title="TestDept1 70")
        self.test_course_4.save()
        self.test_course_5 = Course(department=self.test_department_2, number="C30", title="TestDept2 C30")
        self.test_course_5.save()
        self.test_course_6 = Course(department=self.test_department_2, number="70", title="TestDept2 70")
        self.test_course_6.save()
        self.test_course_7 = Course(department=self.test_department_2, number="130AC", title="TestDept2 130AC")
        self.test_course_7.save()
        self.test_course_8 = Course(department=self.test_department_2, number="C130AC", title="TestDept2 C130AC")
        self.test_course_8.save()
        self.test_course_9 = Course(department=self.test_department_2, number="H130AC", title="TestDept2 Honors 130AC")
        self.test_course_9.save()

    def tearDown(self):
        self.test_department.full_clean()

    def test_save(self):
        self.assertEquals(self.test_course_2.number, "H61A")

    def test_abbreviation(self):
        self.assertEquals(self.test_course_2.abbreviation(), "Tst Dep 1 H61A")

    def test_get_display_name(self):
        self.assertEquals(self.test_course_2.get_display_name(), "Test Department 1 H61A")

    def test_lessthan(self):
        self.assertFalse(self.test_course_1 < self.test_course_1)
        self.assertTrue(self.test_course_1 < self.test_course_2)
        self.assertTrue(self.test_course_1 < self.test_course_3)
        self.assertTrue(self.test_course_1 < self.test_course_4)
        self.assertTrue(self.test_course_1 < self.test_course_5)
        self.assertTrue(self.test_course_1 < self.test_course_6)
        self.assertTrue(self.test_course_2 < self.test_course_3)
        self.assertTrue(self.test_course_2 < self.test_course_4)
        self.assertTrue(self.test_course_4 < self.test_course_5)
        self.assertTrue(self.test_course_4 < self.test_course_6)
        self.assertTrue(self.test_course_4 < self.test_course_7)
        self.assertTrue(self.test_course_4 < self.test_course_8)
        self.assertTrue(self.test_course_7 < self.test_course_8)
        self.assertTrue(self.test_course_7 < self.test_course_9)
        self.assertTrue(self.test_course_8 < self.test_course_9)
        self.assertFalse(self.test_course_1 < self.test_department)

    def test_equals(self):
        self.assertTrue(self.test_course_1 == self.test_course_1)
        self.assertFalse(self.test_course_4 == self.test_course_6)
        self.assertFalse(self.test_course_7 == self.test_course_8)
        self.assertFalse(self.test_course_8 == self.test_course_9)
        self.assertFalse(self.test_course_1 == self.test_department)

    def test_other_comparison_methods(self):
        self.assertTrue(self.test_course_2 <= self.test_course_2)
        self.assertTrue(self.test_course_2 <= self.test_course_3)
        self.assertTrue(self.test_course_2 != self.test_course_3)
        self.assertTrue(self.test_course_4 > self.test_course_1)
        self.assertTrue(self.test_course_4 >= self.test_course_4)
        self.assertTrue(self.test_course_4 >= self.test_course_3)
        self.assertFalse(self.test_course_1 <= self.test_department)
        self.assertFalse(self.test_course_1 > self.test_department)
        self.assertFalse(self.test_course_1 >= self.test_department)
        self.assertTrue(self.test_course_1 != self.test_department)

    def test_sort(self):
        sorted_list = [
            self.test_course_1,
            self.test_course_2,
            self.test_course_3,
            self.test_course_4,
            self.test_course_5,
            self.test_course_6,
            self.test_course_7,
            self.test_course_8,
            self.test_course_9,
        ]
        test_list = [
            self.test_course_1,
            self.test_course_3,
            self.test_course_5,
            self.test_course_7,
            self.test_course_9,
            self.test_course_4,
            self.test_course_6,
            self.test_course_8,
            self.test_course_2,
        ]
        self.assertNotEqual(test_list, sorted_list)
        test_list.sort()
        # Correct ordering:
        # TD1 61A, TD1 H61A, TD1 61B, TD1 70, TD2 C30,
        # TD2 70, TD2 130AC, TD2 C130AC, TD2 H130AC
        self.assertEquals(test_list, sorted_list)
Beispiel #12
0
 def setUp(self):
     self.dept_cs = Department(long_name='Computer Science',
                               short_name='CS',
                               abbreviation='COMPSCI')
     self.dept_cs.save()
     self.dept_ee = Department(long_name='Electrical Engineering',
                               short_name='EE',
                               abbreviation='EL ENG')
     self.dept_ee.save()
     self.course_cs_1 = Course(department=self.dept_cs, number='1')
     self.course_cs_1.save()
     self.course_ee_1 = Course(department=self.dept_ee, number='1')
     self.course_ee_1.save()
     self.instructor_cs = Instructor(first_name='Tau',
                                     last_name='Bate',
                                     department=self.dept_cs)
     self.instructor_cs.save()
     self.instructor_ee = Instructor(first_name='Pi',
                                     last_name='Bent',
                                     department=self.dept_ee)
     self.instructor_ee.save()
     self.instructor_ee_2 = Instructor(first_name='Bau',
                                       last_name='Tate',
                                       department=self.dept_ee)
     self.instructor_ee_2.save()
     self.term = Term(term='sp', year=2013, current=True)
     self.term.save()
     self.term2 = Term(term='sp', year=2014, current=False)
     self.term2.save()
     self.course_instance_cs_1 = CourseInstance(term=self.term,
                                                course=self.course_cs_1)
     self.course_instance_cs_1.save()
     self.course_instance_cs_1.instructors.add(self.instructor_cs)
     self.course_instance_cs_1.save()
     self.course_instance_ee_1 = CourseInstance(term=self.term,
                                                course=self.course_ee_1)
     self.course_instance_ee_1.save()
     self.course_instance_ee_1.instructors.add(self.instructor_ee)
     self.course_instance_ee_1.save()
     self.course_instance_ee_2 = CourseInstance(term=self.term2,
                                                course=self.course_ee_1)
     self.course_instance_ee_2.save()
     self.course_instance_ee_2.instructors.add(self.instructor_ee)
     self.course_instance_ee_2.save()
     self.course_instance_ee_3 = CourseInstance(term=self.term2,
                                                course=self.course_ee_1)
     self.course_instance_ee_3.save()
     self.course_instance_ee_3.instructors.add(self.instructor_ee_2)
     self.course_instance_ee_3.save()
     self.user = get_user_model().objects.create_user(
         username='******',
         email='tbp.berkeley.edu',
         password='******',
         first_name='tbp',
         last_name='user')
     self.user.save()
     self.syllabus_cs_1 = Syllabus(
         course_instance=self.course_instance_cs_1,
         submitter=self.user,
         file_ext='.pdf',
         verified=True)
     self.syllabus_cs_1.save()
     # Create exams:
     # ee_1: Course ee1, instr 1 final exam
     # ee_2: Course ee1, instr 1 final solution
     # ee_3: Course ee1, instr 1 final exam
     # ee_4: Course ee1, instr 2 final exam
     self.exam_ee_1 = Exam(course_instance=self.course_instance_ee_1,
                           submitter=self.user,
                           exam_number=Exam.FINAL,
                           exam_type=Exam.EXAM,
                           file_ext='.pdf',
                           verified=True)
     self.exam_ee_1.save()
     self.exam_ee_2 = Exam(course_instance=self.course_instance_ee_1,
                           submitter=self.user,
                           exam_number=Exam.FINAL,
                           exam_type=Exam.SOLN,
                           file_ext='.pdf',
                           verified=True)
     self.exam_ee_2.save()
     self.exam_ee_3 = Exam(course_instance=self.course_instance_ee_2,
                           submitter=self.user,
                           exam_number=Exam.FINAL,
                           exam_type=Exam.EXAM,
                           file_ext='.pdf',
                           verified=True)
     self.exam_ee_3.save()
     self.exam_ee_4 = Exam(course_instance=self.course_instance_ee_3,
                           submitter=self.user,
                           exam_number=Exam.FINAL,
                           exam_type=Exam.EXAM,
                           file_ext='.pdf',
                           verified=True)
     self.exam_ee_4.save()
Beispiel #13
0
class ExamTest(TestCase):
    fixtures = ['test/course_instance.yaml']

    def setUp(self):
        self.test_exam1 = make_test_exam(10000)
        self.test_exam2 = make_test_exam(20000)
        self.test_exam3 = make_test_exam(30000)

        self.permission1 = InstructorPermission.objects.get(pk=100000)
        self.permission2 = InstructorPermission.objects.get(pk=200000)
        self.permission3 = InstructorPermission.objects.get(pk=300000)

        self.dept_cs = Department(long_name='Computer Science',
                                  short_name='CS',
                                  abbreviation='COMPSCI')
        self.dept_cs.save()
        self.course_cs_1 = Course(department=self.dept_cs, number='1')
        self.course_cs_1.save()
        self.instructor_cs = Instructor(first_name='Tau',
                                        last_name='Bate',
                                        department=self.dept_cs)
        self.instructor_cs.save()
        self.term = Term(term='sp', year=2016, current=True)
        self.term.save()
        self.course_instance_cs_1 = CourseInstance(term=self.term,
                                                   course=self.course_cs_1)
        self.course_instance_cs_1.save()
        self.course_instance_cs_1.instructors.add(self.instructor_cs)
        self.course_instance_cs_1.save()

        self.permission4 = InstructorPermission(instructor=self.instructor_cs,
                                                permission_allowed=True)
        self.permission4.save()

    @classmethod
    def tearDownClass(cls):
        os.remove('test.txt')
        shutil.rmtree(os.path.join(settings.WORKSPACE_ROOT, 'media', 'tests'),
                      ignore_errors=True)

    def test_exam_manager(self):
        # All of the 3 test exams have approval (verified, no flags, not
        # blacklisted) when created in setUp:
        self.assertEquals(3, Exam.objects.get_approved().count())

        # Remove test_exam1 verification:
        self.test_exam1.verified = False
        self.test_exam1.save()
        approved_set = Exam.objects.get_approved()
        self.assertEquals(2, approved_set.count())
        self.assertNotIn(self.test_exam1, approved_set)

    def test_properites(self):
        self.assertEquals(self.test_exam1.file_ext, '.txt')
        self.assertNotEqual(self.test_exam1.unique_id, '')
        self.assertEquals(
            self.test_exam1.get_download_file_name(),
            '{course}-{term}-{number}-{instructors}-{type}{ext}'.format(
                course='test100',
                term=Term.SPRING + '2013',
                number=Exam.MT1,
                instructors='Beta_Tau',
                type=Exam.EXAM,
                ext='.txt'))
        self.assertEquals(unicode(self.test_exam1),
                          ('{term} {number} {type} for {course}, taught by '
                           '{instructors}').format(term='Spring 2013',
                                                   number='Midterm 1',
                                                   type='Exam',
                                                   course='Test 100',
                                                   instructors='Beta, Tau'))

    def test_flag_properites(self):
        exam_flag = ExamFlag(exam=self.test_exam1)
        self.assertEquals(unicode(exam_flag),
                          unicode(self.test_exam1) + ' Flag')
        self.assertFalse(exam_flag.resolved)

    def test_delete_exam_with_file(self):
        file_name = self.test_exam1.get_absolute_pathname()
        self.assertTrue(os.path.exists(file_name))
        self.test_exam1.delete()
        self.assertFalse(os.path.exists(file_name))

    def test_delete_exam_without_file(self):
        # pylint: disable=E1103
        self.test_exam1.exam_file.delete()
        file_name = self.test_exam1.get_absolute_pathname()
        self.test_exam1.delete()
        self.assertFalse(os.path.exists(file_name))

    def test_response(self):
        resp = self.client.get('/courses/Test/100/')
        # A successful HTTP GET request has status code 200
        self.assertEqual(resp.status_code, 200)

    def test_multiple_blacklists_and_exams(self):
        """permission 1 affects only Exam 1.
        permission 2 affects Exam 1 and Exam 2.
        permission 3 affects Exam 2 and Exam 3.
        """
        # pylint: disable=R0915
        resp = self.client.get('/courses/Test/100/')
        # All exams with 0 blacklists
        self.assertEqual(resp.context['exams'].count(), 3)
        # Exam 1 with 1 blacklist, Exam 2 with 0, Exam 3 with 0
        self.permission1.permission_allowed = False
        self.permission1.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertTrue(self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam2.blacklisted)
        self.assertFalse(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Exam 1 with 2 blacklists, Exam 2 with 1, Exam 3 with 0
        self.permission2.permission_allowed = False
        self.permission2.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertTrue(self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam2.blacklisted)
        self.assertFalse(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 1)
        # Exam 1 with 1 blacklists, Exam 2 with 0, Exam 3 with 0
        self.permission2.permission_allowed = True
        self.permission2.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertTrue(self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam2.blacklisted)
        self.assertFalse(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Exam 1 with 1 blacklists, Exam 2 with 1, Exam 3 with 1
        self.permission3.permission_allowed = False
        self.permission3.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertTrue(self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam2.blacklisted)
        self.assertTrue(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 0)
        # Exam 1 with 2 blacklists, Exam 2 with 2, Exam 3 with 1
        self.permission2.permission_allowed = False
        self.permission2.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertTrue(self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam2.blacklisted)
        self.assertTrue(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 0)
        # Exam 1 with 2 blacklists, Exam 2 with 1, Exam 3 with 0
        self.permission3.permission_allowed = True
        self.permission3.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertTrue(self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam2.blacklisted)
        self.assertFalse(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 1)
        # Exam 1 with 1 blacklist, Exam 2 with 0, Exam 3 with 0
        self.permission2.permission_allowed = True
        self.permission2.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertTrue(self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam2.blacklisted)
        self.assertFalse(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Exam 1 with 0 blacklists, Exam 2 with 0, Exam 3 with 0
        self.permission1.permission_allowed = True
        self.permission1.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertFalse(self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam2.blacklisted)
        self.assertFalse(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 3)
        # Exam 1 with 0 blacklist, Exam 2 with 1, Exam 3 with 1
        self.permission3.permission_allowed = False
        self.permission3.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertFalse(self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam2.blacklisted)
        self.assertTrue(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 1)
        # Exam 1 with 1 blacklist, Exam 2 with 2, Exam 3 with 1
        self.permission2.permission_allowed = False
        self.permission2.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertTrue(self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam2.blacklisted)
        self.assertTrue(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 0)
        # Exam 1 with 0 blacklists, Exam 2 with 1, Exam 3 with 1
        self.permission2.permission_allowed = True
        self.permission2.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertFalse(self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam2.blacklisted)
        self.assertTrue(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 1)
        # Exam 1 with 0 blacklists, Exam 2 with 0, Exam 3 with 0
        self.permission3.permission_allowed = True
        self.permission3.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam2 = Exam.objects.get(pk=self.test_exam2.pk)
        self.test_exam3 = Exam.objects.get(pk=self.test_exam3.pk)
        self.assertFalse(self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam2.blacklisted)
        self.assertFalse(self.test_exam3.blacklisted)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 3)

    def test_flags_verified_and_blacklist(self):
        """Tests all 8 combinations of flags, blacklisted, and verified."""
        # pylint: disable=W0612
        self.assertTrue(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertTrue(not self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 3)
        # Under flag limit, not blacklisted, verified
        exam_flag_list = []
        for i in range(0, ExamFlag.LIMIT):
            exam_flag = ExamFlag(exam=self.test_exam1)
            exam_flag.save()
            exam_flag_list.append(exam_flag)
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.assertTrue(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertTrue(not self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 3)
        # Over flag limit, not blacklisted, verified
        last_exam_flag = ExamFlag(exam=self.test_exam1)
        last_exam_flag.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.assertFalse(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertTrue(not self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Under flag limit, blacklisted, verified
        exam_flag_list[0].resolved = True
        exam_flag_list[0].save()
        self.permission1.permission_allowed = False
        self.permission1.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.assertTrue(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertFalse(not self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Under flag limit, not blacklisted, not verified
        self.permission1.permission_allowed = True
        self.permission1.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam1.verified = False
        self.test_exam1.save()
        self.assertTrue(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertTrue(not self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Over flag limit, not blacklisted, not verified
        exam_flag_list[0].resolved = False
        exam_flag_list[0].save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.assertFalse(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertTrue(not self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Over flag limit, blacklisted, verified
        self.test_exam1.verified = True
        self.test_exam1.save()
        self.permission1.permission_allowed = False
        self.permission1.save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.assertFalse(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertFalse(not self.test_exam1.blacklisted)
        self.assertTrue(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Under flag limit, blacklisted, not verified
        exam_flag_list[0].resolved = True
        exam_flag_list[0].save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.test_exam1.verified = False
        self.test_exam1.save()
        self.assertTrue(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertFalse(not self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)
        # Over flag limit, blacklisted, not verified
        exam_flag_list[0].resolved = False
        exam_flag_list[0].save()
        self.test_exam1 = Exam.objects.get(pk=self.test_exam1.pk)
        self.assertFalse(self.test_exam1.flags <= ExamFlag.LIMIT)
        self.assertFalse(not self.test_exam1.blacklisted)
        self.assertFalse(self.test_exam1.verified)
        resp = self.client.get('/courses/Test/100/')
        self.assertEqual(resp.context['exams'].count(), 2)

    def test_form_auto_blacklist(self):
        fields = {
            'department': self.dept_cs.pk,
            'course_number': 1,
            'instructors': [self.instructor_cs.pk],
            'exam_number': Exam.MT1,
            'exam_type': Exam.EXAM,
            'term': self.term.pk,
            'course_instance': self.course_instance_cs_1.pk,
            'agreed': True
        }
        exam_form = ExamForm(fields)
        self.assertTrue(exam_form.is_valid())
        exam_form.set_course_instance(fields)
        self.permission4.permission_allowed = False
        self.permission4.save()

        # After changing instructor permissions, this should raise an error
        exam_form = ExamForm(fields)
        self.assertTrue(exam_form.is_valid())
        self.assertRaises(forms.ValidationError, exam_form.set_course_instance,
                          fields)