def register_exam_attempt(self, exam, context):
        """
        Method that is responsible for communicating with the backend provider
        to establish a new proctored exam
        """

        attempt_code = context['attempt_code']

        data = self._get_payload(exam, context)

        headers = {"Content-Type": 'application/json'}
        # pylint: disable=unicode-format-string
        http_date = datetime.datetime.utcnow().strftime(
            "%a, %d %b %Y %H:%M:%S GMT")
        signature = self._sign_doc(data, 'POST', headers, http_date)

        status, response = self._send_request_to_ssi(data, signature,
                                                     http_date)

        if status not in [200, 201]:
            err_msg = (
                u'Could not register attempt_code = {attempt_code}. '
                u'HTTP Status code was {status_code} and response was {response}.'
                .format(attempt_code=attempt_code,
                        status_code=status,
                        response=response))
            log.error(err_msg)
            raise BackendProviderCannotRegisterAttempt(err_msg, status)

        # get the external ID that Software Secure has defined
        # for this attempt
        ssi_record_locator = json.loads(response)['ssiRecordLocator']

        return ssi_record_locator
Ejemplo n.º 2
0
 def register_exam_attempt(self, exam, context):
     """
     Called when the exam attempt has been created but not started
     """
     url = self.create_exam_attempt_url.format(exam_id=exam['external_id'])
     payload = context
     payload['status'] = 'created'
     # attempt code isn't needed in this API
     payload.pop('attempt_code', False)
     log.debug(u'Creating exam attempt for %r at %r', exam['external_id'],
               url)
     response = self.session.post(url, json=payload)
     if response.status_code != 200:
         raise BackendProviderCannotRegisterAttempt(response.content,
                                                    response.status_code)
     status_code = response.status_code
     response = response.json()
     log.debug(response)
     onboarding_status = response.get('status', None)
     if onboarding_status in ProctoredExamStudentAttemptStatus.onboarding_errors:
         raise BackendProviderOnboardingException(onboarding_status)
     attempt_id = response.get('id', None)
     if not attempt_id:
         raise BackendProviderSentNoAttemptID(response, status_code)
     return attempt_id
Ejemplo n.º 3
0
 def register_exam_attempt(self, exam, context):
     """
     Called when the exam attempt has been created but not started
     """
     url = self.create_exam_attempt_url.format(exam_id=exam['external_id'])
     payload = context
     payload['status'] = 'created'
     # attempt code isn't needed in this API
     payload.pop('attempt_code', False)
     log.debug('Creating exam attempt for %r at %r', exam['external_id'], url)
     response = self.session.post(url, json=payload)
     if response.status_code != 200:
         raise BackendProviderCannotRegisterAttempt(response.content)
     response = response.json()
     log.debug(response)
     return response['id']