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.course = CourseFactory.create( display_name=u"test course omega \u03a9", ) section = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name=u"test factory section omega \u03a9", ) self.sub_section = ItemFactory.create( parent_location=section.location, category="sequential", display_name=u"test subsection omega \u03a9", ) unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={'graded': True, 'format': 'Homework'}, display_name=u"test unit omega \u03a9", ) self.users = [UserFactory.create(username="******" + str(__)) for __ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" self.item = ItemFactory.create( parent_location=unit.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}, display_name=u"test problem omega \u03a9 " + str(i) ) 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=self.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=self.item.location, )
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 xrange(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, )
def test_student_state(self, default_store): """ Verify that saved student state is loaded for xblocks rendered in the index view. """ user = UserFactory() with modulestore().default_store(default_store): course = CourseFactory.create() chapter = ItemFactory.create(parent=course, category="chapter") section = ItemFactory.create(parent=chapter, category="view_checker", display_name="Sequence Checker") vertical = ItemFactory.create(parent=section, category="view_checker", display_name="Vertical Checker") block = ItemFactory.create(parent=vertical, category="view_checker", display_name="Block Checker") for item in (section, vertical, block): StudentModuleFactory.create( student=user, course_id=course.id, module_state_key=item.scope_ids.usage_id, state=json.dumps({"state": unicode(item.scope_ids.usage_id)}), ) CourseEnrollmentFactory(user=user, course_id=course.id) request = RequestFactory().get( reverse( "courseware_section", kwargs={"course_id": unicode(course.id), "chapter": chapter.url_name, "section": section.url_name}, ) ) request.user = user mako_middleware_process_request(request) # Trigger the assertions embedded in the ViewCheckerBlocks response = views.index(request, unicode(course.id), chapter=chapter.url_name, section=section.url_name) self.assertEquals(response.content.count("ViewCheckerPassed"), 3)
def setUp(self): super(TestGradebook, self).setUp() instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') self.users = [UserFactory.create() for _ in xrange(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 ) self.response = self.client.get(reverse( 'spoc_gradebook', args=(self.course.id.to_deprecated_string(),) )) self.assertEquals(self.response.status_code, 200)
def setUp(self): super(TestGradebook, self).setUp() instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') self.users = [UserFactory.create() for _ in xrange(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 ) 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.assertEquals(self.response.status_code, 200)
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() 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 )
def setUp(self): self.request_factory = RequestFactory() self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password='******') self.attempts = 3 self.course = CourseFactory.create( display_name=u"test course omega \u03a9", ) section = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name=u"test factory section omega \u03a9", ) self.sub_section = ItemFactory.create( parent_location=section.location, category="sequential", display_name=u"test subsection omega \u03a9", ) unit = ItemFactory.create( parent_location=self.sub_section.location, category="vertical", metadata={'graded': True, 'format': 'Homework'}, display_name=u"test unit omega \u03a9", ) self.users = [UserFactory.create(username="******" + str(__)) for __ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" self.item = ItemFactory.create( parent_location=unit.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}, display_name=u"test problem omega \u03a9 " + str(i) ) 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=Location(self.item.location).url(), 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=Location(self.item.location).url(), )
def setUp(self): super(TestGradebookVertical, self).setUp() instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') # remove the caches modulestore().request_cache = None modulestore().metadata_inheritance_cache_subsystem = None kwargs = {} if self.grading_policy is not None: kwargs['grading_policy'] = self.grading_policy self.course = CourseFactory.create(**kwargs) chapter = ItemFactory.create( parent_location=self.course.location, category="sequential", ) section = ItemFactory.create( parent_location=chapter.location, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 0.8} ) ItemFactory.create( parent_location=chapter.location, category="vertical", metadata={'graded': True, 'format': 'Homework', 'weight': 0.2} ) self.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" item = ItemFactory.create( parent_location=section.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) 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 ) self.response = self.client.get(reverse( 'spoc_gradebook', args=(self.course.id.to_deprecated_string(),) ))
def setUp(self): super(TestGradebookVertical, self).setUp() instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') # remove the caches modulestore().request_cache = None modulestore().metadata_inheritance_cache_subsystem = None kwargs = {} if self.grading_policy is not None: kwargs['grading_policy'] = self.grading_policy self.course = CourseFactory.create(**kwargs) chapter = ItemFactory.create( parent_location=self.course.location, category="sequential", ) section = ItemFactory.create(parent_location=chapter.location, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.8 }) ItemFactory.create(parent_location=chapter.location, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.2 }) self.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" item = ItemFactory.create( parent_location=section.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}) 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) self.response = self.client.get( reverse('spoc_gradebook', args=(self.course.id.to_deprecated_string(), )))
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 xrange(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 xrange(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(8): response = self.client.get(url) self.assertEqual(response.status_code, 200)
def setUp(self): """ Set up tests """ super(TestCCXGrades, self).setUp() # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create CCX role = CourseCcxCoachRole(self._course.id) role.add_users(coach) ccx = CcxFactory(course_id=self._course.id, coach=self.coach) # override course grading policy and make last section invisible to students override_field_for_ccx( ccx, self._course, 'grading_policy', { 'GRADER': [{ 'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'weight': 1 }], 'GRADE_CUTOFFS': { 'Pass': 0.75 }, }) override_field_for_ccx(ccx, self.sections[-1], 'visible_to_staff_only', True) # create a ccx locator and retrieve the course structure using that key # which emulates how a student would get access. self.ccx_key = CCXLocator.from_course_locator(self._course.id, ccx.id) self.course = get_course_by_id(self.ccx_key, depth=None) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) # create grades for self.student as if they'd submitted the ccx for chapter in self.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=self.student, course_id=self.course.id, module_state_key=problem.location) self.client.login(username=coach.username, password="******") self.addCleanup(RequestCache.clear_request_cache)
def setUp(self): """ Set up tests """ super(TestCCXGrades, self).setUp() # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create CCX role = CourseCcxCoachRole(self._course.id) role.add_users(coach) ccx = CcxFactory(course_id=self._course.id, coach=self.coach) # override course grading policy and make last section invisible to students override_field_for_ccx(ccx, self._course, 'grading_policy', { 'GRADER': [ {'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'weight': 1} ], 'GRADE_CUTOFFS': {'Pass': 0.75}, }) override_field_for_ccx( ccx, self.sections[-1], 'visible_to_staff_only', True ) # create a ccx locator and retrieve the course structure using that key # which emulates how a student would get access. self.ccx_key = CCXLocator.from_course_locator(self._course.id, ccx.id) self.course = get_course_by_id(self.ccx_key, depth=None) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) # create grades for self.student as if they'd submitted the ccx for chapter in self.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=self.student, course_id=self.course.id, module_state_key=problem.location ) self.client.login(username=coach.username, password="******") self.addCleanup(RequestCache.clear_request_cache)
def _create_students_with_state(self, num_students, state=None): """Create students, a problem, and StudentModule objects for testing""" self.define_option_problem(PROBLEM_URL_NAME) students = [ UserFactory.create(username='******' % i, email='*****@*****.**' % i) for i in xrange(num_students) ] for student in students: StudentModuleFactory.create(course_id=self.course.id, module_state_key=self.problem_url, student=student, state=state) return students
def test_edx_grade_with_no_score_but_problem_loaded(self): """Test grading with an already loaded problem but without score. This can happen when the student calls the progress page from the courseware (djangoapps.courseware.views.progress). The progress view grades the activity only to get the current score but staff may have not given the problem a score yet. """ request = RequestFactory().get('/') user = UserFactory(username='******') CourseEnrollmentFactory.create(course_id=self.course.id, user=user) StudentModuleFactory.create(student=user, course_id=self.course.id, module_state_key=str(self.gea_xblock.location)) grade = _grade(user, request, self.course, None) self.assertEqual(grade['percent'], 0.0)
def test_problem_with_no_answer(self): section, sub_section, unit, problem = self.create_course_structure() self.create_student() StudentModuleFactory.create( course_id=self.course.id, module_state_key=problem.location, student=self.student, grade=0, state=u'{"answer": {"problem_id": "123"}}', ) course_with_children = modulestore().get_course(self.course.id, depth=4) datarows = list(student_responses(course_with_children)) self.assertEqual(datarows[0][-2], None)
def test_problem_with_no_answer(self): section, sub_section, unit, problem = self.create_course_structure() self.create_student() StudentModuleFactory.create( course_id=self.course.id, module_state_key=problem.location, student=self.student, grade=0, state=u'{"answer": {"problem_id": "123"}}', ) course_with_children = modulestore().get_course(self.course.id, depth=4) datarows = list(student_responses(course_with_children)) self.assertEqual(datarows[0][-1], None)
def setUp(self): instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') modulestore().request_cache = modulestore( ).metadata_inheritance_cache_subsystem = None course_data = {} if self.grading_policy is not None: course_data['grading_policy'] = self.grading_policy self.course = CourseFactory.create(data=course_data) chapter = ItemFactory.create( parent_location=self.course.location, template="i4x://edx/templates/sequential/Empty", ) section = ItemFactory.create( parent_location=chapter.location, template="i4x://edx/templates/sequential/Empty", metadata={'graded': True, 'format': 'Homework'} ) self.users = [ UserFactory.create(username='******' % i, email='*****@*****.**' % i) for i in xrange(USER_COUNT) ] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): template_name = "i4x://edx/templates/problem/Blank_Common_Problem" item = ItemFactory.create( parent_location=section.location, template=template_name, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) 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=Location(item.location).url() ) self.response = self.client.get(reverse( 'gradebook', args=(self.course.id,)))
def setUp(self): instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') modulestore().request_cache = modulestore( ).metadata_inheritance_cache_subsystem = None course_data = {} if self.grading_policy is not None: course_data['grading_policy'] = self.grading_policy self.course = CourseFactory.create(data=course_data) chapter = ItemFactory.create( parent_location=self.course.location, template="i4x://edx/templates/sequential/Empty", ) section = ItemFactory.create( parent_location=chapter.location, template="i4x://edx/templates/sequential/Empty", metadata={ 'graded': True, 'format': 'Homework' }) self.users = [ UserFactory.create(username='******' % i, email='*****@*****.**' % i) for i in xrange(USER_COUNT) ] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): template_name = "i4x://edx/templates/problem/Blank_Common_Problem" item = ItemFactory.create( parent_location=section.location, template=template_name, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}) 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=Location( item.location).url()) self.response = self.client.get( reverse('gradebook', args=(self.course.id, )))
def test_invalid_module_state(self): section, sub_section, unit, problem = self.create_course_structure() self.create_student() StudentModuleFactory.create( course_id=self.course.id, module_state_key=problem.location, student=self.student, grade=0, state=u'{"student_answers":{"fake-problem":"No idea"}}}', ) course_with_children = modulestore().get_course(self.course.id, depth=4) datarows = list(student_responses(course_with_children)) # Invalid module state response will be skipped, so datarows should be empty self.assertEqual(len(datarows), 0)
def setUp(self): self.instructor = AdminFactory.create() self.client.login(username=self.instructor.username, password="******") self.attempts = 3 self.course = CourseFactory.create(display_name=u"test course omega \u03a9") section = ItemFactory.create( parent_location=self.course.location, category="chapter", display_name=u"test factory section omega \u03a9" ) sub_section = ItemFactory.create( parent_location=section.location, category="sequential", display_name=u"test subsection omega \u03a9" ) unit = ItemFactory.create( parent_location=sub_section.location, category="vertical", metadata={"graded": True, "format": "Homework"}, display_name=u"test unit omega \u03a9", ) self.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" item = ItemFactory.create( parent_location=unit.location, category=category, data=StringResponseXMLFactory().build_xml(answer="foo"), metadata={"rerandomize": "always"}, display_name=u"test problem omega \u03a9 " + str(i), ) 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=Location(item.location).url(), 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=Location(item.location).url() )
def test_unicode(self): self.course = CourseFactory.create() course_key = self.course.id self.problem_location = Location('edX', 'unicode_graded', '2012_Fall', 'problem', 'H1P1') self.student = UserFactory(username=u'student\xec') CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) StudentModuleFactory.create( course_id=self.course.id, module_state_key=self.problem_location, student=self.student, grade=0, state=u'{"student_answers":{"fake-problem":"caf\xe9"}}', ) result = push_student_responses_to_s3(None, None, self.course.id, None, 'generated') self.assertEqual(result, 'succeeded')
def test_problem_with_no_answer(self): self.course = get_course(CourseKey.from_string('edX/graded/2012_Fall')) problem_location = Location('edX', 'graded', '2012_Fall', 'problem', 'H1P2') self.create_student() StudentModuleFactory.create( course_id=self.course.id, module_state_key=problem_location, student=self.student, grade=0, state=u'{"answer": {"problem_id": "123"}}', ) datarows = list(student_responses(self.course)) self.assertEqual(datarows[0][-1], None)
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
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) students = [ UserFactory.create(username='******' % i, email='*****@*****.**' % i) for i in xrange(num_students) ] for student in students: CourseEnrollmentFactory.create(course_id=self.course.id, user=student) StudentModuleFactory.create(course_id=self.course.id, module_state_key=self.location, student=student, grade=grade, max_grade=max_grade, state=state) return students
def test_histogram_enabled_for_scored_xmodules(self): """Histograms should display for xmodules which are scored.""" StudentModuleFactory.create( course_id=self.course.id, module_state_key=self.location, student=UserFactory(), grade=1, max_grade=1, state="{}", ) with patch("xmodule_modifiers.grade_histogram") as mock_grade_histogram: mock_grade_histogram.return_value = [] module = render.get_module(self.user, self.request, self.location, self.field_data_cache) module.render(STUDENT_VIEW) self.assertTrue(mock_grade_histogram.called)
def test_invalid_module_state(self): self.course = get_course(CourseKey.from_string('edX/graded/2012_Fall')) self.problem_location = Location("edX", "graded", "2012_Fall", "problem", "H1P2") self.create_student() StudentModuleFactory.create( course_id=self.course.id, module_state_key=self.problem_location, student=self.student, grade=0, state=u'{"student_answers":{"fake-problem":"No idea"}}}' ) datarows = list(student_responses(self.course)) #Invalid module state response will be skipped, so datarows should be empty self.assertEqual(len(datarows), 0)
def test_problem_with_student_answer_and_answers(self): section, sub_section, unit, problem = self.create_course_structure() submit_and_compare_valid_state = ItemFactory.create( parent_location=unit.location, category='submit-and-compare', display_name=u'test submit_and_compare1', ) submit_and_compare_invalid_state = ItemFactory.create( parent_location=unit.location, category='submit-and-compare', display_name=u'test submit_and_compare2', ) content_library = ItemFactory.create( parent_location=unit.location, category='library_content', display_name=u'test content_library', ) library_problem = ItemFactory.create( parent_location=content_library.location, category='problem', ) self.create_student() StudentModuleFactory.create( course_id=self.course.id, module_state_key=problem.location, student=self.student, grade=0, state=u'{"student_answers":{"problem_id":"student response1"}}', ) StudentModuleFactory.create( course_id=self.course.id, module_state_key=submit_and_compare_valid_state.location, student=self.student, grade=1, state=u'{"student_answer": "student response2"}', ) StudentModuleFactory.create( course_id=self.course.id, module_state_key=submit_and_compare_invalid_state.location, student=self.student, grade=1, state=u'{"answer": {"problem_id": "123"}}', ) StudentModuleFactory.create( course_id=self.course.id, module_state_key=library_problem.location, student=self.student, grade=0, state=u'{"student_answers":{"problem_id":"content library response1"}}', ) course_with_children = modulestore().get_course(self.course.id, depth=4) datarows = list(student_responses(course_with_children)) self.assertEqual(datarows[0][-1], u'problem_id=student response1') self.assertEqual(datarows[1][-1], u'student response2') self.assertEqual(datarows[2][-1], None) self.assertEqual(datarows[3][-1], u'problem_id=content library response1')
def test_problem_with_student_answer_and_answers(self): section, sub_section, unit, problem = self.create_course_structure() submit_and_compare_valid_state = ItemFactory.create( parent_location=unit.location, category='submit-and-compare', display_name=u'test submit_and_compare1', ) submit_and_compare_invalid_state = ItemFactory.create( parent_location=unit.location, category='submit-and-compare', display_name=u'test submit_and_compare2', ) content_library = ItemFactory.create( parent_location=unit.location, category='library_content', display_name=u'test content_library', ) library_problem = ItemFactory.create( parent_location=content_library.location, category='problem', ) self.create_student() StudentModuleFactory.create( course_id=self.course.id, module_state_key=problem.location, student=self.student, grade=0, state=u'{"student_answers":{"problem_id":"student response1"}}', ) StudentModuleFactory.create( course_id=self.course.id, module_state_key=submit_and_compare_valid_state.location, student=self.student, grade=1, state=u'{"student_answer": "student response2"}', ) StudentModuleFactory.create( course_id=self.course.id, module_state_key=submit_and_compare_invalid_state.location, student=self.student, grade=1, state=u'{"answer": {"problem_id": "123"}}', ) StudentModuleFactory.create( course_id=self.course.id, module_state_key=library_problem.location, student=self.student, grade=0, state=u'{"student_answers":{"problem_id":"content library response1"}}', ) course_with_children = modulestore().get_course(self.course.id, depth=4) datarows = list(student_responses(course_with_children)) self.assertEqual(datarows[0][-2], u'problem_id=student response1') self.assertEqual(datarows[1][-2], u'student response2') self.assertEqual(datarows[2][-2], None) self.assertEqual(datarows[3][-2], u'problem_id=content library response1')
def setUp(self): instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') # remove the caches modulestore().set_modulestore_configuration({}) kwargs = {} if self.grading_policy is not None: kwargs['grading_policy'] = self.grading_policy self.course = CourseFactory.create(**kwargs) 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.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" item = ItemFactory.create( parent_location=section.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}) 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=Location( item.location).url()) self.response = self.client.get( reverse('gradebook', args=(self.course.id, )))
def setUp(self): instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') # remove the caches modulestore().set_modulestore_configuration({}) kwargs = {} if self.grading_policy is not None: kwargs['grading_policy'] = self.grading_policy self.course = CourseFactory.create(**kwargs) 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.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" item = ItemFactory.create( parent_location=section.location, category=category, data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'} ) 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=Location(item.location).url() ) self.response = self.client.get(reverse('gradebook', args=(self.course.id,)))
def test_unicode(self): course_key = CourseKey.from_string('edX/unicode_graded/2012_Fall') self.course = get_course_by_id(course_key) self.problem_location = Location("edX", "unicode_graded", "2012_Fall", "problem", "H1P1") self.student = UserFactory(username=u'student\xec') CourseEnrollmentFactory.create(user=self.student, course_id=self.course.id) StudentModuleFactory.create( course_id=self.course.id, module_state_key=self.problem_location, student=self.student, grade=0, state=u'{"student_answers":{"fake-problem":"caf\xe9"}}', ) result = push_student_responses_to_s3(None, None, self.course.id, None, 'generated') self.assertEqual(result, "succeeded")
def test_student_state(self, default_store): """ Verify that saved student state is loaded for xblocks rendered in the index view. """ user = UserFactory() with modulestore().default_store(default_store): course = CourseFactory.create() chapter = ItemFactory.create(parent=course, category='chapter') section = ItemFactory.create(parent=chapter, category='view_checker', display_name="Sequence Checker") vertical = ItemFactory.create(parent=section, category='view_checker', display_name="Vertical Checker") block = ItemFactory.create(parent=vertical, category='view_checker', display_name="Block Checker") for item in (section, vertical, block): StudentModuleFactory.create( student=user, course_id=course.id, module_state_key=item.scope_ids.usage_id, state=json.dumps({'state': unicode(item.scope_ids.usage_id)})) CourseEnrollmentFactory(user=user, course_id=course.id) request = RequestFactory().get( reverse('courseware_section', kwargs={ 'course_id': unicode(course.id), 'chapter': chapter.url_name, 'section': section.url_name, })) request.user = user mako_middleware_process_request(request) # Trigger the assertions embedded in the ViewCheckerBlocks response = views.index(request, unicode(course.id), chapter=chapter.url_name, section=section.url_name) self.assertEquals(response.content.count("ViewCheckerPassed"), 3)
def _create_student_module_entry(self): cmap = self._build_correct_map('correct') student_answers = self._build_student_answers(OPTION_1, OPTION_2) StudentModuleFactory(course_id=self.course.id, module_state_key=self.problem_module.location, student=UserFactory(username=self.username, profile__year_of_birth=1989, profile__level_of_education=u'bac'), state=json.dumps(self._build_student_module_state(cmap, student_answers)))
def setUp(self): instructor = AdminFactory.create() self.client.login(username=instructor.username, password="******") # remove the caches modulestore().request_cache = None modulestore().metadata_inheritance_cache_subsystem = None kwargs = {} if self.grading_policy is not None: kwargs["grading_policy"] = self.grading_policy self.course = CourseFactory.create(**kwargs) 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.users = [UserFactory.create() for _ in xrange(USER_COUNT)] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) for i in xrange(USER_COUNT - 1): category = "problem" item = ItemFactory.create( parent_location=section.location, category=category, data=StringResponseXMLFactory().build_xml(answer="foo"), metadata={"rerandomize": "always"}, ) 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, ) self.response = self.client.get(reverse("spoc_gradebook", args=(self.course.id.to_deprecated_string(),)))
def test_histogram_enabled_for_scored_xmodules(self): """Histograms should display for xmodules which are scored.""" StudentModuleFactory.create( course_id=self.course.id, module_state_key=self.location, student=UserFactory(), grade=1, max_grade=1, state="{}", ) with patch('xmodule_modifiers.grade_histogram') as mock_grade_histogram: mock_grade_histogram.return_value = [] module = render.get_module( self.user, self.request, self.location, self.field_data_cache, ) module.render(STUDENT_VIEW) self.assertTrue(mock_grade_histogram.called)
def test_problem_with_student_answer_and_answers(self): self.course = get_course(CourseKey.from_string('edX/graded/2012_Fall')) problem_location = Location('edX', 'graded', '2012_Fall', 'problem', 'H1P2') self.create_student() StudentModuleFactory.create( course_id=self.course.id, module_state_key=problem_location, student=self.student, grade=0, state=u'{"student_answers":{"problem_id":"student response1"}}', ) submit_and_compare_location = Location('edX', 'graded', '2012_Fall', 'problem', 'H1P3') StudentModuleFactory.create( course_id=self.course.id, module_state_key=submit_and_compare_location, student=self.student, grade=0, state=u'{"student_answer": "student response2"}', ) submit_and_compare_location = Location("edX", "graded", "2012_Fall", "problem", 'H1P0') StudentModuleFactory.create( course_id=self.course.id, module_state_key=submit_and_compare_location, student=self.student, grade=0, state=u'{"answer": {"problem_id": "123"}}', ) datarows = list(student_responses(self.course)) self.assertEqual(datarows[0][-1], u'problem_id=student response1') self.assertEqual(datarows[1][-1], u'student response2')
def setUp(self): self.course_id = "edX/open_ended/2012_Fall" self.problem_location = Location([ "i4x", "edX", "open_ended", "combinedopenended", "SampleQuestion" ]) self.self_assessment_task_number = 0 self.open_ended_task_number = 1 self.student_on_initial = UserFactory() self.student_on_accessing = UserFactory() self.student_on_post_assessment = UserFactory() StudentModuleFactory.create(course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_initial, grade=0, max_grade=1, state=STATE_INITIAL) StudentModuleFactory.create(course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_accessing, grade=0, max_grade=1, state=STATE_ACCESSING) StudentModuleFactory.create(course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_post_assessment, grade=0, max_grade=1, state=STATE_POST_ASSESSMENT)
def setUp(self): super(TestGradebook, self).setUp() instructor = AdminFactory.create() self.client.login(username=instructor.username, password='******') self.users = [UserFactory.create() for _ in xrange(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 ) self.response = self.client.get(reverse( 'spoc_gradebook', args=(self.course.id.to_deprecated_string(),) ))
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()
def test_get_student_answers(self): first_question = RF.MultipleChoiceResponseXMLFactory().build_xml( choices=[True, False, False]) second_question = RF.MultipleChoiceResponseXMLFactory().build_xml( choices=[False, True, False]) self.problem_module.data = self._build_problem(first_question, second_question) problem_monitor = ProblemMonitor(self.problem_module) cmap = self._build_correct_map('correct', 'incorrect') student_answers = self._build_student_answers('choice_0', 'choice_2') StudentModuleFactory(course_id=self.course.id, state=self._build_student_module_state( cmap, student_answers)) problem_monitor.get_student_answers() correctness_first_question = problem_monitor.question_monitors[ self._build_question_id(0)].correctness student_answers_first_question = problem_monitor.question_monitors[ self._build_question_id(1)].student_answers correctness_second_question = problem_monitor.question_monitors[ self._build_question_id(1)].correctness student_answers_second_question = problem_monitor.question_monitors[ self._build_question_id(1)].student_answers self.assertDictContainsSubset(correctness_first_question, { 'correct': 1, 'incorrect': 0 }) self.assertDictContainsSubset(student_answers_first_question, {'choice_0': 1}) self.assertDictContainsSubset(correctness_second_question, { 'correct': 0, 'incorrect': 1 }) self.assertDictContainsSubset(student_answers_second_question, {'choice_2': 1})
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()
def setUp(self): super(OpenEndedStatsTest, self).setUp() self.user = UserFactory() store = modulestore() course_items = import_from_xml(store, self.user.id, TEST_DATA_DIR, ['open_ended']) # pylint: disable=maybe-no-member self.course = course_items[0] self.course_id = self.course.id self.problem_location = Location("edX", "open_ended", "2012_Fall", "combinedopenended", "SampleQuestion") self.task_number = 1 self.invalid_task_number = 3 self.student_on_initial = UserFactory() self.student_on_accessing = UserFactory() self.student_on_post_assessment = UserFactory() StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_initial, grade=0, max_grade=1, state=STATE_INITIAL ) StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_accessing, grade=0, max_grade=1, state=STATE_ACCESSING ) StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_post_assessment, grade=0, max_grade=1, state=STATE_POST_ASSESSMENT ) self.students = [self.student_on_initial, self.student_on_accessing, self.student_on_post_assessment]
def setUp(self): self.course_id = SlashSeparatedCourseKey("edX", "open_ended", "2012_Fall") self.problem_location = Location("edX", "open_ended", "2012_Fall", "combinedopenended", "SampleQuestion") self.task_number = 1 self.invalid_task_number = 3 self.student_on_initial = UserFactory() self.student_on_accessing = UserFactory() self.student_on_post_assessment = UserFactory() StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_initial, grade=0, max_grade=1, state=STATE_INITIAL ) StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_accessing, grade=0, max_grade=1, state=STATE_ACCESSING ) StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_post_assessment, grade=0, max_grade=1, state=STATE_POST_ASSESSMENT ) self.students = [self.student_on_initial, self.student_on_accessing, self.student_on_post_assessment]
def setUp(self): self.course_id = "edX/open_ended/2012_Fall" self.problem_location = Location(["i4x", "edX", "open_ended", "combinedopenended", "SampleQuestion"]) self.self_assessment_task_number = 0 self.open_ended_task_number = 1 self.student_on_initial = UserFactory() self.student_on_accessing = UserFactory() self.student_on_post_assessment = UserFactory() StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_initial, grade=0, max_grade=1, state=STATE_INITIAL ) StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_accessing, grade=0, max_grade=1, state=STATE_ACCESSING ) StudentModuleFactory.create( course_id=self.course_id, module_state_key=self.problem_location, student=self.student_on_post_assessment, grade=0, max_grade=1, state=STATE_POST_ASSESSMENT )
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=u"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(9): response = self.client.get(url) self.assertEqual(response.status_code, 200)
def setUp(self): """ Set up a course with graded problems. Course hierarchy is as follows: -> course -> chapter -> vertical (graded) -> problem -> problem """ super(TestCCXGradesVertical, self).setUp() self.course = course = CourseFactory.create(enable_ccx=True) # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) chapter = ItemFactory.create(start=start, parent=course) verticals = [ ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.5 }), ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.2 }), ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.2 }), ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 0.1 }), ItemFactory.create(parent=chapter, category="vertical", metadata={ 'graded': True, 'format': 'Homework', 'weight': 1.0 }), ] # pylint: disable=unused-variable problems = [[ ItemFactory.create( parent=section, category="problem", data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}) for _ in xrange(4) ] for section in verticals] # Create CCX role = CourseCcxCoachRole(course.id) role.add_users(coach) ccx = CcxFactory(course_id=course.id, coach=self.coach) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None # pylint: disable=protected-access for block in iter_blocks(course): block._field_data = OverrideFieldData.wrap(coach, course, block._field_data) new_cache = {'tabs': [], 'discussion_topics': []} if 'grading_policy' in block._field_data_cache: new_cache['grading_policy'] = block._field_data_cache[ 'grading_policy'] block._field_data_cache = new_cache def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes) # override course grading policy and make last section invisible to students override_field_for_ccx( ccx, course, 'grading_policy', { 'GRADER': [{ 'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'passing_grade': 0, 'weight': 1 }], 'GRADE_CUTOFFS': { 'Pass': 0.75 }, }) override_field_for_ccx(ccx, verticals[-1], 'visible_to_staff_only', True) # create a ccx locator and retrieve the course structure using that key # which emulates how a student would get access. self.ccx_key = CCXLocator.from_course_locator(course.id, ccx.id) self.course = get_course_by_id(self.ccx_key) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CcxMembershipFactory(ccx=ccx, student=student, active=True) # create grades for self.student as if they'd submitted the ccx for chapter in self.course.get_children(): for i, vertical in enumerate(chapter.get_children()): for j, problem in enumerate(vertical.get_children()): # if not problem.visible_to_staff_only: StudentModuleFactory.create( grade=1 if i < j else 0, max_grade=1, student=self.student, course_id=self.course.id, module_state_key=problem.location) self.client.login(username=coach.username, password="******")
def setUp(self): """ Set up tests """ super(TestCCXGrades, self).setUp() self.course = course = CourseFactory.create(enable_ccx=True) # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) chapter = ItemFactory.create(start=start, parent=course, category='sequential') sections = [ ItemFactory.create(parent=chapter, category="sequential", metadata={ 'graded': True, 'format': 'Homework' }) for _ in xrange(4) ] # pylint: disable=unused-variable problems = [[ ItemFactory.create( parent=section, category="problem", data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}) for _ in xrange(4) ] for section in sections] # Create CCX role = CourseCcxCoachRole(course.id) role.add_users(coach) ccx = CcxFactory(course_id=course.id, coach=self.coach) # override course grading policy and make last section invisible to students override_field_for_ccx( ccx, course, 'grading_policy', { 'GRADER': [{ 'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'weight': 1 }], 'GRADE_CUTOFFS': { 'Pass': 0.75 }, }) override_field_for_ccx(ccx, sections[-1], 'visible_to_staff_only', True) # create a ccx locator and retrieve the course structure using that key # which emulates how a student would get access. self.ccx_key = CCXLocator.from_course_locator(course.id, ccx.id) self.course = get_course_by_id(self.ccx_key) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CcxMembershipFactory(ccx=ccx, student=student, active=True) # create grades for self.student as if they'd submitted the ccx for chapter in self.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=self.student, course_id=self.course.id, module_state_key=problem.location) self.client.login(username=coach.username, password="******") self.addCleanup(RequestCache.clear_request_cache)
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 xrange(USER_COUNT) ] for user in self.users: CourseEnrollmentFactory.create(user=user, course_id=self.course.id) # Adding an instructor and a staff to the site. These should not be included in any reports. instructor_member = InstructorFactory(course_key=self.course.id) CourseEnrollment.enroll(instructor_member, self.course.id) staff_member = StaffFactory(course_key=self.course.id) CourseEnrollment.enroll(staff_member, 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, state=json.dumps({'attempts': self.attempts}), ) StudentModuleFactory.create( grade=1, max_grade=1, student=instructor_member, course_id=self.course.id, module_state_key=item.location, state=json.dumps({'attempts': self.attempts}), ) StudentModuleFactory.create( grade=1, max_grade=1, student=staff_member, 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, student=user, module_type='sequential', module_state_key=self.sub_section.location, ) StudentModuleFactory.create( course_id=self.course.id, student=instructor_member, module_type='sequential', module_state_key=self.sub_section.location, ) StudentModuleFactory.create( course_id=self.course.id, student=staff_member, module_type='sequential', module_state_key=self.sub_section.location, )
def setUp(self): """ Set up tests """ super(TestCCXGrades, self).setUp() self.course = course = CourseFactory.create() # Create instructor account self.coach = coach = AdminFactory.create() self.client.login(username=coach.username, password="******") # Create a course outline self.mooc_start = start = datetime.datetime(2010, 5, 12, 2, 42, tzinfo=pytz.UTC) chapter = ItemFactory.create(start=start, parent=course, category='sequential') sections = [ ItemFactory.create(parent=chapter, category="sequential", metadata={ 'graded': True, 'format': 'Homework' }) for _ in xrange(4) ] role = CourseCcxCoachRole(self.course.id) role.add_users(coach) self.ccx = ccx = CcxFactory(course_id=self.course.id, coach=self.coach) self.student = student = UserFactory.create() CourseEnrollmentFactory.create(user=student, course_id=self.course.id) CcxMembershipFactory(ccx=ccx, student=student, active=True) for i, section in enumerate(sections): for j in xrange(4): item = ItemFactory.create( parent=section, category="problem", data=StringResponseXMLFactory().build_xml(answer='foo'), metadata={'rerandomize': 'always'}) StudentModuleFactory.create(grade=1 if i < j else 0, max_grade=1, student=student, course_id=self.course.id, module_state_key=item.location) # Apparently the test harness doesn't use LmsFieldStorage, and I'm not # sure if there's a way to poke the test harness to do so. So, we'll # just inject the override field storage in this brute force manner. OverrideFieldData.provider_classes = None # pylint: disable=protected-access for block in iter_blocks(course): block._field_data = OverrideFieldData.wrap(coach, block._field_data) new_cache = {'tabs': [], 'discussion_topics': []} if 'grading_policy' in block._field_data_cache: new_cache['grading_policy'] = block._field_data_cache[ 'grading_policy'] block._field_data_cache = new_cache def cleanup_provider_classes(): """ After everything is done, clean up by un-doing the change to the OverrideFieldData object that is done during the wrap method. """ OverrideFieldData.provider_classes = None self.addCleanup(cleanup_provider_classes) patch_context = patch('ccx.views.get_course_by_id') get_course = patch_context.start() get_course.return_value = course self.addCleanup(patch_context.stop) override_field_for_ccx( ccx, course, 'grading_policy', { 'GRADER': [{ 'drop_count': 0, 'min_count': 2, 'short_label': 'HW', 'type': 'Homework', 'weight': 1 }], 'GRADE_CUTOFFS': { 'Pass': 0.75 }, }) override_field_for_ccx(ccx, sections[-1], 'visible_to_staff_only', True)