def test_cert_generation_on_passing_instructor_paced(self):
     with mock.patch(
         'lms.djangoapps.certificates.signals.generate_certificate.apply_async',
         return_value=None
     ) as mock_generate_certificate_apply_async:
         with waffle.waffle().override(waffle.INSTRUCTOR_PACED_ONLY, active=True):
             grade_factory = CourseGradeFactory()
             with mock_get_score(0, 2):
                 grade_factory.update(self.user, self.ip_course)
                 mock_generate_certificate_apply_async.assert_not_called(
                     student=self.user,
                     course_key=self.ip_course.id
                 )
             with mock_get_score(1, 2):
                 grade_factory.update(self.user, self.ip_course)
                 mock_generate_certificate_apply_async.assert_called(
                     student=self.user,
                     course_key=self.ip_course.id
                 )
             # Certs are not re-fired after passing
             with mock_get_score(2, 2):
                 grade_factory.update(self.user, self.ip_course)
                 mock_generate_certificate_apply_async.assert_not_called(
                     student=self.user,
                     course_key=self.ip_course.id
                 )
Example #2
0
    def test_generate_code_success_with_passport(self, post):
        """
            test views.generate_code(request) success process
        """
        CorfoCodeInstitution.objects.create(id_institution=3094)
        try:
            from unittest.case import SkipTest
            from uchileedxlogin.models import EdxLoginUser
            EdxLoginUser.objects.create(user=self.student, run='P09472337K')
        except ImportError:
            self.skipTest("import error uchileedxlogin")

        id_content = 200
        post_data = {
                'Data': 0,
                'Message': None,
                'Status': 0,
                'Success': True
            }
        resp_data = {
            "access_token": "IE742SAsEMadiliCt1w582TMnvj98aDyS6L7BXSFP84vto914p77nX",
            "token_type": "Bearer",
            "expires_in": 3599,
            "scope": "resource.READ"
        }
        post.side_effect = [namedtuple("Request", ["status_code", "json"])(200, lambda:resp_data) ,namedtuple("Request", ["status_code", "json"])(200, lambda:post_data)]
        with mock_get_score(3, 4):
            self.grade_factory.update(self.student, self.course, force_update_subsections=True)
        with mock_get_score(3, 4):
            data = generate_code(self.student, str(self.course.id), 3093, id_content)
            self.assertEqual(data['result'], 'success')
            corfouser = CorfoCodeUser.objects.get(user=self.student, mapping_content__id_content=id_content)
            self.assertEqual(data['code'], corfouser.code)
            self.assertTrue(corfouser.corfo_save)
Example #3
0
    def test_generate_code_request_validate_no_id_institution(self, post):
        """
            test views.generate_code(request) when post validate without id_institution
        """
        try:
            from unittest.case import SkipTest
            from uchileedxlogin.models import EdxLoginUser
            EdxLoginUser.objects.create(user=self.student, run='009472337K')
        except ImportError:
            self.skipTest("import error uchileedxlogin")

        id_content = 200
        post_data = {"Message":"An error has occurred."}
        resp_data = {
            "access_token": "IE742SAsEMadiliCt1w582TMnvj98aDyS6L7BXSFP84vto914p77nX",
            "token_type": "Bearer",
            "expires_in": 3599,
            "scope": "resource.READ"
        }
        post.side_effect = [namedtuple("Request", ["status_code", "json"])(200, lambda:resp_data), namedtuple("Request", ["status_code", "json"])(200, lambda:post_data)]
        with mock_get_score(3, 4):
            self.grade_factory.update(self.student, self.course, force_update_subsections=True)
        with mock_get_score(3, 4):
            data = generate_code(self.student, str(self.course.id), 3093, id_content)
            self.assertEqual(data['result'], 'error')
            self.assertEqual(data['status'], 3)
            mapp_content = CorfoCodeMappingContent.objects.get(id_content=id_content)
            corfouser = CorfoCodeUser.objects.get(user=self.student, mapping_content=mapp_content)
            self.assertFalse(corfouser.corfo_save)
            self.assertTrue(corfouser.code != '')
Example #4
0
 def test_get_user_grade(self):
     """
         Verify method get_user_grade() work correctly
     """
     with mock_get_score(1, 4):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
     with mock_get_score(1, 4):
         percent = GradeUcursosView().get_user_grade(self.student, self.course.id, 'gradeucursos_total', False)
         self.assertEqual(percent, {'Prom':0.25})
