当前位置: 首页>>代码示例>>Python>>正文


Python api.create_submission函数代码示例

本文整理汇总了Python中submissions.api.create_submission函数的典型用法代码示例。如果您正苦于以下问题:Python create_submission函数的具体用法?Python create_submission怎么用?Python create_submission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了create_submission函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_top_submissions_from_cache

    def test_get_top_submissions_from_cache(self):
        student_1 = api.create_submission(STUDENT_ITEM, "Hello World")
        student_2 = api.create_submission(STUDENT_ITEM, "Hello World")
        student_3 = api.create_submission(STUDENT_ITEM, "Hello World")

        api.set_score(student_1['uuid'], 8, 10)
        api.set_score(student_2['uuid'], 4, 10)
        api.set_score(student_3['uuid'], 2, 10)

        # The first call should hit the database
        with self.assertNumQueries(1):
            scores = api.get_top_submissions(
                STUDENT_ITEM["course_id"],
                STUDENT_ITEM["item_id"],
                STUDENT_ITEM["item_type"], 2,
                use_cache=True,
                read_replica=False
            )
            self.assertEqual(scores, [
                { "content": "Hello World", "score": 8 },
                { "content": "Hello World", "score": 4 },
            ])

        # The second call should use the cache
        with self.assertNumQueries(0):
            cached_scores = api.get_top_submissions(
                STUDENT_ITEM["course_id"],
                STUDENT_ITEM["item_id"],
                STUDENT_ITEM["item_type"], 2,
                use_cache=True,
                read_replica=False
            )
            self.assertEqual(cached_scores, scores)
开发者ID:AgentK1729,项目名称:edx-submissions,代码行数:33,代码来源:test_api.py

示例2: test_staff_debug_student_info_file_download_url_error

    def test_staff_debug_student_info_file_download_url_error(self, xblock):
        # Simulate that we are course staff
        xblock.xmodule_runtime = self._create_mock_runtime(
            xblock.scope_ids.usage_id, True, False, "Bob"
        )
        xblock.runtime._services['user'] = NullUserService()

        bob_item = STUDENT_ITEM.copy()
        bob_item["item_id"] = xblock.scope_ids.usage_id

        # Create an image submission for Bob
        sub_api.create_submission(bob_item, {
            'text': "Bob Answer",
            'file_key': "test_key"
        })

        # Mock the file upload API to simulate an error
        with patch("openassessment.xblock.staff_info_mixin.file_api.get_download_url") as file_api_call:
            file_api_call.side_effect = FileUploadInternalError("Error!")
            __, context = xblock.get_student_info_path_and_context("Bob")

            # Expect that the page still renders, but without the image url
            self.assertIn('submission', context)
            self.assertNotIn('image_url', context['submission'])

            # Check the fully rendered template
            payload = urllib.urlencode({"student_username": "Bob"})
            resp = self.request(xblock, "render_student_info", payload)
            self.assertIn("Bob Answer", resp)
开发者ID:eestay,项目名称:edx-ora2,代码行数:29,代码来源:test_staff_info.py

示例3: test_reset_different_student_item

    def test_reset_different_student_item(self, changed):
        # Create a submissions for two students
        submission = sub_api.create_submission(self.STUDENT_ITEM, "test answer")
        sub_api.set_score(submission["uuid"], 1, 2)

        other_student = copy.copy(self.STUDENT_ITEM)
        other_student.update(changed)
        submission = sub_api.create_submission(other_student, "other test answer")
        sub_api.set_score(submission["uuid"], 3, 4)

        # Reset the score for the first student
        sub_api.reset_score(
            self.STUDENT_ITEM["student_id"], self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["item_id"]
        )

        # The first student's scores should be reset
        self.assertIs(sub_api.get_score(self.STUDENT_ITEM), None)
        scores = sub_api.get_scores(self.STUDENT_ITEM["course_id"], self.STUDENT_ITEM["student_id"])
        self.assertNotIn(self.STUDENT_ITEM["item_id"], scores)

        # But the second student should still have a score
        score = sub_api.get_score(other_student)
        self.assertEqual(score["points_earned"], 3)
        self.assertEqual(score["points_possible"], 4)
        scores = sub_api.get_scores(other_student["course_id"], other_student["student_id"])
        self.assertIn(other_student["item_id"], scores)
开发者ID:AgentK1729,项目名称:edx-submissions,代码行数:26,代码来源:test_reset_score.py

