예제 #1
0
    def test_fetch_submission_generic_exception(
        self,
        mock_check_submission_lock,
        mock_get_assessment_info,
        mock_get_submission_info,
    ):
        """Other generic exceptions should return the "unknown" error response"""
        mock_get_submission_info.return_value = test_data.example_submission
        # Mock an error in getting the assessment info
        mock_get_assessment_info.side_effect = XBlockInternalError(
            context={"handler": "get_assessment_info"})
        mock_check_submission_lock.return_value = {"lock_status": "unlocked"}

        ora_location, submission_uuid = Mock(), Mock()
        response = self.client.get(
            self.api_url,
            {
                PARAM_ORA_LOCATION: ora_location,
                PARAM_SUBMISSION_ID: submission_uuid
            },
        )

        assert response.status_code == 500
        assert json.loads(response.content) == {
            "error": ERR_INTERNAL,
            "handler": "get_assessment_info",
        }
예제 #2
0
파일: ora_api.py 프로젝트: edx/edx-platform
def get_submissions(request, usage_id):
    """
    Get a list of submissions from the ORA's 'list_staff_workflows' XBlock.json_handler
    """
    handler_name = "list_staff_workflows"
    response = call_xblock_json_handler(request, usage_id, handler_name, {})

    if response.status_code != 200:
        raise XBlockInternalError(context={"handler": handler_name})

    return json.loads(response.content)
예제 #3
0
    def test_delete_lock_xblock_exception(self, mock_delete_lock):
        """In the unlikely event of an error, the exits are to your left and behind you"""
        mock_delete_lock.side_effect = XBlockInternalError(
            context={"handler": "delete_submission_lock"})

        response = self.delete_lock(self.test_lock_params)

        assert response.status_code == 500
        assert json.loads(response.content) == {
            "error": ERR_INTERNAL,
            "handler": "delete_submission_lock",
        }
예제 #4
0
파일: ora_api.py 프로젝트: edx/edx-platform
def check_submission_lock(request, usage_id, submission_uuid):
    """
    Look up lock info for the given submission by calling the ORA's 'check_submission_lock' XBlock.json_handler
    """
    handler_name = "check_submission_lock"
    data = {"submission_uuid": submission_uuid}
    response = call_xblock_json_handler(request, usage_id, handler_name, data)

    # Unclear that there would every be an error (except network/auth) but good to catch here
    if response.status_code != 200:
        raise XBlockInternalError(context={"handler": handler_name})

    return json.loads(response.content)
예제 #5
0
    def test_batch_unlock_internal_error(self, mock_batch_delete):
        """Any internal errors to this API get surfaced as an internal error"""
        mock_batch_delete.side_effect = XBlockInternalError(
            context={"handler": "batch_delete_submission_locks"})

        response = self.batch_unlock(self.test_request_params,
                                     self.test_request_body)

        assert response.status_code == 500
        assert json.loads(response.content) == {
            "error": ERR_INTERNAL,
            "handler": "batch_delete_submission_locks",
        }
예제 #6
0
파일: ora_api.py 프로젝트: edx/edx-platform
def get_submission_info(request, usage_id, submission_uuid):
    """
    Get submission content from ORA 'get_submission_info' XBlock.json_handler
    """
    handler_name = "get_submission_info"
    data = {"submission_uuid": submission_uuid}
    response = call_xblock_json_handler(request, usage_id, handler_name, data)

    if response.status_code != 200:
        details = (json.loads(response.content).get("error", "")
                   if is_json(response.content) else "")
        raise XBlockInternalError(context={"handler": handler_name})

    return json.loads(response.content)
예제 #7
0
def batch_delete_submission_locks(request, usage_id, submission_uuids):
    """
    Batch delete a list of submission locks. Limited only to those in the list the user owns.

    Returns: none
    """
    handler_name = "batch_delete_submission_lock"
    body = {"submission_uuids": submission_uuids}

    response = call_xblock_json_handler(request, usage_id, handler_name, body)

    # Errors should raise a blanket exception. Otherwise body is empty, 200 is implicit success
    if response.status_code != 200:
        raise XBlockInternalError(context={"handler": handler_name})
