Esempio n. 1
0
def extract_evaluation_answer_data(request, evaluation):
    # TextAnswerExporter wants a dict from Question to tuple of contributor_name and string list (of the answers)

    view, view_as_user, represented_users, contributor_id = evaluation_detail_parse_get_parameters(request, evaluation)

    evaluation_result = get_results(evaluation)
    filter_text_answers(evaluation_result)
    remove_textanswers_that_the_user_must_not_see(evaluation_result, view_as_user, represented_users, view)

    results = TextAnswerExporter.InputData(evaluation_result.contribution_results)

    return results, contributor_id
Esempio n. 2
0
    def test_text_answer_export(self):
        evaluation = baker.make(Evaluation,
                                state=Evaluation.State.PUBLISHED,
                                can_publish_text_results=True)
        questions = [
            baker.make(Question, questionnaire__type=t, type=Question.TEXT)
            for t in Questionnaire.Type.values
        ]

        for idx in [0, 1, 2, 2, 0]:
            baker.make(
                TextAnswer,
                question=questions[idx],
                contribution__evaluation=evaluation,
                contribution__questionnaires=[questions[idx].questionnaire],
                state=TextAnswer.State.PUBLISHED,
            )

        cache_results(evaluation)
        evaluation_result = get_results(evaluation)
        filter_text_answers(evaluation_result)

        results = TextAnswerExporter.InputData(
            evaluation_result.contribution_results)

        binary_content = BytesIO()
        TextAnswerExporter(evaluation.name, evaluation.course.semester.name,
                           evaluation.course.responsibles_names, results,
                           None).export(binary_content)
        binary_content.seek(0)
        workbook = xlrd.open_workbook(file_contents=binary_content.read())
        sheet = workbook.sheets()[0]

        # Sheet headline
        self.assertEqual(sheet.row_values(0)[0], evaluation.name)
        self.assertEqual(
            sheet.row_values(1)[0], evaluation.course.semester.name)
        self.assertEqual(
            sheet.row_values(2)[0], evaluation.course.responsibles_names)

        # Questions are ordered by questionnaire type, answers keep their order respectively
        self.assertEqual(sheet.row_values(3)[0], questions[0].text)
        self.assertEqual(sheet.row_values(5)[0], questions[1].text)
        self.assertEqual(sheet.row_values(6)[0], questions[2].text)