コード例 #1
0
    def test_student_user_view_with_false_past_due_form_completed(
            self, get, post):
        """
            Test student view when section is finished
        """
        from lms.djangoapps.courseware.models import StudentModule
        get.side_effect = [namedtuple("Request", ["status_code", "text"])(
            200, json.dumps({"session": {"api_token": "test_token"}}))]
        post.side_effect = [
            namedtuple(
                "Request", [
                    "status_code", "headers"])(
                200, {
                    'Set-Cookie': 'Domain=quilgo.com; Path=/, connect.sid=test;'}), namedtuple(
                        "Request", [
                            "status_code", "text"])(
                                200, json.dumps(
                                    {
                                        "links": [
                                            {
                                                "id": 1, "hash": "testhash", "label": "test"}]}))]

        self.xblock.xmodule_runtime.user_is_staff = False
        self.xblock.scope_ids.user_id = self.student.id

        module = StudentModule(
            module_state_key=self.xblock.location,
            student_id=self.student.id,
            course_id=self.course.id,
            state='{"id_link": "1", "score": "2", "link": "testhash", "name_link": "test", "id_form": "11223344", "expired": "2020-05-11T15:37:55.000Z"}')
        module.save()
        with mock.patch('eoltimify.eoltimify.EolTimifyXBlock.is_past_due', return_value=True):
            response = self.xblock.student_view()
        self.assertTrue('id="expired"' in response.content)
        self.assertTrue('<label>Puntaje: 2</label>' in response.content)
コード例 #2
0
 def test_xblockcompletion_get_resumen(self):
     """
     test to generate course survey report
     and then test the report authenticity.
     """
     from lms.djangoapps.courseware.models import StudentModule
     data = {'format': True, 'course': str(self.course.id), 'base_url':'this_is_a_url'}
     task_input = {'data': data }
     module = StudentModule(
         module_state_key=self.items[0].location,
         student=self.student,
         course_id=self.course.id,
         module_type='problem',
         state='{"score": {"raw_earned": 0, "raw_possible": 3}, "seed": 1, "attempts":1}')
     module.save()
     with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'):
         result = generate(
             None, None, self.course.id,
             task_input, 'EOL_Xblock_Completion'
         )
     report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD')
     header_row = ",".join(['Titulo', 'Username', 'Email', 'Run', 'Seccion', 'SubSeccion', 'Unidad', 'Intentos', 'Pts Ganados', 'Pts Posibles', 'Url', 'block_id'])
     student1_row = ",".join([
         self.items[0].display_name,
         self.student.username,
         self.student.email,
         '',
         '1.' + self.chapter.display_name,
         '1.1.' + self.section.display_name,
         '1.1.1.' + self.subsection.display_name,
         '1','0','3'
     ])
     expected_data = [header_row, student1_row]
     self._verify_csv_file_report(report_store, expected_data)
コード例 #3
0
    def test_student_user_view_get_1_400(self, get, post):
        """
            Test student view when get api-key fail
        """
        from lms.djangoapps.courseware.models import StudentModule
        get.side_effect = [namedtuple("Request", ["status_code", "text", "content"])(
            400, json.dumps({"session": {"api_token": "test_token"}}), 'error')]
        post.side_effect = [
            namedtuple(
                "Request", [
                    "status_code", "headers"])(
                200, {
                    'Set-Cookie': 'Domain=quilgo.com; Path=/, connect.sid=test;'}), namedtuple(
                        "Request", [
                            "status_code", "text"])(
                                200, json.dumps(
                                    {
                                        "links": [
                                            {
                                                "id": 1, "hash": "testhash", "label": "test"}]}))]

        self.xblock.idform = "11223344"
        self.xblock.xmodule_runtime.user_is_staff = False
        self.xblock.scope_ids.user_id = self.student.id

        module = StudentModule(
            module_state_key=self.xblock.location,
            student_id=self.student.id,
            course_id=self.course.id,
            state='{}')
        module.save()

        response = self.xblock.student_view()

        self.assertTrue('Sin Datos' in response.content)
