def test_generate_response_xml(self):
     '''
     Should generate response XML.
     '''
     response = OutcomeResponse()
     response.process_xml(RESPONSE_XML)
     correct = normalize_xml(RESPONSE_XML)
     got = normalize_xml(response.generate_response_xml())
     self.assertEqual(got, correct)
Exemple #2
0
 def test_generate_response_xml(self):
     '''
     Should generate response XML.
     '''
     response = OutcomeResponse()
     response.process_xml(RESPONSE_XML)
     correct = normalize_xml(RESPONSE_XML)
     got = normalize_xml(response.generate_response_xml())
     self.assertEqual(got, correct)
 def test_recognize_failure_response(self):
     '''
     Should recognize a failure response.
     '''
     failure_xml = RESPONSE_XML.replace(b'success', b'failure')
     fake = self.mock_response(failure_xml)
     result = OutcomeResponse.from_post_response(fake, failure_xml)
     self.assertTrue(result.is_failure())
Exemple #4
0
 def test_recognize_failure_response(self):
     '''
     Should recognize a failure response.
     '''
     failure_xml = RESPONSE_XML.replace('success', 'failure')
     fake = self.mock_response(failure_xml)
     result = OutcomeResponse.from_post_response(fake, failure_xml)
     self.assertTrue(result.is_failure())
 def test_parse_replace_result_response_xml(self):
     '''
     Should parse replaceResult response XML.
     '''
     fake = self.mock_response(RESPONSE_XML)
     response = OutcomeResponse.from_post_response(fake, RESPONSE_XML)
     self.assertTrue(response.is_success())
     self.assertEqual(response.code_major, 'success')
     self.assertEqual(response.severity, 'status')
     self.assertEqual(response.description, '')
     self.assertEqual(response.message_ref_identifier, '123456789')
     self.assertEqual(response.operation, 'replaceResult')
     self.assertEqual(response.score, None)
Exemple #6
0
 def test_parse_replace_result_response_xml(self):
     '''
     Should parse replaceResult response XML.
     '''
     fake = self.mock_response(RESPONSE_XML)
     response = OutcomeResponse.from_post_response(fake, RESPONSE_XML)
     self.assertTrue(response.is_success())
     self.assertEqual(response.code_major, 'success')
     self.assertEqual(response.severity, 'status')
     self.assertEqual(response.description, '')
     self.assertEqual(response.message_ref_identifier, '123456789')
     self.assertEqual(response.operation, 'replaceResult')
     self.assertEqual(response.score, None)
 def test_parse_delete_result_response_xml(self):
     '''
     Should parse deleteResult response XML.
     '''
     delete_xml = RESPONSE_XML.replace(b'replaceResult', b'deleteResult')
     fake = self.mock_response(delete_xml)
     result = OutcomeResponse.from_post_response(fake, delete_xml)
     self.assertTrue(result.is_success())
     self.assertEqual(result.code_major, 'success')
     self.assertEqual(result.severity, 'status')
     self.assertEqual(result.description, '')
     self.assertEqual(result.message_ref_identifier, '123456789')
     self.assertEqual(result.operation, 'deleteResult')
     self.assertEqual(result.score, None)
Exemple #8
0
 def test_parse_delete_result_response_xml(self):
     '''
     Should parse deleteResult response XML.
     '''
     delete_xml = RESPONSE_XML.replace('replaceResult', 'deleteResult')
     fake = self.mock_response(delete_xml)
     result = OutcomeResponse.from_post_response(fake, delete_xml)
     self.assertTrue(result.is_success())
     self.assertEqual(result.code_major, 'success')
     self.assertEqual(result.severity, 'status')
     self.assertEqual(result.description, '')
     self.assertEqual(result.message_ref_identifier, '123456789')
     self.assertEqual(result.operation, 'deleteResult')
     self.assertEqual(result.score, None)
    def test_parse_read_result_response_xml(self):
        '''
        Should parse readResult response XML.
        '''
        read_xml = RESPONSE_XML.replace(
            b'<replaceResultResponse/>', b'''<readResultResponse>
<result>
<resultScore>
<language>en</language>
<textString>0.91</textString>
</resultScore>
</result>
</readResultResponse>''')
        fake = self.mock_response(read_xml)
        response = OutcomeResponse.from_post_response(fake, read_xml)
        self.assertTrue(response.is_success())
        self.assertEqual(response.code_major, 'success')
        self.assertEqual(response.severity, 'status')
        self.assertEqual(response.description, '')
        self.assertEqual(response.message_ref_identifier, '123456789')
        self.assertEqual(response.score, '0.91')
