def test_multi_responses_name_mask(self):

        xml = textwrap.dedent("""\
        <?xml version="1.0"?>
        <problem>
        <p>1st question</p>
        <choiceresponse>
            <checkboxgroup direction="vertical">
                <choice correct="true">row 1</choice>
                <choice correct="true">row 2</choice>
                <choice correct="false">row 3</choice>
            </checkboxgroup>
        </choiceresponse>
        <p>2nd question in the same problem:</p>
        <multiplechoiceresponse>
            <choicegroup type="MultipleChoice">
                <choice correct="false" name="Tom">1st choice text</choice>
                <choice correct="false" name="Dick">2nd choice text</choice>
                <choice correct="true" name="Harry">3rd choice text</choice>
            </choicegroup>
        </multiplechoiceresponse>
        </problem>
        """)

        module = CapaFactory.create(xml=xml)
        response = get_responses_data(module)

        self.assertEquals(response[0].correct_response, ['choice_0', 'choice_1'])
        self.assertEquals(response[1].correct_response, ['choice_Harry'])
        self.assertEquals(response[0].response_type, 'checkbox')
        self.assertEquals(response[1].response_type, 'radio')
        self.assertEquals(response[0].message, None)
        self.assertEquals(response[1].message, None)
        self.assertEquals(response[0].choice_name_list, '[]')
        self.assertEquals(response[1].choice_name_list, '[&quot;choice_Tom&quot;, &quot;choice_Dick&quot;, &quot;choice_Harry&quot;]')
Esempio n. 2
0
def add_inline_analytics(user, block, view, frag, context):  # pylint: disable=unused-argument
    """
    Adds a fragment for in-line analytics.

    Fragment consists of a button and some placeholder divs.

    Returns the wrapped fragment if the problem has a valid question (response). See get_responses_data function
    for valid responses.

    Otherwise, returns the fragment unchanged.
    """
    responses_data = get_responses_data(block)
    if responses_data:
        analytics_context = {
            'block_content': frag.content,
            'location': block.location.to_deprecated_string(),
            'element_id': block.location.html_id().replace('-', '_'),
            'answer_dist_url': reverse('get_analytics_answer_dist'),
            'responses_data': responses_data,
            'course_id': block.course_id.to_deprecated_string(),
        }
        return wrap_fragment(frag, render_to_string("inline_analytics.html", analytics_context))

    else:
        return frag
    def test_other_type(self):

        response = get_responses_data(self.module)
        self.assertEquals(response[0].message, 'The analytics cannot be displayed for this type of question.')
    def test_rerandomize_true(self):

        module = CapaFactory.create(rerandomize='always')
        response = get_responses_data(module)
        self.assertEquals(response[0].message, 'The analytics cannot be displayed for this question as it uses randomization.')
    def test_invalid_type(self):

        response = get_responses_data('invalid_type')
        self.assertEquals(response, [])
    def test_no_valid_types(self):

        response = get_responses_data(self.module)
        self.assertEquals(response, [])
    def test_capa_module(self):

        response = get_responses_data(self.module)
        self.assertEquals(len(response), 1)