예제 #8
0
파일: ora_api.py 프로젝트: edx/edx-platform
def submit_grade(request, usage_id, grade_data):
    """
    Submit a grade for an assessment.

    Returns: {'success': True/False, 'msg': err_msg}
    """
    handler_name = "submit_staff_assessment"
    response = call_xblock_json_handler(request, usage_id, handler_name,
                                        grade_data)

    # Unhandled errors might not be JSON, catch before loading
    if response.status_code != 200:
        raise XBlockInternalError(context={"handler": handler_name})

    response_data = json.loads(response.content)

    # Handled faillure still returns HTTP 200 but with 'success': False and supplied error message 'msg'
    if not response_data.get("success", False):
        raise XBlockInternalError(context={
            "handler": handler_name,
            "msg": response_data.get("msg", "")
        })

    return response_data
예제 #9
0
    def test_init_xblock_exception(self, mock_get_course_overview,
                                   mock_get_submissions):
        """If one of the XBlock handlers fails, the exception should be caught"""
        mock_course_overview = CourseOverviewFactory.create()
        mock_get_course_overview.return_value = mock_course_overview
        # Mock an error getting submissions
        mock_get_submissions.side_effect = XBlockInternalError(
            context={"handler": "list_staff_workflows"})

        response = self.client.get(self.api_url,
                                   {PARAM_ORA_LOCATION: self.ora_usage_key})

        assert response.status_code == 500
        assert json.loads(response.content) == {
            "error": ERR_INTERNAL,
            "handler": "list_staff_workflows",
        }
예제 #10
0
    def test_fetch_files_xblock_exception(self, mock_get_submission_info):
        """An exception in any XBlock handler returns an error response"""
        mock_get_submission_info.side_effect = XBlockInternalError(
            context={"handler": "get_submission_info"})

        ora_location, submission_uuid = Mock(), Mock()
        response = self.client.get(
            self.api_url,
            {
                PARAM_ORA_LOCATION: ora_location,
                PARAM_SUBMISSION_ID: submission_uuid
            },
        )

        assert response.status_code == 500
        assert json.loads(response.content) == {
            "error": ERR_INTERNAL,
            "handler": "get_submission_info",
        }
예제 #11
0
파일: ora_api.py 프로젝트: edx/edx-platform
def claim_submission_lock(request, usage_id, submission_uuid):
    """
    Attempt to claim a submission lock for grading.

    Returns:
    - lockStatus (string) - One of ['not-locked', 'locked', 'in-progress']
    """
    handler_name = "claim_submission_lock"
    body = {"submission_uuid": submission_uuid}
    response = call_xblock_json_handler(request, usage_id, handler_name, body)

    # Lock contested returns a 403
    if response.status_code == 403:
        raise LockContestedError()

    # Other errors should raise a blanket exception
    if response.status_code != 200:
        raise XBlockInternalError(context={"handler": handler_name})

    return json.loads(response.content)
예제 #12
0
    def test_fetch_submission_status_xblock_exception(
            self, mock_check_submission_lock, mock_get_assessment_info):
        """Exceptions within an XBlock return an internal error response"""
        mock_get_assessment_info.return_value = {}
        mock_check_submission_lock.side_effect = XBlockInternalError(
            context={"handler": "claim_submission_lock"})

        ora_location, submission_uuid = Mock(), Mock()
        response = self.client.get(
            self.api_url,
            {
                PARAM_ORA_LOCATION: ora_location,
                PARAM_SUBMISSION_ID: submission_uuid
            },
        )

        assert response.status_code == 500
        assert json.loads(response.content) == {
            "error": ERR_INTERNAL,
            "handler": "claim_submission_lock",
        }
예제 #13
0
    def test_submit_grade_xblock_exception(self, mock_submit_grade,
                                           mock_check_lock):
        """A handled ORA failure to submit a grade returns a server error"""
        mock_check_lock.return_value = {"lock_status": "in-progress"}
        mock_submit_grade.side_effect = XBlockInternalError(
            context={
                "handler": "submit_staff_assessment",
                "msg": "Danger, Will Robinson!"
            })
        url = self.url_with_params({
            PARAM_ORA_LOCATION: self.ora_location,
            PARAM_SUBMISSION_ID: self.submission_uuid,
        })
        data = test_data.example_grade_data

        response = self.client.post(url, data, format="json")
        assert response.status_code == 500
        assert json.loads(response.content) == {
            "error": ERR_INTERNAL,
            "handler": "submit_staff_assessment",
            "msg": "Danger, Will Robinson!",
        }