示例4: test_staff_debug_student_info_full_workflow

    def test_staff_debug_student_info_full_workflow(self, xblock):
        # Simulate that we are course staff
        xblock.xmodule_runtime = self._create_mock_runtime(
            xblock.scope_ids.usage_id, True, False, "Bob"
        )

        # Commonly chosen options for assessments
        options_selected = {
            "Ideas": "Good",
            "Content": "Poor",
        }

        criterion_feedback = {
            "Ideas": "Dear diary: Lots of creativity from my dream journal last night at 2 AM,",
            "Content": "Not as insightful as I had thought in the wee hours of the morning!"
        }

        overall_feedback = "I think I should tell more people about how important worms are for the ecosystem."

        bob_item = STUDENT_ITEM.copy()
        bob_item["item_id"] = xblock.scope_ids.usage_id

        # Create a submission for Bob, and corresponding workflow.
        submission = sub_api.create_submission(bob_item, {'text':"Bob Answer"})
        peer_api.on_start(submission["uuid"])
        workflow_api.create_workflow(submission["uuid"], ['peer', 'self'])

        # Create a submission for Tim, and corresponding workflow.
        tim_item = bob_item.copy()
        tim_item["student_id"] = "Tim"
        tim_sub = sub_api.create_submission(tim_item, "Tim Answer")
        peer_api.on_start(tim_sub["uuid"])
        workflow_api.create_workflow(tim_sub["uuid"], ['peer', 'self'])

        # Bob assesses Tim.
        peer_api.get_submission_to_assess(submission['uuid'], 1)
        peer_api.create_assessment(
            submission["uuid"],
            STUDENT_ITEM["student_id"],
            options_selected, dict(), "",
            {'criteria': xblock.rubric_criteria},
            1,
        )

        # Bob assesses himself.
        self_api.create_assessment(
            submission['uuid'],
            STUDENT_ITEM["student_id"],
            options_selected,
            criterion_feedback,
            overall_feedback,
            {'criteria': xblock.rubric_criteria},
        )

        # Now Bob should be fully populated in the student info view.
        request = namedtuple('Request', 'params')
        request.params = {"student_id": "Bob"}
        # Verify that we can render without error
        resp = xblock.render_student_info(request)
        self.assertIn("bob answer", resp.body.lower())
开发者ID:ovnicraft,项目名称:edx-ora2,代码行数:60,代码来源:test_staff_info.py

示例5: test_staff_debug_student_info_peer_only

    def test_staff_debug_student_info_peer_only(self, xblock):
        # Simulate that we are course staff
        xblock.xmodule_runtime =  self._create_mock_runtime(
            xblock.scope_ids.usage_id, True, False, "Bob"
        )

        bob_item = STUDENT_ITEM.copy()
        bob_item["item_id"] = xblock.scope_ids.usage_id
        # Create a submission for Bob, and corresponding workflow.
        submission = sub_api.create_submission(bob_item, {'text':"Bob Answer"})
        peer_api.on_start(submission["uuid"])
        workflow_api.create_workflow(submission["uuid"], ['peer'])

        # Create a submission for Tim, and corresponding workflow.
        tim_item = bob_item.copy()
        tim_item["student_id"] = "Tim"
        tim_sub = sub_api.create_submission(tim_item, "Tim Answer")
        peer_api.on_start(tim_sub["uuid"])
        workflow_api.create_workflow(tim_sub["uuid"], ['peer', 'self'])

        # Bob assesses Tim.
        peer_api.get_submission_to_assess(submission['uuid'], 1)
        peer_api.create_assessment(
            submission["uuid"],
            STUDENT_ITEM["student_id"],
            ASSESSMENT_DICT['options_selected'], dict(), "",
            {'criteria': xblock.rubric_criteria},
            1,
        )

        # Now Bob should be fully populated in the student info view.
        path, context = xblock.get_student_info_path_and_context("Bob")
        self.assertEquals("Bob Answer", context['submission']['answer']['text'])
        self.assertIsNone(context['self_assessment'])
        self.assertEquals("openassessmentblock/staff_debug/student_info.html", path)
开发者ID:robertgerinlajoie,项目名称:edx-ora2,代码行数:35,代码来源:test_staff_info.py

示例6: upload_assignment

 def upload_assignment(self, request, suffix=''):
     # pylint: disable=unused-argument
     """
     Save a students submission file.
     """
     require(self.upload_allowed())
     upload = request.params['assignment']
     sha1 = _get_sha1(upload.file)
     upload.file.name = upload.file.name.replace(',','_')
     answer = {
         "sha1": sha1,
         "filename": upload.file.name,
         "mimetype": mimetypes.guess_type(upload.file.name)[0],
     }
     student_id = self.student_submission_id()
     submissions_api.create_submission(student_id, answer)
     path = self._file_storage_path(sha1, upload.file.name)
     if not default_storage.exists(path):
         default_storage.save(path, File(upload.file))
         
     #if student already have score, set recheck to true
     if self.score is not None:
         self.need_recheck = True
     
     return Response(json_body=self.student_state())
开发者ID:kursitet,项目名称:edx-sga,代码行数:25,代码来源:sga.py