Example #5
0
 def test_user_course_passed(self):
     """
         Verify method user_course_passed() work correctly
     """
     with mock_get_score(1, 4):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
     with mock_get_score(1, 4):
         self.xblock.scope_ids.user_id = self.student.id
         passed = self.xblock.user_course_passed()
         self.assertFalse(passed)
Example #6
0
 def test_user_course_passed(self):
     """
         Verify method user_course_passed() work correctly
     """
     with mock_get_score(1, 4):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
     with mock_get_score(1, 4):
         passed, percent = user_course_passed(self.student, self.course.id)            
         self.assertEqual(percent, 0.25)
         self.assertFalse(passed)
Example #7
0
    def test_block_generate_code_with_passport(self, post):
        """
            Verify generate_code() is working whern user have passport
        """
        try:
            from unittest.case import SkipTest
            from uchileedxlogin.models import EdxLoginUser
            EdxLoginUser.objects.create(user=self.student, run='P009472337K')
        except ImportError:
            self.skipTest("import error uchileedxlogin")

        request = TestRequest()
        request.method = 'POST'
        self.xblock.xmodule_runtime.user_is_staff = True
        data = json.dumps({'display_name': 'testname', "id_content": '200', "content": 'testtest', 'display_title': 'testtitle'})
        request.body = data.encode()
        response = self.xblock.studio_submit(request)
        self.assertEqual(self.xblock.display_name, 'testname')
        self.assertEqual(self.xblock.display_title, 'testtitle')
        self.assertEqual(self.xblock.id_content, 200)
        self.assertEqual(self.xblock.id_institution, 3093)
        self.assertEqual(self.xblock.content, 'testtest')

        CorfoCodeInstitution.objects.create(id_institution=self.xblock.id_institution)
        post_data = {
                'Data': 0,
                'Message': None,
                'Status': 0,
                'Success': True
            }
        resp_data = {
            "access_token": "IE742SAsEMadiliCt1w582TMnvj98aDyS6L7BXSFP84vto914p77nX",
            "token_type": "Bearer",
            "expires_in": 3599,
            "scope": "resource.READ"
        }
        post.side_effect = [namedtuple("Request", ["status_code", "json"])(200, lambda:resp_data) ,namedtuple("Request", ["status_code", "json"])(200, lambda:post_data)]
        with mock_get_score(3, 4):
            self.grade_factory.update(self.student, self.course, force_update_subsections=True)
        with mock_get_score(3, 4):
            request = TestRequest()
            request.method = 'POST'
            self.xblock.xmodule_runtime.user_is_staff = False
            self.xblock.scope_ids.user_id = self.student.id
            data = json.dumps({})
            request.body = data.encode()
            response = self.xblock.generate_code(request)
            data = json.loads(response._app_iter[0].decode())
            self.assertEqual(data['result'], 'success')
            corfouser = CorfoCodeUser.objects.get(user=self.student, mapping_content__id_content=self.xblock.id_content)
            self.assertEqual(data['code'], corfouser.code)
            self.assertTrue(corfouser.corfo_save)
Example #8
0
 def test_generate_code_request_user_with_code(self):
     """
         test views.generate_code(request) when user already have code
     """
     id_content = 200
     mapp_content = CorfoCodeMappingContent.objects.get(id_content=id_content)
     corfouser = CorfoCodeUser.objects.create(user=self.student, mapping_content=mapp_content, code='U1CODASDFGH', corfo_save=True)
     with mock_get_score(3, 4):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
     with mock_get_score(3, 4):
         data = generate_code(self.student, str(self.course.id), 3093, id_content)
         self.assertEqual(data['result'], 'success')
         self.assertEqual(data['code'], corfouser.code)
Example #9
0
 def test_student_view_user_passed_course_without_code(self):
     """
         Verify context in student_view when user has passed the course and dont have code
     """
     with mock_get_score(3, 4):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
     with mock_get_score(3, 4):
         self.xblock.scope_ids.user_id = self.student.id
         response = self.xblock.get_context()
         self.assertEqual(response['passed'], True)
         self.assertEqual(response['code'], '')
         self.assertEqual(response['user_rut'], '')
         self.assertEqual(response['corfo_save'], False)
