Пример #1
0
    def test_get_response_state_with_ora(self, files_descriptions, saved_response):
        """
        Tests that ORA response state is transformed expectedly when the problem
        state contains unicode characters.
        """
        payload_state = json.dumps({
            'saved_response': json.dumps({'parts': [{'text': saved_response}]}),
            'saved_files_descriptions': json.dumps([files_descriptions]),
        })
        response = Mock(module_type='openassessment', student=Mock(username='******'), state=payload_state)

        transformed_state = json.loads(get_response_state(response))
        assert transformed_state['saved_files_descriptions'][0] == files_descriptions
        assert transformed_state['saved_response']['parts'][0]['text'] == saved_response
Пример #2
0
def list_problem_responses(course_key, problem_location):
    """
    Return responses to a given problem as a dict.

    list_problem_responses(course_key, problem_location)

    would return [
        {'username': u'user1', 'state': u'...'},
        {'username': u'user2', 'state': u'...'},
        {'username': u'user3', 'state': u'...'},
    ]

    where `state` represents a student's response to the problem
    identified by `problem_location`.
    """
    if isinstance(problem_location, UsageKey):
        problem_key = problem_location
    else:
        problem_key = UsageKey.from_string(problem_location)
    # Are we dealing with an "old-style" problem location?
    run = problem_key.run
    if not run:
        problem_key = UsageKey.from_string(problem_location).map_into_course(
            course_key)
    if problem_key.course_key != course_key:
        return []

    smdat = StudentModule.objects.filter(course_id=course_key,
                                         module_state_key=problem_key)
    smdat = smdat.order_by('student')

    for response in smdat:
        try:
            yield {
                'username': response.student.username,
                'state': get_response_state(response)
            }
        except User.DoesNotExist:
            continue