示例7: test_get_scores

    def test_get_scores(self):
        student_item = copy.deepcopy(STUDENT_ITEM)
        student_item["course_id"] = "get_scores_course"

        student_item["item_id"] = "i4x://a/b/c/s1"
        s1 = api.create_submission(student_item, "Hello World")

        student_item["item_id"] = "i4x://a/b/c/s2"
        s2 = api.create_submission(student_item, "Hello World")

        student_item["item_id"] = "i4x://a/b/c/s3"
        s3 = api.create_submission(student_item, "Hello World")

        api.set_score(s1['uuid'], 3, 5)
        api.set_score(s1['uuid'], 4, 5)
        api.set_score(s1['uuid'], 2, 5)  # Should overwrite previous lines

        api.set_score(s2['uuid'], 0, 10)
        api.set_score(s3['uuid'], 4, 4)

        # Getting the scores for a user should never take more than one query
        with self.assertNumQueries(1):
            scores = api.get_scores(
                student_item["course_id"], student_item["student_id"]
            )
            self.assertEqual(
                scores,
                {
                    u"i4x://a/b/c/s1": (2, 5),
                    u"i4x://a/b/c/s2": (0, 10),
                    u"i4x://a/b/c/s3": (4, 4),
                }
            )
开发者ID:YoshidaKS,项目名称:edx-ora2,代码行数:33,代码来源:test_api.py

示例8: test_get_submissions

    def test_get_submissions(self):
        api.create_submission(STUDENT_ITEM, ANSWER_ONE)
        api.create_submission(STUDENT_ITEM, ANSWER_TWO)
        submissions = api.get_submissions(STUDENT_ITEM)

        self._assert_submission(submissions[1], ANSWER_ONE, 1, 1)
        self._assert_submission(submissions[0], ANSWER_TWO, 1, 2)
开发者ID:ctpad,项目名称:edx-tim,代码行数:7,代码来源:test_api.py

示例9: upload_assignment

 def upload_assignment(self, request, suffix=''):
     # pylint: disable=unused-argument, protected-access
     """
     Save a students submission file.
     """
     require(self.upload_allowed())
     user = self.get_real_user()
     require(user)
     upload = request.params['assignment']
     sha1 = get_sha1(upload.file)
     if self.file_size_over_limit(upload.file):
         raise JsonHandlerError(
             413, 'Unable to upload file. Max size limit is {size}'.format(
                 size=self.student_upload_max_size()
             )
         )
     # Uploading an assignment represents a change of state with this user in this block,
     # so we need to ensure that the user has a StudentModule record, which represents that state.
     self.get_or_create_student_module(user)
     answer = {
         "sha1": sha1,
         "filename": upload.file.name,
         "mimetype": mimetypes.guess_type(upload.file.name)[0],
         "finalized": False
     }
     student_item_dict = self.get_student_item_dict()
     submissions_api.create_submission(student_item_dict, answer)
     path = self.file_storage_path(sha1, upload.file.name)
     log.info("Saving file: %s at path: %s for user: %s", upload.file.name, path, user.username)
     if default_storage.exists(path):
         # save latest submission
         default_storage.delete(path)
     default_storage.save(path, File(upload.file))
     return Response(json_body=self.student_state())
开发者ID:mitodl,项目名称:edx-sga,代码行数:34,代码来源:sga.py

示例10: test_staff_debug_student_info_image_submission

    def test_staff_debug_student_info_image_submission(self, xblock):
        # Simulate that we are course staff
        xblock.xmodule_runtime = self._create_mock_runtime(
            xblock.scope_ids.usage_id, True, False, "Bob"
        )
        xblock.runtime._services['user'] = NullUserService()

        bob_item = STUDENT_ITEM.copy()
        bob_item["item_id"] = xblock.scope_ids.usage_id

        # Create an image submission for Bob
        sub_api.create_submission(bob_item, {
            'text': "Bob Answer",
            'file_key': "test_key"
        })

        # Mock the file upload API to avoid hitting S3
        with patch("openassessment.xblock.staff_info_mixin.file_api") as file_api:
            file_api.get_download_url.return_value = "http://www.example.com/image.jpeg"
            __, context = xblock.get_student_info_path_and_context("Bob")

            # Check that the right file key was passed to generate the download url
            file_api.get_download_url.assert_called_with("test_key")

            # Check the context passed to the template
            self.assertEquals('http://www.example.com/image.jpeg', context['submission']['image_url'])

            # Check the fully rendered template
            payload = urllib.urlencode({"student_username": "Bob"})
            resp = self.request(xblock, "render_student_info", payload)
            self.assertIn("http://www.example.com/image.jpeg", resp)
开发者ID:eestay,项目名称:edx-ora2,代码行数:31,代码来源:test_staff_info.py