Example #10
0
 def test_gradeucursos_post_from_instructor_tab_is_resumen(self):
     """
         Test gradeucursos post from instructor tab normal process with is_resumen params
     """
     self.skipTest("disabled temporarily")
     with mock_get_score(1, 2):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
         self.grade_factory.update(self.student_2, self.course, force_update_subsections=True)
     try:
         from uchileedxlogin.models import EdxLoginUser
         EdxLoginUser.objects.create(user=self.student, run='09472337K')
     except ImportError:
         self.skipTest("import error uchileedxlogin")
     task_input = {
         'grade_type': 'seven_scale',
         'course_id': str(self.course.id),
         'instructor_tab': True,
         'assig_type': 'Homework',
         'is_resumen': True
     }
     with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'):
         result = task_get_data(
             None, None, self.course.id,
             task_input, 'EOL_GRADE_UCURSOS'
         )
     report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD')
     report_csv_filename = report_store.links_for(self.course.id)[0][0]
     report_path = report_store.path_to(self.course.id, report_csv_filename)
     self.assertTrue('_notas_estudiantes_' in report_csv_filename)
     self.assertTrue('_notas_estudiantes_' in report_path)
Example #11
0
    def test_get_subsection_grade_percentage_with_override(self):
        user = self.request.user
        subsection_key = self.sequence.location

        with mock_get_score(3, 3):
            # this update() call creates a persistent grade
            self.subsection_grade_factory.update(self.sequence)

            # there should only be one persistent grade
            persistent_grade = PersistentSubsectionGrade.objects.first()

            PersistentSubsectionGradeOverride.update_or_create_override(
                UserFactory(
                ),  # it doesn't matter to us who created the override
                persistent_grade,
                earned_graded_override=0,
                earned_all_override=0,
                possible_graded_override=3,
                feature=GradeOverrideFeatureEnum.gradebook,
            )

            # it's important that we stay in the mock_get_score() context here,
            # since get_subsection_grade_percentage() creates its own SubsectionGradeFactory,
            # which will in turn make calls to get_score().
            grade_percentage = gating_api.get_subsection_grade_percentage(
                subsection_key, user)
            assert 0 == grade_percentage
Example #12
0
 def test_generate_code_request_fail_token(self, post):
     """
         test views.generate_code(request) when get toket failed
     """
     id_content = 200
     post.side_effect = [namedtuple("Request", ["status_code"])(400)]
     with mock_get_score(3, 4):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
     with mock_get_score(3, 4):
         data = generate_code(self.student, str(self.course.id), 3093, id_content)
         self.assertEqual(data['result'], 'error')
         self.assertEqual(data['status'], 1)
         mapp_content = CorfoCodeMappingContent.objects.get(id_content=id_content)
         corfouser = CorfoCodeUser.objects.get(user=self.student, mapping_content=mapp_content)
         self.assertFalse(corfouser.corfo_save)
         self.assertTrue(corfouser.code != '')
Example #13
0
 def test_student_view_user_passed_course_with_corfo_save(self):
     """
         Verify context in student_view when user has passed the course and have corfo_save
     """
     mapp_content = CorfoCodeMappingContent.objects.get(id_content=200, content='testtest')
     corfouser = CorfoCodeUser.objects.create(user=self.student, mapping_content=mapp_content, code='U1CODASDFGH', corfo_save=True)
     with mock_get_score(3, 4):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
     with mock_get_score(3, 4):
         self.xblock.scope_ids.user_id = self.student.id
         self.xblock.id_content = 200
         response = self.xblock.get_context()
         self.assertEqual(response['passed'], True)
         self.assertEqual(response['code'], corfouser.code)
         self.assertEqual(response['user_rut'], '')
         self.assertEqual(response['corfo_save'], True)
Example #14
0
    def test_get_subsection_grade_percentage_with_override(self):
        user = self.request.user
        subsection_key = self.sequence.location

        with mock_get_score(3, 3):
            # this update() call creates a persistent grade
            self.subsection_grade_factory.update(self.sequence)

            # there should only be one persistent grade
            persistent_grade = PersistentSubsectionGrade.objects.first()

            PersistentSubsectionGradeOverride.update_or_create_override(
                UserFactory(),  # it doesn't matter to us who created the override
                persistent_grade,
                earned_graded_override=0,
                earned_all_override=0,
                possible_graded_override=3,
                feature=PersistentSubsectionGradeOverrideHistory.GRADEBOOK,
            )

            # it's important that we stay in the mock_get_score() context here,
            # since get_subsection_grade_percentage() creates its own SubsectionGradeFactory,
            # which will in turn make calls to get_score().
            grade_percentage = gating_api.get_subsection_grade_percentage(subsection_key, user)
            assert 0 == grade_percentage