コード例 #4
0
    def make_student(self, block, name, make_state=True, **state):
        """
        Create a student along with submission state.
        """
        answer = {}
        module = None
        for key in ('sha1', 'mimetype', 'filename', 'finalized'):
            if key in state:
                answer[key] = state.pop(key)
        score = state.pop('score', None)

        with transaction.atomic():
            user = User(username=name, email='{}@example.com'.format(name))
            user.save()
            profile = UserProfile(user=user, name=name)
            profile.save()
            if make_state:
                module = StudentModule(module_state_key=block.location,
                                       student=user,
                                       course_id=self.course_id,
                                       state=json.dumps(state))
                module.save()

            anonymous_id = anonymous_id_for_user(user, self.course_id)
            item = StudentItem(student_id=anonymous_id,
                               course_id=self.course_id,
                               item_id=block.block_id,
                               item_type='sga')
            item.save()

            if answer:
                student_id = block.get_student_item_dict(anonymous_id)
                submission = submissions_api.create_submission(
                    student_id, answer)
                if score is not None:
                    submissions_api.set_score(submission['uuid'], score,
                                              block.max_score())
            else:
                submission = None

            self.addCleanup(item.delete)
            self.addCleanup(profile.delete)
            self.addCleanup(user.delete)

            if make_state:
                self.addCleanup(module.delete)
                return {
                    'module': module,
                    'item': item,
                    'submission': submission
                }

            return {'item': item, 'submission': submission}
コード例 #5
0
 def test_xblockcompletion_get_all_data(self, report):
     """
         Test xblockcompletion view all data
     """
     state_1 = {_("Answer ID"): 'answer_id',
         _("Question"): 'question_text',
         _("Answer"): 'answer_text',
         _("Correct Answer") : 'correct_answer_text'
         }
     state_2 = {_("Answer ID"): 'answer_id',
         _("Question"): 'question_text',
         _("Answer"): 'correct_answer_text',
         _("Correct Answer") : 'correct_answer_text'
         }
     generated_report_data = {self.student.username : [state_1,state_2,state_1]}               
     report.return_value = generated_report_data
     from lms.djangoapps.courseware.models import StudentModule
     data = {'format': False, 'course': str(self.course.id), 'base_url':'this_is_a_url'}
     task_input = {'data': data }
     module = StudentModule(
         module_state_key=self.items[0].location,
         student=self.student,
         course_id=self.course.id,
         module_type='problem',
         state='{"score": {"raw_earned": 1, "raw_possible": 3}, "seed": 1, "attempts": 1}')
     module.save()
     with patch('lms.djangoapps.instructor_task.tasks_helper.runner._get_current_task'):
         result = generate(
             None, None, self.course.id,
             task_input, 'EOL_Xblock_Completion'
         )
     report_store = ReportStore.from_config(config_name='GRADES_DOWNLOAD')
     header_row = ",".join(['Titulo', 'Username', 'Email', 'Run', 'Seccion', 'SubSeccion', 'Unidad', 'Pregunta', 'Respuesta Estudiante', 'Resp. Correcta', 'Intentos', 'Pts Ganados', 'Pts Posibles', 'Pts Total Componente', 'Url', 'block_id'])
     base_student_row = ",".join([
         self.items[0].display_name,
         self.student.username,
         self.student.email,
         '',
         '1.' + self.chapter.display_name,
         '1.1.' + self.section.display_name,
         '1.1.1.' + self.subsection.display_name
     ])
     student_row = base_student_row + ',question_text,answer_text,correct_answer_text,1,0,1.0,3'
     student_row2 = base_student_row + ',question_text,correct_answer_text,correct_answer_text,1,1.0,1.0,3'
     expected_data = [header_row, student_row, student_row2, student_row]
     self._verify_csv_file_report(report_store, expected_data)
コード例 #6
0
    def test_student_user_view_no_setting(self):
        """
            Verify student view if the xblock dont have user/password in settings
        """
        from lms.djangoapps.courseware.models import StudentModule
        self.xblock.idform = "11223344"
        self.xblock.xmodule_runtime.user_is_staff = False
        self.xblock.scope_ids.user_id = self.student.id

        module = StudentModule(
            module_state_key=self.xblock.location,
            student_id=self.student.id,
            course_id=self.course.id,
            state='{}')
        module.save()

        response = self.xblock.student_view()
        self.assertTrue('Sin Datos' in response.content)
コード例 #7
0
    def test_student_user_view_with_different_id_form(self, get, post):
        """
            Test student view when student already have student_module and if form is different
        """
        from lms.djangoapps.courseware.models import StudentModule
        get.side_effect = [namedtuple("Request",
                                      ["status_code",
                                       "text"])(200,
                                                json.dumps({"session": {"api_token": "test_token"}})),
                           namedtuple("Request",
                                      ["status_code",
                                       "text"])(200,
                                                json.dumps({"links": [{"id": 1,
                                                                    "hash": "testhash",
                                                                    "label": "test",
                                                                    "finishedAt": None}]}))]
        post.side_effect = [
            namedtuple(
                "Request", [
                    "status_code", "headers"])(
                200, {
                    'Set-Cookie': 'Domain=quilgo.com; Path=/, connect.sid=test;'}), namedtuple(
                        "Request", [
                            "status_code", "text"])(
                                200, json.dumps(
                                    {
                                        "links": [
                                            {
                                                "id": 1, "hash": "testhash", "label": "test"}]}))]

        self.xblock.idform = "55667788"
        self.xblock.xmodule_runtime.user_is_staff = False
        self.xblock.scope_ids.user_id = self.student.id

        module = StudentModule(
            module_state_key=self.xblock.location,
            student_id=self.student.id,
            course_id=self.course.id,
            state='{"id_link": "1", "score": "Sin Registros", "link": "testhash", "name_link": "test", "id_form": "11223344", "expired": null}')
        module.save()

        response = self.xblock.student_view()
        self.assertTrue(
            'href=https://quilgo.com/link/testhash ' in response.content)