示例11: test_get_top_submissions

    def test_get_top_submissions(self):
        student_1 = sub_api.create_submission(self.STUDENT_ITEM, "Hello World")
        student_2 = sub_api.create_submission(self.STUDENT_ITEM, "Hello World")
        student_3 = sub_api.create_submission(self.STUDENT_ITEM, "Hello World")

        sub_api.set_score(student_1['uuid'], 8, 10)
        sub_api.set_score(student_2['uuid'], 4, 10)
        sub_api.set_score(student_3['uuid'], 2, 10)

        # Use the read-replica
        with self.assertNumQueries(0):
            top_scores = sub_api.get_top_submissions(
                self.STUDENT_ITEM['course_id'],
                self.STUDENT_ITEM['item_id'],
                self.STUDENT_ITEM['item_type'], 2,
                read_replica=True
            )
            self.assertEqual(
                top_scores,
                [
                    {
                        'content': "Hello World",
                        'score': 8
                    },
                    {
                        'content': "Hello World",
                        'score': 4
                    },
                ]
            )
开发者ID:AgentK1729,项目名称:edx-submissions,代码行数:30,代码来源:test_read_replica.py

示例12: test_get_submissions

    def test_get_submissions(self):
        api.create_submission(STUDENT_ITEM, ANSWER_ONE)
        api.create_submission(STUDENT_ITEM, ANSWER_TWO)
        submissions = api.get_submissions(STUDENT_ITEM)

        student_item = self._get_student_item(STUDENT_ITEM)
        self._assert_submission(submissions[1], ANSWER_ONE, student_item.pk, 1)
        self._assert_submission(submissions[0], ANSWER_TWO, student_item.pk, 2)
开发者ID:YoshidaKS,项目名称:edx-ora2,代码行数:8,代码来源:test_api.py

示例13: test_get_scores

    def test_get_scores(self):
        student_item = copy.deepcopy(STUDENT_ITEM)
        student_item["course_id"] = "get_scores_course"

        student_item["item_id"] = "i4x://a/b/c/s1"
        s1 = api.create_submission(student_item, "Hello World")

        student_item["item_id"] = "i4x://a/b/c/s2"
        s2 = api.create_submission(student_item, "Hello World")

        student_item["item_id"] = "i4x://a/b/c/s3"
        s3 = api.create_submission(student_item, "Hello World")

        api.set_score(s1['uuid'], 3, 5)
        api.set_score(s1['uuid'], 4, 5)
        api.set_score(s1['uuid'], 2, 5)  # Should overwrite previous lines

        api.set_score(s2['uuid'], 0, 10)
        api.set_score(s3['uuid'], 4, 4)

        # Getting the scores for a user should never take more than one query
        with self.assertNumQueries(1):
            scores = api.get_scores(
                student_item["course_id"], student_item["student_id"]
            )
        self.assertEqual(
            scores,
            {
                u'i4x://a/b/c/s1': {
                    'created_at': now(),
                    'points_earned': 2,
                    'points_possible': 5,
                    'student_item': 1,
                    'submission': 1,
                    'submission_uuid': s1['uuid'],
                },
                u'i4x://a/b/c/s2': {
                    'created_at': now(),
                    'points_earned': 0,
                    'points_possible': 10,
                    'student_item': 2,
                    'submission': 2,
                    'submission_uuid': s2['uuid'],
                },
                u'i4x://a/b/c/s3': {
                    'created_at': now(),
                    'points_earned': 4,
                    'points_possible': 4,
                    'student_item': 3,
                    'submission': 3,
                    'submission_uuid': s3['uuid'],
                },
            }
        )
开发者ID:edx,项目名称:edx-submissions,代码行数:54,代码来源:test_api.py

示例14: test_two_students

    def test_two_students(self):
        api.create_submission(STUDENT_ITEM, ANSWER_ONE)
        api.create_submission(SECOND_STUDENT_ITEM, ANSWER_TWO)

        submissions = api.get_submissions(STUDENT_ITEM)
        self.assertEqual(1, len(submissions))
        self._assert_submission(submissions[0], ANSWER_ONE, 1, 1)

        submissions = api.get_submissions(SECOND_STUDENT_ITEM)
        self.assertEqual(1, len(submissions))
        self._assert_submission(submissions[0], ANSWER_TWO, 2, 1)
开发者ID:ctpad,项目名称:edx-tim,代码行数:11,代码来源:test_api.py

示例15: handle_answer

 def handle_answer(self, data, suffix=''):
     the_post_student_answer = data.get('student_answer')
     self.student_answer = the_post_student_answer
     #Save a students submission
     student_id = self.student_submission_id()
     answer = {
         "sha1": "None",
         "filename": "None",
         "mimetype": "json",
         }
     submissions_api.create_submission(student_id, answer)
     return {"student_answer":self.student_answer}
开发者ID:uestcmooc,项目名称:edx-sga,代码行数:12,代码来源:sga.py


注:本文中的submissions.api.create_submission函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。