Example #15
0
 def test_gradeucursos_post_data_researcher(self):
     """
         Test gradeucursos post normal process with data researcher role
     """
     with mock_get_score(1, 2):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
         self.grade_factory.update(self.student_2, self.course, force_update_subsections=True)
     try:
         from uchileedxlogin.models import EdxLoginUser
         EdxLoginUser.objects.create(user=self.student, run='09472337K')
     except ImportError:
         self.skipTest("import error uchileedxlogin")
     post_data = {
         'grade_type': 'seven_scale',
         'curso': str(self.course.id)
     }
     #grade cutoff 50%
     response = self.client_data_researcher.post(reverse('gradeucursos-export:data'), post_data)
     r = json.loads(response._container[0].decode())
     self.assertEqual(response.status_code, 200)
     self.assertEqual(r['status'] , 'Generating')
     response2 = self.client_data_researcher.post(reverse('gradeucursos-export:data'), post_data)
     r2 = json.loads(response2._container[0].decode())
     self.assertEqual(response2.status_code, 200)
     self.assertEqual(r2['status'] , 'Generated')
     report_grade, _ = GradeUcursosView().get_grade_report(post_data['curso'], post_data['grade_type'], 'gradeucursos_total', False)
     self.assertTrue(report_grade is not None)
     self.assertEqual(len(report_grade), 2)
     self.assertEqual(report_grade[0], ['9472337-K', self.student.username, '', {'Prom':4.0}])
     obs = 'Usuario {} no tiene rut asociado en la plataforma.'.format(self.student_2.username)
     self.assertEqual(report_grade[1], ['', self.student_2.username, obs, {'Prom':4.0}])
Example #16
0
 def test_compute(self):
     """
     Assuming the underlying score reporting methods work, test that the score is calculated properly.
     """
     with mock_get_score(1, 2):
         grade = self.subsection_grade_factory.create(self.sequence)
     self.assertEqual(grade.all_total.earned, 1)
     self.assertEqual(grade.all_total.possible, 2)
Example #17
0
 def test_compute(self):
     """
     Assuming the underlying score reporting methods work, test that the score is calculated properly.
     """
     with mock_get_score(1, 2):
         grade = self.subsection_grade_factory.create(self.sequence)
     self.assertEqual(grade.all_total.earned, 1)
     self.assertEqual(grade.all_total.possible, 2)
Example #18
0
 def test_compute(self):
     """
     Assuming the underlying score reporting methods work, test that the score is calculated properly.
     """
     grade = self.subsection_grade_factory.create(self.sequence, self.course_structure, self.course)
     with mock_get_score(1, 2):
         # The final 2 parameters are only passed through to our mocked-out get_score method
         grade.compute(self.request.user, self.course_structure, None, None)
     self.assertEqual(grade.all_total.earned, 1)
     self.assertEqual(grade.all_total.possible, 2)
 def test_grade(self, grade, result):
     """
     Test that the user gets her grade in case she answered tests with an insufficient score.
     """
     with mock_get_score(*grade):
         resp = self.client.get(self.get_url(self.student.username))
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
     expected_data = {"username": self.student.username, "course_key": str(self.course_key)}
     expected_data.update(result)
     self.assertEqual(resp.data, [expected_data])  # pylint: disable=no-member
Example #20
0
 def test_cert_generation_on_passing_self_paced(self):
     with mock.patch(
             'lms.djangoapps.certificates.signals.generate_certificate.apply_async',
             return_value=None) as mock_generate_certificate_apply_async:
         with waffle.waffle().override(waffle.SELF_PACED_ONLY, active=True):
             grade_factory = CourseGradeFactory()
             with mock_get_score(0, 2):
                 grade_factory.update(self.user, self.course)
                 mock_generate_certificate_apply_async.assert_not_called(
                     student=self.user, course_key=self.course.id)
             with mock_get_score(1, 2):
                 grade_factory.update(self.user, self.course)
                 mock_generate_certificate_apply_async.assert_called(
                     student=self.user, course_key=self.course.id)
             # Certs are not re-fired after passing
             with mock_get_score(2, 2):
                 grade_factory.update(self.user, self.course)
                 mock_generate_certificate_apply_async.assert_not_called(
                     student=self.user, course_key=self.course.id)