コード例 #8
0
    def test_student_user_view(self, get, post):
        """
            Test student view normal process
        """
        from lms.djangoapps.courseware.models import StudentModule
        get.side_effect = [namedtuple("Request", ["status_code", "text"])(
            200, json.dumps({"session": {"api_token": "test_token"}}))]
        post.side_effect = [
            namedtuple(
                "Request", [
                    "status_code", "headers"])(
                200, {
                    'Set-Cookie': 'Domain=quilgo.com; Path=/, connect.sid=test;'}), namedtuple(
                        "Request", [
                            "status_code", "text"])(
                                200, json.dumps(
                                    {
                                        "links": [
                                            {
                                                "id": 1, "hash": "testhash", "label": "test"}]}))]

        self.xblock.idform = "11223344"
        self.xblock.xmodule_runtime.user_is_staff = False
        self.xblock.scope_ids.user_id = self.student.id

        module = StudentModule(
            module_state_key=self.xblock.location,
            student_id=self.student.id,
            course_id=self.course.id,
            state='{}')
        module.save()

        response = self.xblock.student_view()
        state = StudentModule.objects.get(pk=module.id)
        self.assertEqual(
            json.loads(state.state),
            json.loads('{"name_link": "test", "id_link": "1", "score": "Sin Registros", "link": "testhash", "id_form": "11223344", "expired": null}'))
        self.assertTrue(
            'href=https://quilgo.com/link/testhash ' in response.content)
コード例 #9
0
    def test_staff_user_view_with_datetime_late(self, get, post):
        """
            Test staff view when finished datetime section is already finished
        """
        from lms.djangoapps.courseware.models import StudentModule
        request = TestRequest()
        request.method = 'POST'

        get.side_effect = [namedtuple("Request",
                                      ["status_code",
                                       "text"])(200,
                                                json.dumps({"session": {"api_token": "test_token"}})),
                           namedtuple("Request",
                                      ["status_code",
                                       "text"])(200,
                                                json.dumps({"links": [{"id": 1,
                                                                    "score": "1",
                                                                    "finishedAt": "2020-05-11T15:37:55.000Z"},
                                                                    {"id": 2,
                                                                    "score": None,
                                                                    "finishedAt": None}]}))]
        post.side_effect = [
            namedtuple(
                "Request", [
                    "status_code", "headers"])(
                200, {
                    'Set-Cookie': 'Domain=quilgo.com; Path=/, connect.sid=test;'}), namedtuple(
                        "Request", [
                            "status_code", "text"])(
                                200, json.dumps(
                                    {
                                        "links": [
                                            {
                                                "id": 1, "hash": "testhash", "label": "test"}]}))]

        self.xblock.idform = "11223344"
        self.xblock.xmodule_runtime.user_is_staff = True
        self.xblock.scope_ids.user_id = self.staff_user.id
        data = b'{}'
        request.body = data

        module = StudentModule(
            module_state_key=self.xblock.location,
            student_id=self.student.id,
            course_id=self.course.id,
            state='{"id_link": "1", "score": "Sin Registros", "link": "testhash", "name_link": "test", "id_form": "11223344", "expired": "2020-05-11T15:37:55.000Z"}')
        module.save()

        module2 = StudentModule(
            module_state_key=self.xblock.location,
            student_id=self.staff_user.id,
            course_id=self.course.id,
            state='{"id_link": "2", "score": "Sin Registros", "link": "testhash", "name_link": "test", "id_form": "11223344", "expired": null}')
        module2.save()
        from dateutil.parser import parse
        with mock.patch('eoltimify.eoltimify.EolTimifyXBlock.expired_date', return_value=parse("2020-05-11T15:36:55.000Z")):
            response = self.xblock.show_score(request)

        data = json.loads(response._app_iter[0].decode())
        list_student = [[self.staff_user.id,
                         'staff_user',
                         '*****@*****.**',
                         'test',
                         'Sin Registros',
                         'Sin Registros'],
                        [self.student.id,
                         'student',
                         '*****@*****.**',
                         'test',
                         '1',
                         'Si']]
        self.assertEqual(data["list_student"], list_student)
        self.assertEqual(data["result"], "success")