Пример #1
0
    def setUp(self):
        super(TestGetProblemGradeDistribution, self).setUp()

        self.request_factory = RequestFactory()
        self.instructor = AdminFactory.create()
        self.client.login(username=self.instructor.username, password='******')
        self.attempts = 3
        self.users = [
            UserFactory.create(username="******" + str(__))
            for __ in range(USER_COUNT)
        ]

        for user in self.users:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)

        for i, item in enumerate(self.items):
            for j, user in enumerate(self.users):
                StudentModuleFactory.create(
                    grade=1 if i < j else 0,
                    max_grade=1 if i < j else 0.5,
                    student=user,
                    course_id=self.course.id,
                    module_state_key=item.location,
                    state=json.dumps({'attempts': self.attempts}),
                )
            for j, user in enumerate(self.users):
                StudentModuleFactory.create(
                    course_id=self.course.id,
                    module_type='sequential',
                    module_state_key=item.location,
                )
Пример #2
0
 def _create_student_module(self, state):
     StudentModuleFactory.create(
         student=self.user,
         module_state_key=self.problem.location,
         course_id=self.course.id,
         state=json.dumps(state)
     )
Пример #3
0
    def setUp(self):
        super(TestGradebook, self).setUp()

        instructor = AdminFactory.create()
        self.client.login(username=instructor.username, password='******')
        self.users = [UserFactory.create() for _ in range(USER_COUNT)]

        for user in self.users:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)

        for i, item in enumerate(self.items):
            for j, user in enumerate(self.users):
                StudentModuleFactory.create(
                    grade=1 if i < j else 0,
                    max_grade=1,
                    student=user,
                    course_id=self.course.id,
                    module_state_key=item.location
                )
        task_compute_all_grades_for_course.apply_async(kwargs={'course_key': text_type(self.course.id)})

        self.response = self.client.get(reverse(
            'spoc_gradebook',
            args=(text_type(self.course.id),)
        ))

        self.assertEqual(self.response.status_code, 200)
Пример #4
0
def setup_students_and_grades(context):
    """
    Create students and set their grades.
    :param context:  class reference
    """
    if context.course:
        context.student = student = UserFactory.create()
        CourseEnrollmentFactory.create(user=student, course_id=context.course.id)

        context.student2 = student2 = UserFactory.create(username='******')
        CourseEnrollmentFactory.create(user=student2, course_id=context.course.id)

        # create grades for self.student as if they'd submitted the ccx
        for chapter in context.course.get_children():
            for i, section in enumerate(chapter.get_children()):
                for j, problem in enumerate(section.get_children()):
                    # if not problem.visible_to_staff_only:
                    StudentModuleFactory.create(
                        grade=1 if i < j else 0,
                        max_grade=1,
                        student=context.student,
                        course_id=context.course.id,
                        module_state_key=problem.location
                    )

                    StudentModuleFactory.create(
                        grade=1 if i > j else 0,
                        max_grade=1,
                        student=context.student2,
                        course_id=context.course.id,
                        module_state_key=problem.location
                    )

        task_compute_all_grades_for_course.apply_async(kwargs={'course_key': str(context.course.id)})
Пример #5
0
    def _create_user_progress(self, user):
        """
        Creates block completion, student module and submission for a given
        user.
        """

        block = ItemFactory.create(parent=self.course)

        completion_test_value = 0.4

        with completion_waffle.waffle().override(completion_waffle.ENABLE_COMPLETION_TRACKING, True):
            BlockCompletion.objects.submit_completion(
                user=user,
                block_key=block.location,
                completion=completion_test_value,
            )

        StudentModuleFactory.create(
            student=user,
            course_id=self.course.id,
            module_state_key=block.location,
            state=json.dumps({})
        )

        sub_api.create_submission(
            {
                'student_id': anonymous_id_for_user(user, self.course.id),
                'course_id': str(self.course.id),
                'item_id': str(block.location),
                'item_type': 'problem',
            },
            'test answer'
        )
Пример #6
0
    def _create_students_with_state(self, num_students, state=None, grade=0, max_grade=1):
        """Create students, a problem, and StudentModule objects for testing"""
        self.define_option_problem(PROBLEM_URL_NAME)
        enrolled_students = self._create_and_enroll_students(num_students)

        for student in enrolled_students:
            StudentModuleFactory.create(
                course_id=self.course.id,
                module_state_key=self.location,
                student=student,
                grade=grade,
                max_grade=max_grade,
                state=state
            )
        return enrolled_students