Example #21
0
 def test_compute(self):
     """
     Assuming the underlying score reporting methods work, test that the score is calculated properly.
     """
     grade = self.subsection_grade_factory.create(self.sequence, self.course_structure, self.course)
     with mock_get_score(1, 2):
         # The final 2 parameters are only passed through to our mocked-out get_score method
         grade.compute(self.request.user, self.course_structure, None, None)
     self.assertEqual(grade.all_total.earned, 1)
     self.assertEqual(grade.all_total.possible, 2)
Example #22
0
    def test_get_subsection_grade_percentage(self):
        user = self.request.user
        subsection_key = self.sequence.location

        with mock_get_score(3, 3):
            # this update() call creates a persistent grade
            self.subsection_grade_factory.update(self.sequence)

            # it's important that we stay in the mock_get_score() context here,
            # since get_subsection_grade_percentage() creates its own SubsectionGradeFactory,
            # which will in turn make calls to get_score().
            grade_percentage = gating_api.get_subsection_grade_percentage(subsection_key, user)
            assert 100.0 == grade_percentage
Example #23
0
 def test_generate_code_request_user_no_rut(self, post):
     """
         test views.generate_code(request) when user dont have edxloginuser.rut
     """
     id_content = 200
     resp_data = {
         "access_token": "IE742SAsEMadiliCt1w582TMnvj98aDyS6L7BXSFP84vto914p77nX",
         "token_type": "Bearer",
         "expires_in": 3599,
         "scope": "resource.READ"
     }
     post.side_effect = [namedtuple("Request", ["status_code", "json"])(200, lambda:resp_data)]
     with mock_get_score(3, 4):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
     with mock_get_score(3, 4):
         data = generate_code(self.student, str(self.course.id), 3093, id_content)
         self.assertEqual(data['result'], 'error')
         self.assertEqual(data['status'], 2)
         mapp_content = CorfoCodeMappingContent.objects.get(id_content=id_content)
         corfouser = CorfoCodeUser.objects.get(user=self.student, mapping_content=mapp_content)
         self.assertFalse(corfouser.corfo_save)
         self.assertTrue(corfouser.code != '')
Example #24
0
 def test_grade(self, grade, result):
     """
     Test that the user gets her grade in case she answered tests with an insufficient score.
     """
     with mock_get_score(*grade):
         resp = self.client.get(self.get_url(self.student.username))
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
     expected_data = {
         'username': self.student.username,
         'course_key': str(self.course_key),
     }
     expected_data.update(result)
     self.assertEqual(resp.data, [expected_data])  # pylint: disable=no-member
Example #25
0
 def setUp(self):
     super(TestGradesBulkAPIView, self).setUp()
     self.client.login(username=self.global_staff.username, password=self.password)
     self.course_structure = get_course_blocks(self.global_staff, self.course.location)
     self.subsection_grade_factory = SubsectionGradeFactory(self.global_staff, self.course, self.course_structure)
     
     
     with mock_get_score(1, 2):
         self.created_grade = CreateSubsectionGrade(
                 self.section,
                 self.course_structure,
                 self.subsection_grade_factory._submissions_scores,
                 self.subsection_grade_factory._csm_scores,
             )
Example #26
0
 def test_gradeucursos_post_from_instructor_tab_is_resumen_data(self):
     """
         Test gradeucursos post from instructor tab normal process with is_resumen params
     """
     with mock_get_score(1, 2):
         self.grade_factory.update(self.student, self.course, force_update_subsections=True)
         self.grade_factory.update(self.student_2, self.course, force_update_subsections=True)
     try:
         from uchileedxlogin.models import EdxLoginUser
         EdxLoginUser.objects.create(user=self.student, run='09472337K')
     except ImportError:
         self.skipTest("import error uchileedxlogin")
     post_data = {
         'grade_type': 'seven_scale',
         'curso': str(self.course.id)
     }
     #grade cutoff 50%
     report_grade, headers = GradeUcursosView().get_grade_report(post_data['curso'], post_data['grade_type'], 'gradeucursos_total', True)
     self.assertTrue(report_grade is not None)
     self.assertEqual(len(report_grade), 2)
     result = OrderedDict([('Homework', 50.0), ('NoCredit', 0.0), ('Prom', 4.0)])
     self.assertEqual(report_grade[0], ['9472337-K', self.student.username, '', result])
     obs = 'Usuario {} no tiene rut asociado en la plataforma.'.format(self.student_2.username)
     self.assertEqual(report_grade[1], ['', self.student_2.username, obs, result])