本文整理汇总了Python中questionnaire.services.users.UserQuestionnaireService.questionnaire_answers方法的典型用法代码示例。如果您正苦于以下问题:Python UserQuestionnaireService.questionnaire_answers方法的具体用法?Python UserQuestionnaireService.questionnaire_answers怎么用?Python UserQuestionnaireService.questionnaire_answers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类questionnaire.services.users.UserQuestionnaireService
的用法示例。
在下文中一共展示了UserQuestionnaireService.questionnaire_answers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_user_knows_answers_given_questionnaire_and_version
# 需要导入模块: from questionnaire.services.users import UserQuestionnaireService [as 别名]
# 或者: from questionnaire.services.users.UserQuestionnaireService import questionnaire_answers [as 别名]
def test_user_knows_answers_given_questionnaire_and_version(self):
data = self.data
version_1_primary_answer = MultiChoiceAnswer.objects.create(response=self.option1, question=self.question1,
**self.initial)
version_1_answer_1 = NumericalAnswer.objects.create(response=int(data['Number-0-response']),
question=self.question2, **self.initial)
version_1_answer_2 = NumericalAnswer.objects.create(response=int(data['Number-1-response']),
question=self.question3, **self.initial)
answer_group = AnswerGroup.objects.create(grouped_question=self.question_group)
answer_group.answer.add(version_1_answer_1, version_1_answer_2, version_1_primary_answer)
user_service = UserQuestionnaireService(self.user.user_profile.country, self.questionnaire, version=1)
user_answers = user_service.questionnaire_answers()
self.assertEqual(3, len(user_answers))
self.assertIn(version_1_primary_answer, user_answers)
self.assertIn(version_1_answer_1, user_answers)
self.assertIn(version_1_answer_2, user_answers)
version_1_primary_answer.status = Answer.SUBMITTED_STATUS
version_1_primary_answer.save()
version_1_answer_1.status = Answer.SUBMITTED_STATUS
version_1_answer_1.save()
version_1_answer_2.status = Answer.SUBMITTED_STATUS
version_1_answer_2.save()
initial = self.initial.copy()
del initial['version']
version_2_primary = MultiChoiceAnswer.objects.create(response=self.option1, question=self.question1, version=2,
**initial)
version_2_answer_1 = NumericalAnswer.objects.create(response=int(data['Number-0-response']),
question=self.question2, version=2, **initial)
version_2_answer_2 = NumericalAnswer.objects.create(response=int(data['Number-1-response']),
question=self.question3, version=2, **initial)
answer_group = AnswerGroup.objects.create(grouped_question=self.question_group)
answer_group.answer.add(version_2_primary, version_2_answer_1, version_2_answer_2)
user_service = UserQuestionnaireService(self.country, self.questionnaire, version=2)
user_answers = user_service.questionnaire_answers()
self.assertEqual(3, len(user_answers))
self.assertIn(version_2_primary, user_answers)
self.assertIn(version_2_answer_1, user_answers)
self.assertIn(version_2_answer_2, user_answers)
示例2: test_user_knows_answers_given_questionnaire
# 需要导入模块: from questionnaire.services.users import UserQuestionnaireService [as 别名]
# 或者: from questionnaire.services.users.UserQuestionnaireService import questionnaire_answers [as 别名]
def test_user_knows_answers_given_questionnaire(self):
data = self.data
old_primary = MultiChoiceAnswer.objects.create(response=self.option1, question=self.question1, **self.initial)
old_answer_1 = NumericalAnswer.objects.create(response=int(data['Number-0-response']), question=self.question2,
**self.initial)
old_answer_2 = NumericalAnswer.objects.create(response=int(data['Number-1-response']), question=self.question3,
**self.initial)
answer_group = AnswerGroup.objects.create(grouped_question=self.question_group)
answer_group.answer.add(old_primary, old_answer_1, old_answer_2)
other_questionnaire = Questionnaire.objects.create(name="JRF 2013 Core English",
description="From dropbox as given by Rouslan")
other_section_1 = Section.objects.create(title="Reported Cases of Selected Vaccine Preventable Diseases (VPDs)",
order=1, questionnaire=other_questionnaire, name="Reported Cases")
other_sub_section = SubSection.objects.create(title="Reported cases for the year 2013", order=1,
section=other_section_1)
other_question1 = Question.objects.create(text='Disease', UID='C00011', answer_type='Number')
other_question_group = QuestionGroup.objects.create(subsection=other_sub_section, order=1)
other_question_group.question.add(other_question1)
other_answer_1 = NumericalAnswer.objects.create(response=1, question=other_question1)
section_2 = Section.objects.create(title="Section 2", order=2, questionnaire=self.questionnaire,
name="section2")
sub_section2 = SubSection.objects.create(title="subsection 2", order=1, section=section_2)
question1 = Question.objects.create(text='question 1', UID='C00013', answer_type='Number')
question2 = Question.objects.create(text='question 2', UID='C00014', answer_type='Number')
question_group = QuestionGroup.objects.create(subsection=sub_section2, order=1)
question_group.question.add(question1, question2)
QuestionGroupOrder.objects.create(question=question1, order=1, question_group=question_group)
QuestionGroupOrder.objects.create(question=question2, order=2, question_group=question_group)
answer_1 = NumericalAnswer.objects.create(response=1, question=question1, status=Answer.DRAFT_STATUS,
country=self.country, questionnaire=self.questionnaire)
answer_2 = NumericalAnswer.objects.create(response=2, question=question2, status=Answer.DRAFT_STATUS,
country=self.country, questionnaire=self.questionnaire)
answer_group = AnswerGroup.objects.create(grouped_question=question_group)
answer_group.answer.add(answer_1, answer_2)
user_service = UserQuestionnaireService(self.user.user_profile.country, self.questionnaire)
user_answers = user_service.questionnaire_answers()
self.assertEqual(5, len(user_answers))
self.assertIn(old_primary, user_answers)
self.assertIn(old_answer_1, user_answers)
self.assertIn(old_answer_2, user_answers)
self.assertNotIn(other_answer_1, user_answers)
self.assertIn(answer_1, user_answers)
self.assertIn(answer_2, user_answers)