def map_orders_with_answer_type(self, mapped_orders): orders = self.orders.order_by('order').select_related() if self.primary_question() and self.grid and self.display_all: for option in self.primary_question().options.all(): map_question_type_with(orders, mapped_orders, option) else: map_question_type_with(orders, mapped_orders)
def test_maps_question_type_with_orders(self): expected_map = {self.question4.answer_type: [{'option': self.option1, 'order': self.order4}], self.question1.answer_type: [{'option': self.option1, 'order': self.order1}], 'Number': [], 'Text': []} orders = self.question_group.orders.filter(question__in=[self.question1, self.question4]) map_question_type_with(orders, self.empty_mapping, option=self.option1) self.assertEqual(expected_map, self.empty_mapping)
def test_maps_multiple_questions_type_with_orders_when_they_are_of_same_type(self): question5 = Question.objects.create(text='question 5', instructions="instruction 5", UID='04444', answer_type='Date') self.question_group.question.add(question5) order5 = QuestionGroupOrder.objects.create(question=question5, question_group=self.question_group, order=5) expected_map = {self.question4.answer_type: [{'option': self.option1, 'order': self.order4}, {'option': self.option1, 'order': order5}], self.question1.answer_type: [{'option': self.option1, 'order': self.order1}], 'Number': [], 'Text': []} orders = self.question_group.orders.filter(question__in=[self.question1, self.question4, question5]) map_question_type_with(orders, self.empty_mapping, option=self.option1) self.assertEqual(expected_map, self.empty_mapping)