Пример #7
0
 def setUp(self):
     super(TestStudentModuleHistoryBackends, self).setUp()
     for record in (1, 2, 3):
         # This will store into CSMHE via the post_save signal
         csm = StudentModuleFactory.create(module_state_key=location('usage_id'),
                                           course_id=course_id,
                                           state=json.dumps({'type': 'csmhe', 'order': record}))
         # This manually gets us a CSMH record to compare
         csmh = StudentModuleHistory(student_module=csm,
                                     version=None,
                                     created=csm.modified,
                                     state=json.dumps({'type': 'csmh', 'order': record}),
                                     grade=csm.grade,
                                     max_grade=csm.max_grade)
         csmh.save()
Пример #8
0
    def test_spoc_gradebook_mongo_calls(self):
        """
        Test that the MongoDB cache is used in API to return grades
        """
        # prepare course structure
        course = ItemFactory.create(
            parent_location=self.course.location,
            category="course",
            display_name="Test course",
        )

        students = []
        for i in range(20):
            username = "******" % i
            student = UserFactory.create(username=username)
            CourseEnrollmentFactory.create(user=student,
                                           course_id=self.course.id)
            students.append(student)

        chapter = ItemFactory.create(
            parent=course,
            category='chapter',
            display_name="Chapter",
            publish_item=True,
            start=datetime.datetime(2015, 3, 1, tzinfo=UTC),
        )
        sequential = ItemFactory.create(
            parent=chapter,
            category='sequential',
            display_name="Lesson",
            publish_item=True,
            start=datetime.datetime(2015, 3, 1, tzinfo=UTC),
            metadata={
                'graded': True,
                'format': 'Homework'
            },
        )
        vertical = ItemFactory.create(
            parent=sequential,
            category='vertical',
            display_name='Subsection',
            publish_item=True,
            start=datetime.datetime(2015, 4, 1, tzinfo=UTC),
        )
        for i in range(10):
            problem = ItemFactory.create(
                category="problem",
                parent=vertical,
                display_name="A Problem Block %d" % i,
                weight=1,
                publish_item=False,
                metadata={'rerandomize': 'always'},
            )
            for j in students:
                grade = i % 2
                StudentModuleFactory.create(grade=grade,
                                            max_grade=1,
                                            student=j,
                                            course_id=self.course.id,
                                            module_state_key=problem.location)

        # check MongoDB calls count
        url = reverse('spoc_gradebook', kwargs={'course_id': self.course.id})
        with check_mongo_calls(7):
            response = self.client.get(url)
            assert response.status_code == 200
Пример #9
0
    def setUp(self):
        super(TestStaffView, self).setUp()
        # create a course
        self.course = CourseFactory.create(org='mss',
                                           course='999',
                                           display_name='eol feedback course')

        # Now give it some content
        with self.store.bulk_operations(self.course.id, emit_signals=False):
            chapter = ItemFactory.create(
                parent_location=self.course.location,
                category="sequential",
            )
            section = ItemFactory.create(parent_location=chapter.location,
                                         category="sequential",
                                         metadata={
                                             'graded': True,
                                             'format': 'Homework'
                                         })
            self.items = [
                ItemFactory.create(
                    parent_location=section.location,
                    category="problem",
                    data=StringResponseXMLFactory().build_xml(answer='foo'),
                    metadata={'rerandomize': 'always'})
                for __ in range(USER_COUNT - 1)
            ]

        # Create users, enroll and set grades
        self.users = [UserFactory.create() for _ in range(USER_COUNT)]
        for user in self.users:
            CourseEnrollmentFactory.create(user=user, course_id=self.course.id)
        for i, item in enumerate(self.items):
            for j, user in enumerate(self.users):
                StudentModuleFactory.create(grade=1 if i < j else 0,
                                            max_grade=1,
                                            student=user,
                                            course_id=self.course.id,
                                            module_state_key=item.location)
        task_compute_all_grades_for_course.apply_async(
            kwargs={'course_key': text_type(self.course.id)})

        # Patch the comment client user save method so it does not try
        # to create a new cc user when creating a django user
        with patch('student.models.cc.User.save'):
            # Create the student
            self.student = UserFactory(username='******',
                                       password='******',
                                       email='*****@*****.**')
            # Enroll the student in the course
            CourseEnrollmentFactory(user=self.student,
                                    course_id=self.course.id)

            # Create and Enroll staff user
            self.staff_user = UserFactory(username='******',
                                          password='******',
                                          email='*****@*****.**',
                                          is_staff=True)
            CourseEnrollmentFactory(user=self.staff_user,
                                    course_id=self.course.id)

            # Log the student in
            self.client = Client()
            self.assertTrue(
                self.client.login(username='******', password='******'))

            # Log the user staff in
            self.staff_client = Client()
            self.assertTrue(
                self.staff_client.login(username='******',
                                        password='******'))