Exemple #10
0
    def test_parse_read_result_response_xml(self):
        '''
        Should parse readResult response XML.
        '''
        read_xml = RESPONSE_XML.replace(\
                '<replaceResultResponse/>',\
                '''<readResultResponse>
<result>
<resultScore>
<language>en</language>
<textString>0.91</textString>
</resultScore>
</result>
</readResultResponse>''')
        fake = self.mock_response(read_xml)
        response = OutcomeResponse.from_post_response(fake, read_xml)
        self.assertTrue(response.is_success())
        self.assertEqual(response.code_major, 'success')
        self.assertEqual(response.severity, 'status')
        self.assertEqual(response.description, '')
        self.assertEqual(response.message_ref_identifier, '123456789')
        self.assertEqual(response.score, '0.91')
Exemple #11
0
def callback_sequence_item_grade(request):
    outcome_response = OutcomeResponse(message_identifier='unknown',
                                       code_major=CODE_MAJOR_CODES[2],
                                       severity=SEVERITY_CODES[0])

    try:
        outcome_request = OutcomeRequest().from_post_request(request)
        score = float(outcome_request.score)
        if not 0.0 <= score <= 1.0:
            raise InvalidLTIConfigError(
                '[LTI] score value is outside the permitted range of 0.0-1.0')
        operation = outcome_request.operation
        if not operation == 'replaceResult':
            raise InvalidLTIConfigError(
                '[LTI] request operation {} cannot be proceed'.format(
                    operation))
    except (InvalidLTIConfigError, ValueError) as err:
        body = escape(request.body) if request.body else ''
        error_message = "Request body XML parsing error: {} {}".format(
            err.message, body)
        log.debug("Failure to archive grade from the source: %s" +
                  error_message)
        outcome_response.description = escape(error_message)
        return HttpResponse(outcome_response.generate_response_xml(),
                            content_type='application/xml')
    sequence_item_id, user_id, _activity, _suffix = outcome_request.lis_result_sourcedid.text.split(
        ':')
    outcome_response.code_major = CODE_MAJOR_CODES[0]
    outcome_response.description = 'Score for {sourced_id} is now {score}'.format(
        sourced_id=outcome_request.lis_result_sourcedid, score=score)
    outcome_response.message_identifier = outcome_request.message_identifier
    outcome_response.operation = operation

    xml = outcome_response.generate_response_xml()
    log.debug(
        "Received CallBack with the submitted answer for sequence item {}.".
        format(sequence_item_id))
    try:
        sequence_item = SequenceItem.objects.get(id=sequence_item_id)
    except SequenceItem.DoesNotExist:
        error_message = "Sequence Item with the ID={} was not found".format(
            sequence_item_id)
        outcome_response.description = escape(error_message)
        log.debug("[LTI] {}".format(error_message))
        return HttpResponseNotFound(outcome_response.generate_response_xml(),
                                    content_type='application/xml')

    sequence_item.score = score
    sequence_item.save()

    log.debug("[LTI] Sequence item {} grade is updated".format(sequence_item))
    last_log_submit = Log.objects.filter(sequence_item=sequence_item,
                                         log_type='S').last()
    attempt = (last_log_submit.attempt if last_log_submit else 0) + 1
    correct = bool(score)
    Log.objects.create(
        sequence_item=sequence_item,
        log_type=Log.SUBMITTED,
        answer=correct,
        attempt=attempt,
    )
    log.debug(
        "New Log is created log_type: 'Submitted', attempt: {}, correct: {}, sequence is completed: {}"
        .format(attempt, correct, sequence_item.sequence.completed))
    message_to_consumer = {"sequence_status": "updated"}
    sequence = sequence_item.sequence
    if sequence_item.sequence.collection_order.ui_option:
        ui_details = sequence_item.sequence.sequence_ui_details()
        message_to_consumer["ui_details"] = ui_details

    NextButtonConsumer.send_message_to_channel(
        f'{sequence_item.id}_{sequence_item.position}', message_to_consumer)
    if sequence.lis_result_sourcedid:
        policy = sequence.collection_order.grading_policy.policy_instance(
            sequence=sequence, request=request, user_id=user_id)
        policy.send_grade()

    return HttpResponse(xml, content_type="application/xml")
def outcome_response_object():
    out = OutcomeResponse()
    out.score = 0.5

    return out