def setUp(self): self.PHONE = '+12065551212' self.flow_id = 2436 self.flow = FlowFactory(label=Flow.Label.IMPLEMENTING_PARTNER) requests.get = MagicMock(return_value=MagicMock( status_code=200, json=MagicMock(return_value=FLOW_RESPONSE))) self.my_hook = reload(my_hook)
def test_should_return_default_answers_for_delivery(self): delivery = DeliveryFactory() flow = FlowFactory(label='IMPLEMENTING_PARTNER') question_1 = MultipleChoiceQuestionFactory( label='deliveryReceived', flow=flow, text='Was Delivery Received?') question_2 = TextQuestionFactory(label='dateOfReceipt', flow=flow, text='When was Delivery Received?') OptionFactory(text='Yes', question=question_1) RunFactory(runnable=delivery) expected_multiple_choice_answer = { 'question_label': question_1.label, 'type': 'multipleChoice', 'text': question_1.text, 'value': '', 'options': ['Yes'], 'position': question_1.position } expected_text_answer = { 'question_label': question_2.label, 'type': 'text', 'text': question_2.text, 'value': '', 'position': question_2.position } answers = delivery.answers() self.assertEqual(len(answers), 2) self.assertIn(expected_multiple_choice_answer, answers) self.assertIn(expected_text_answer, answers)
def test_should_return_answers_for_delivery_in_the_same_order_as_flow( self): delivery = DeliveryFactory() flow = FlowFactory(label='IMPLEMENTING_PARTNER') question_1 = MultipleChoiceQuestionFactory( label='deliveryReceived', flow=flow, text='Was Delivery Received?', position=3) question_2 = TextQuestionFactory(label='dateOfReceipt', flow=flow, text='When was Delivery Received?', position=1) question_3 = TextQuestionFactory( label='satisfiedWithProduct', flow=flow, text='Are you satisfied with product?', position=2) OptionFactory(text='No', question=question_1) OptionFactory(text='Yes', question=question_1) RunFactory(runnable=delivery) answers = delivery.answers() self.assertEqual(len(answers), 3) self.assertEqual(question_2.label, answers[0]['question_label']) self.assertEqual(question_3.label, answers[1]['question_label']) self.assertEqual(question_1.label, answers[2]['question_label'])
def test_should_not_return_deliveries_for_ip_if_received_is_false(self): first_consignee = ConsigneeFactory() date = datetime.date(2014, 07, 9) first_delivery = DeliveryFactory(consignee=first_consignee, track=True, delivery_date=date) second_delivery = DeliveryFactory(consignee=first_consignee, track=True) self.logout() self.log_consignee_in(consignee=first_consignee) response = self.client.get(ENDPOINT_URL) ids = map(lambda delivery: delivery['id'], response.data) self.assertEqual(response.status_code, 200) self.assertIn(first_delivery.id, ids) self.assertIn(second_delivery.id, ids) flow = FlowFactory(label=Flow.Label.IMPLEMENTING_PARTNER) delivery_received_qn = MultipleChoiceQuestionFactory(label='deliveryReceived', flow=flow) OptionFactory(question=delivery_received_qn, text='Yes') option_no = OptionFactory(question=delivery_received_qn, text='No') run = RunFactory(runnable=first_delivery) MultipleChoiceAnswerFactory(run=run, question=delivery_received_qn, value=option_no) response = self.client.get(ENDPOINT_URL) ids = map(lambda delivery: delivery['id'], response.data) self.assertEqual(response.status_code, 200) self.assertNotIn(first_delivery.id, ids) self.assertIn(second_delivery.id, ids)
def _create_questions(self): flow = FlowFactory(label='IMPLEMENTING_PARTNER') self.delivery_received_qtn = MultipleChoiceQuestionFactory(text='Was delivery received?', flow=flow, position=1, label=Question.LABEL.deliveryReceived) self.yes_one = OptionFactory(text='Yes', question=self.delivery_received_qtn) self.no_one = OptionFactory(text='No', question=self.delivery_received_qtn) self.date_received_qtn = TextQuestionFactory(text='When was delivery received?', flow=flow, position=2, label='dateOfReceipt') self.delivery_in_good_order = MultipleChoiceQuestionFactory(text='Was delivery in good condition?', flow=flow, position=3, label=Question.LABEL.isDeliveryInGoodOrder) self.yes_two = OptionFactory(text='Yes', question=self.delivery_in_good_order) self.no_two = OptionFactory(text='No', question=self.delivery_in_good_order) self.satisfied_with_delivery = MultipleChoiceQuestionFactory(text="Are you satisfied with the delivery?", flow=flow, position=4, label="satisfiedWithDelivery") self.yes_three = OptionFactory(text="Yes", question=self.satisfied_with_delivery) self.no_three = OptionFactory(text="No", question=self.satisfied_with_delivery) self.additional_comments = TextQuestionFactory(text='Additional Remarks', flow=flow, position=5, label='additionalDeliveryComments')
def setup_multiple_nodes_with_answers(self, number_of_nodes): consignee_one = ConsigneeFactory(name='consignee one') programme_one = ProgrammeFactory(name='my first programme') po_item = PurchaseOrderItemFactory(item=ItemFactory(description='Mama kit'), purchase_order=PurchaseOrderFactory(order_number=329293)) flow = FlowFactory(label='WEB') question_1 = MultipleChoiceQuestionFactory(text='Was the item received?', label='itemReceived', flow=flow, position=1) option_1 = OptionFactory(text='Yes', question=question_1) question_2 = NumericQuestionFactory(text='How much was received?', label='amountReceived', flow=flow) question_3 = MultipleChoiceQuestionFactory(text='What is the quality of the product?', label='qualityOfProduct', flow=flow, position=3) option_3 = OptionFactory(text='Damaged', question=question_3) question_4 = MultipleChoiceQuestionFactory(text='Are you satisfied with the product?', label='satisfiedWithProduct', flow=flow, position=4) option_4 = OptionFactory(text='Yes', question=question_4) question_5 = TextQuestionFactory(label='dateOfReceipt', flow=flow, text='When was Delivery Received?') nodes = [] for index in range(number_of_nodes): node = DeliveryNodeFactory(consignee=consignee_one, item=po_item, programme=programme_one, distribution_plan=DeliveryFactory(track=True), track=True) run_one = RunFactory(runnable=node) MultipleChoiceAnswerFactory(question=question_1, run=run_one, value=option_1) NumericAnswerFactory(question=question_2, run=run_one, value=5) MultipleChoiceAnswerFactory(question=question_3, run=run_one, value=option_3) MultipleChoiceAnswerFactory(question=question_4, run=run_one, value=option_4) TextAnswerFactory(run=run_one, question=question_5, value='2014-10-10') nodes.append(node) return nodes
def test_node_flow_is_middleman_for_non_end_user_node(self): middleman_flow = FlowFactory(label=Flow.Label.MIDDLE_MAN) runnable = DeliveryNodeFactory( tree_position=Flow.Label.IMPLEMENTING_PARTNER) self.assertEqual(runnable.flow(), middleman_flow) runnable.tree_position = Flow.Label.MIDDLE_MAN self.assertEqual(runnable.flow(), middleman_flow)
def test_should_return_answers_for_completed_or_scheduled_runs_only(self): delivery = DeliveryFactory() flow = FlowFactory(label='IMPLEMENTING_PARTNER') question_1 = MultipleChoiceQuestionFactory( label='deliveryReceived', flow=flow, text='Was Delivery Received?', position=3) question_2 = TextQuestionFactory(label='dateOfReceipt', flow=flow, text='When was Delivery Received?', position=1) question_3 = TextQuestionFactory( label='satisfiedWithProduct', flow=flow, text='Are you satisfied with product?', position=2) option_no = OptionFactory(text='No', question=question_1) option_yes = OptionFactory(text='Yes', question=question_1) run_one = RunFactory(runnable=delivery) MultipleChoiceAnswerFactory(question=question_1, value=option_no, run=run_one) TextAnswerFactory(question=question_2, value="2014-10-10", run=run_one) TextAnswerFactory(question=question_3, value="yup", run=run_one) answers = delivery.answers() self.assertEqual(len(answers), 3) self.assertEqual(answers[0]['value'], '2014-10-10') run_one.status = 'cancelled' run_one.save() answers = delivery.answers() self.assertEqual(len(answers), 3) self.assertEqual(answers[0]['value'], '') run_two = RunFactory(runnable=delivery) MultipleChoiceAnswerFactory(question=question_1, value=option_yes, run=run_two) answers = delivery.answers() self.assertEqual(len(answers), 3) self.assertEqual(answers[0]['value'], '') self.assertEqual(answers[1]['value'], '') self.assertEqual(answers[2]['value'], 'Yes')
def test_should_return_answers_for_delivery(self): delivery = DeliveryFactory() flow = FlowFactory(label='IMPLEMENTING_PARTNER') question_1 = MultipleChoiceQuestionFactory( label='deliveryReceived', flow=flow, text='Was Delivery Received?') question_2 = TextQuestionFactory(label='dateOfReceipt', flow=flow, text='When was Delivery Received?') question_3 = NumericQuestionFactory(text='How much was received?', label='amountReceived', flow=flow) option_yes = OptionFactory(text='Yes', question=question_1) run = RunFactory(runnable=delivery) multiple_choice_answer = MultipleChoiceAnswerFactory( run=run, question=question_1, value=option_yes) text_answer = TextAnswerFactory(run=run, question=question_2, value='2015-10-10') numeric_answer = NumericAnswerFactory(run=run, question=question_3, value=10) expected_multiple_choice_answer = { 'question_label': question_1.label, 'type': 'multipleChoice', 'text': question_1.text, 'value': multiple_choice_answer.value.text, 'options': ['Yes'], 'position': question_1.position } expected_text_answer = { 'question_label': question_2.label, 'type': 'text', 'text': question_2.text, 'value': text_answer.value, 'position': question_2.position } expected_numeric_answer = { 'question_label': question_3.label, 'type': 'numeric', 'text': question_3.text, 'value': numeric_answer.value, 'position': question_3.position } answers = delivery.answers() self.assertEqual(len(answers), 3) self.assertIn(expected_multiple_choice_answer, answers) self.assertIn(expected_text_answer, answers) self.assertIn(expected_numeric_answer, answers)
def setup_flow_with_questions(self, flow_type): flow = FlowFactory(label=flow_type) delivery_received_qn = MultipleChoiceQuestionFactory(label='deliveryReceived', flow=flow) OptionFactory(question=delivery_received_qn, text='Yes') OptionFactory(question=delivery_received_qn, text='No') TextQuestionFactory(label='dateOfReceipt', flow=flow) good_order_qn = MultipleChoiceQuestionFactory(label='isDeliveryInGoodOrder', flow=flow) OptionFactory(question=good_order_qn, text='Yes') OptionFactory(question=good_order_qn, text='No') OptionFactory(question=good_order_qn, text='Incomplete') satisfied_qn = MultipleChoiceQuestionFactory(label='areYouSatisfied', flow=flow) OptionFactory(question=satisfied_qn, text='Yes') OptionFactory(question=satisfied_qn, text='No') TextQuestionFactory(label='additionalDeliveryComments', flow=flow)
def setUp(self): self.__backup_original_methods() self.__mock_ready() self.flow_scheduler.settings.RAPIDPRO_LIVE = True self.contact = { 'first_name': 'Test', 'last_name': 'User', 'phone': '+256 772 123456' } self.node = NodeFactory() local_celery.app.control.revoke = MagicMock(return_value=None) self.node.build_contact = MagicMock(return_value=self.contact) Node.objects.get = MagicMock(return_value=self.node) Runnable.objects.get = MagicMock(return_value=self.node) self.ip_flow = FlowFactory(label=Flow.Label.IMPLEMENTING_PARTNER) self.end_user_flow = FlowFactory(label=Flow.Label.END_USER) self.middle_man_flow = FlowFactory(label=Flow.Label.MIDDLE_MAN) self.MIDDLEMAN_FLOW_ID = 1 self.END_USER_FLOW_ID = 2 self.IMPLEMENTING_PARTNER_FLOW_ID = 3
def setUp(self): web_flow = FlowFactory(label=Flow.Label.WEB) question = MultipleChoiceQuestionFactory(label='itemReceived', when_answered='update_consignee_inventory', flow=web_flow) OptionFactory(question=question, text='Yes') OptionFactory(question=question, text='No') self.consignee = ConsigneeFactory() self.item = ItemFactory() self.node = DeliveryNodeFactory(consignee=self.consignee, item=PurchaseOrderItemFactory(item=self.item)) self.was_item_received = MultipleChoiceQuestion.objects.get(label='itemReceived', flow=web_flow) self.yes = self.was_item_received.option_set.get(text='Yes') self.no = self.was_item_received.option_set.get(text='No')
def test_should_return_a_deliveries_answers(self): delivery = DeliveryFactory() flow = FlowFactory(label='IMPLEMENTING_PARTNER') question_1 = MultipleChoiceQuestionFactory(label='deliveryReceived', flow=flow, text='Was Delivery Received?') question_2 = TextQuestionFactory(label='dateOfReceipt', flow=flow, text='When was Delivery Received?') option_yes = OptionFactory(text='Yes', question=question_1) run = RunFactory(runnable=delivery) MultipleChoiceAnswerFactory(run=run, question=question_1, value=option_yes) TextAnswerFactory(run=run, question=question_2, value='2015-10-10') response = self.client.get('%s%d/%s/' % (ENDPOINT_URL, delivery.id, 'answers')) self.assertEqual(len(response.data), 2)
def setUp(self): self.consignee = ConsigneeFactory() self.item = ItemFactory() self.node = DeliveryNodeFactory( consignee=self.consignee, item=PurchaseOrderItemFactory(item=self.item)) web_flow = FlowFactory() self.amount_received = NumericQuestionFactory( label='amountReceived', when_answered='update_consignee_stock_level', flow=web_flow) self.was_item_received = MultipleChoiceQuestionFactory( label='itemReceived', when_answered='update_consignee_inventory', flow=web_flow) self.run = RunFactory(runnable=self.node) self.amount_received = NumericQuestion.objects.get( label='amountReceived', flow=web_flow) self.run = RunFactory(runnable=self.node)
def setUp(self): self.consignee = ConsigneeFactory() self.item = ItemFactory() self.node = DeliveryNodeFactory( consignee=self.consignee, item=PurchaseOrderItemFactory(item=self.item)) web_flow = FlowFactory() self.amount_received = NumericQuestionFactory( label='amountReceived', when_answered='update_consignee_stock_level', flow=web_flow) self.was_item_received = MultipleChoiceQuestionFactory( label='itemReceived', when_answered='update_consignee_inventory', flow=web_flow) option_yes = OptionFactory(question=self.was_item_received, text='Yes') OptionFactory(question=self.was_item_received, text='No') self.run = RunFactory(runnable=self.node) MultipleChoiceAnswerFactory(question=self.was_item_received, value=option_yes, run=self.run)
def test_should_return_answers_to_top_level_nodes_of_a_delivery(self): delivery = DeliveryFactory() node_one = DeliveryNodeFactory(distribution_plan=delivery) node_two = DeliveryNodeFactory(distribution_plan=delivery) flow = FlowFactory(label='WEB') question_1 = MultipleChoiceQuestionFactory(text='Was the item received?', label='itemReceived', flow=flow, position=1) option_1 = OptionFactory(text='Yes', question=question_1) question_2 = NumericQuestionFactory(text='How much was received?', label='amountReceived', flow=flow) question_3 = MultipleChoiceQuestionFactory(text='What is the quality of the product?', label='qualityOfProduct', flow=flow, position=3) option_3 = OptionFactory(text='Damaged', question=question_3) question_4 = MultipleChoiceQuestionFactory(text='Are you satisfied with the product?', label='satisfiedWithProduct', flow=flow, position=4) option_4 = OptionFactory(text='Yes', question=question_4) question_5 = TextQuestionFactory(text='Remarks', label='additionalDeliveryComments', flow=flow, position=5) run_one = RunFactory(runnable=node_one) MultipleChoiceAnswerFactory(question=question_1, run=run_one, value=option_1) NumericAnswerFactory(question=question_2, run=run_one, value=5) MultipleChoiceAnswerFactory(question=question_3, run=run_one, value=option_3) MultipleChoiceAnswerFactory(question=question_4, run=run_one, value=option_4) TextAnswerFactory(question=question_5, run=run_one, value='Answer1') run_two = RunFactory(runnable=node_two) MultipleChoiceAnswerFactory(question=question_1, run=run_two, value=option_1) NumericAnswerFactory(question=question_2, run=run_two, value=3) MultipleChoiceAnswerFactory(question=question_3, run=run_two, value=option_3) MultipleChoiceAnswerFactory(question=question_4, run=run_two, value=option_4) TextAnswerFactory(question=question_5, run=run_two, value='Answer2') response = self.client.get('%s%d/%s/' % (ENDPOINT_URL, delivery.id, 'node_answers')) self.assertEqual(len(response.data), 2)
def test_should_return_answers_for_all_first_level_nodes_in_a_delivery( self): delivery = DeliveryFactory() node_one = DeliveryNodeFactory(distribution_plan=delivery) node_two = DeliveryNodeFactory(distribution_plan=delivery) flow = FlowFactory(label='WEB') question_1 = MultipleChoiceQuestionFactory( text='Was the item received?', label='itemReceived', flow=flow, position=1) option_1 = OptionFactory(text='Yes', question=question_1) question_2 = NumericQuestionFactory(text='How much was received?', label='amountReceived', flow=flow) question_3 = MultipleChoiceQuestionFactory( text='What is the quality of the product?', label='qualityOfProduct', flow=flow, position=3) option_3 = OptionFactory(text='Damaged', question=question_3) question_4 = MultipleChoiceQuestionFactory( text='Are you satisfied with the product?', label='satisfiedWithProduct', flow=flow, position=4) option_4 = OptionFactory(text='Yes', question=question_4) question_5 = TextQuestionFactory(text='Remarks', label='additionalDeliveryComments', flow=flow, position=5) run_one = RunFactory(runnable=node_one) MultipleChoiceAnswerFactory(question=question_1, run=run_one, value=option_1) NumericAnswerFactory(question=question_2, run=run_one, value=5) MultipleChoiceAnswerFactory(question=question_3, run=run_one, value=option_3) MultipleChoiceAnswerFactory(question=question_4, run=run_one, value=option_4) TextAnswerFactory(question=question_5, run=run_one, value="Answer") run_two = RunFactory(runnable=node_two) MultipleChoiceAnswerFactory(question=question_1, run=run_two, value=option_1) NumericAnswerFactory(question=question_2, run=run_two, value=3) MultipleChoiceAnswerFactory(question=question_3, run=run_two, value=option_3) MultipleChoiceAnswerFactory(question=question_4, run=run_two, value=option_4) TextAnswerFactory(question=question_5, run=run_two, value="Answer") node_answers = delivery.node_answers() expected_multiple_choice_answer = { 'question_label': question_1.label, 'type': 'multipleChoice', 'text': question_1.text, 'value': 'Yes', 'options': ['Yes'], 'position': question_1.position } expected_text_answer = { 'question_label': question_5.label, 'type': 'text', 'text': question_5.text, 'value': 'Answer', 'position': question_5.position } self.assertEqual(len(node_answers), 2) self.assertIn(node_answers[0]['id'], [node_one.id, node_two.id]) self.assertEqual(len(node_answers[0]['answers']), 5) self.assertIn(expected_multiple_choice_answer, node_answers[0]['answers']) self.assertIn(node_answers[1]['id'], [node_one.id, node_two.id]) self.assertEqual(len(node_answers[1]['answers']), 5) self.assertIn(expected_text_answer, node_answers[1]['answers'])
def test_node_flow_is_end_user_for_end_user_node(self): end_user_flow = FlowFactory(label=Flow.Label.END_USER) runnable = DeliveryNodeFactory(tree_position=Flow.Label.END_USER) self.assertEqual(runnable.flow(), end_user_flow)
def setup_flow(self): self.ip_flow = FlowFactory(label=Flow.Label.IMPLEMENTING_PARTNER)
def test_should_know_question_given_label(self): label = 'someLabel' flow = FlowFactory() question = NumericQuestionFactory(label=label, flow=flow) self.assertEqual(flow.question_with(label=label), question)
def setup_nodes_with_answers(self): DistributionPlanNode.append_positive_answers = MagicMock(return_value=None) ip = ConsigneeFactory(name='ip one') middle_man = ConsigneeFactory(name='middle man one', type=Consignee.TYPES.middle_man) end_user_one = ConsigneeFactory(name='consignee one', type=Consignee.TYPES.end_user) end_user_two = ConsigneeFactory(name='consignee two', type=Consignee.TYPES.end_user) programme_one = ProgrammeFactory(name='my first programme') programme_two = ProgrammeFactory(name='my second programme') programme_three = ProgrammeFactory(name='my third programme') purchase_order_item = PurchaseOrderItemFactory(item=ItemFactory(description='Mama kit'), purchase_order=PurchaseOrderFactory(order_number=329293)) release_order_item = ReleaseOrderItemFactory(item=ItemFactory(description='Baba bla bla'), release_order=ReleaseOrderFactory(waybill=5540322)) ip_node_one = DeliveryNodeFactory(consignee=ip, item=purchase_order_item, quantity=1500, programme=programme_one, track=True, distribution_plan=DeliveryFactory(track=True), location='Fort portal', tree_position=Flow.Label.IMPLEMENTING_PARTNER) ip_node_two = DeliveryNodeFactory(consignee=ip, item=release_order_item, quantity=100, distribution_plan=DeliveryFactory(track=True), programme=programme_two, location='Kampala', tree_position=Flow.Label.IMPLEMENTING_PARTNER, track=True) ip_node_three = DeliveryNodeFactory(consignee=ip, item=release_order_item, quantity=100, distribution_plan=DeliveryFactory(track=True), programme=programme_two, location='Gulu', tree_position=Flow.Label.IMPLEMENTING_PARTNER, track=True) ip_node_four = DeliveryNodeFactory(consignee=ip, item=purchase_order_item, quantity=100, distribution_plan=DeliveryFactory(track=True), programme=programme_three, location='Gulu', tree_position=Flow.Label.IMPLEMENTING_PARTNER, track=True) middle_man_node = DeliveryNodeFactory(consignee=middle_man, item=purchase_order_item, programme=programme_one, location='Wakiso', track=True, tree_position=Flow.Label.MIDDLE_MAN, parents=[(ip_node_one, 1500)], distribution_plan=None) end_user_node_one = DeliveryNodeFactory(consignee=end_user_one, item=purchase_order_item, parents=[(middle_man_node, 1000)], programme=programme_one, location='Amuru', track=True, distribution_plan=None) end_user_node_two = DeliveryNodeFactory(consignee=end_user_two, item=purchase_order_item, track=True, parents=[(middle_man_node, 500)], programme=programme_one, distribution_plan=None) assign_to_self_node = DeliveryNodeFactory(consignee=ip, item=purchase_order_item, tree_position=Flow.Label.END_USER, parents=[(ip_node_four, 93)], programme=programme_three, distribution_plan=None, is_assigned_to_self=True) # IP_ITEM Flow and Questions ip_item_flow = FlowFactory(label=Flow.Label.IMPLEMENTING_PARTNER) ip_item_question_1 = MultipleChoiceQuestionFactory(text='Was the item received?', label='itemReceived', when_answered='update_consignee_inventory', flow=ip_item_flow, position=1) ip_item_option_1 = OptionFactory(text='Yes', question=ip_item_question_1) ip_item_option_no = OptionFactory(text='No', question=ip_item_question_1) ip_item_question_2 = NumericQuestionFactory(text='How much was received?', label='amountReceived', when_answered='update_consignee_stock_level', flow=ip_item_flow, position=3) ip_item_question_3 = MultipleChoiceQuestionFactory(text='What is the quality of the product?', label='qualityOfProduct', flow=ip_item_flow, position=3) ip_item_option_2 = OptionFactory(text='Good', question=ip_item_question_3) ip_item_option_3 = OptionFactory(text='Damaged', question=ip_item_question_3) ip_item_question_4 = MultipleChoiceQuestionFactory(text='Are you satisfied with the product?', label='satisfiedWithProduct', flow=ip_item_flow, position=4) ip_item_option_4 = OptionFactory(text='Yes', question=ip_item_question_4) ip_item_option_5 = OptionFactory(text='No', question=ip_item_question_4) # MIDDLE_MAN Flow and Questions middle_man_flow = FlowFactory(label=Flow.Label.MIDDLE_MAN) mm_question_1 = MultipleChoiceQuestionFactory(text='Was product received?', label='productReceived', flow=middle_man_flow, position=1) mm_option_1 = OptionFactory(text='Yes', question=mm_question_1) mm_option_2 = OptionFactory(text='No', question=mm_question_1) mm_question_2 = TextQuestionFactory(label='dateOfReceipt', flow=middle_man_flow, text='When was item received?', position=2) mm_question_3 = NumericQuestionFactory(text='What is the amount received?', label='amountReceived', flow=middle_man_flow, position=3) end_user_flow = FlowFactory(label=Flow.Label.END_USER) eu_question_1 = MultipleChoiceQuestionFactory(text='Was the item received?', label='itemReceived', flow=end_user_flow, position=1) eu_option_1 = OptionFactory(text='Yes', question=eu_question_1) eu_question_2 = NumericQuestionFactory(text='How much was received?', label='amountReceived', flow=end_user_flow) eu_question_3 = MultipleChoiceQuestionFactory(text='What is the quality of the product?', label='qualityOfProduct', flow=end_user_flow, position=3) eu_option_3 = OptionFactory(text='Damaged', question=eu_question_3) eu_option_3_1 = OptionFactory(text='Good', question=eu_question_3) eu_question_4 = MultipleChoiceQuestionFactory(text='Are you satisfied with the product?', label='satisfiedWithProduct', flow=end_user_flow, position=4) eu_option_4 = OptionFactory(text='Yes', question=eu_question_4) eu_question_5 = TextQuestionFactory(label='dateOfReceipt', flow=end_user_flow, text='When was Delivery Received?') ip_run_one = RunFactory(runnable=ip_node_one) MultipleChoiceAnswerFactory(question=ip_item_question_1, run=ip_run_one, value=ip_item_option_1) NumericAnswerFactory(question=ip_item_question_2, run=ip_run_one, value=1500) MultipleChoiceAnswerFactory(question=ip_item_question_3, run=ip_run_one, value=ip_item_option_2) MultipleChoiceAnswerFactory(question=ip_item_question_4, run=ip_run_one, value=ip_item_option_4) ip_run_three = RunFactory(runnable=ip_node_three) MultipleChoiceAnswerFactory(question=ip_item_question_1, run=ip_run_three, value=ip_item_option_no) ip_run_two = RunFactory(runnable=ip_node_two) MultipleChoiceAnswerFactory(question=ip_item_question_1, run=ip_run_two, value=ip_item_option_1) NumericAnswerFactory(question=ip_item_question_2, run=ip_run_two, value=50) MultipleChoiceAnswerFactory(question=ip_item_question_3, run=ip_run_two, value=ip_item_option_3) MultipleChoiceAnswerFactory(question=ip_item_question_4, run=ip_run_two, value=ip_item_option_5) middle_man_node_run = RunFactory(runnable=middle_man_node) MultipleChoiceAnswerFactory(question=mm_question_1, run=middle_man_node_run, value=mm_option_1) TextAnswerFactory(question=mm_question_2, run=middle_man_node_run, value='2014-9-25') NumericAnswerFactory(question=mm_question_3, run=middle_man_node_run, value=1501, remark='Some remark 2') end_user_run_one = RunFactory(runnable=end_user_node_one) MultipleChoiceAnswerFactory(question=eu_question_1, run=end_user_run_one, value=eu_option_1) NumericAnswerFactory(question=eu_question_2, run=end_user_run_one, value=5) MultipleChoiceAnswerFactory(question=eu_question_3, run=end_user_run_one, value=eu_option_3) MultipleChoiceAnswerFactory(question=eu_question_4, run=end_user_run_one, value=eu_option_4) TextAnswerFactory(run=end_user_run_one, question=eu_question_5, value='2014-10-10') end_user_run_two = RunFactory(runnable=end_user_node_two) MultipleChoiceAnswerFactory(question=eu_question_1, run=end_user_run_two, value=eu_option_1) NumericAnswerFactory(question=eu_question_2, run=end_user_run_two, value=500) MultipleChoiceAnswerFactory(question=eu_question_3, run=end_user_run_two, value=eu_option_3) MultipleChoiceAnswerFactory(question=eu_question_4, run=end_user_run_two, value=eu_option_4) TextAnswerFactory(question=eu_question_5, run=end_user_run_two, value='2013-12-12') assign_to_self_run = RunFactory(runnable=assign_to_self_node) MultipleChoiceAnswerFactory(question=eu_question_1, run=assign_to_self_run, value=eu_option_1) NumericAnswerFactory(question=eu_question_2, run=assign_to_self_run, value=500) TextAnswerFactory(question=eu_question_5, run=assign_to_self_run, value='2013-12-14') MultipleChoiceAnswerFactory(question=eu_question_3, run=assign_to_self_run, value=eu_option_3_1) MultipleChoiceAnswerFactory(question=eu_question_4, run=assign_to_self_run, value=eu_option_4) return end_user_node_one, purchase_order_item, release_order_item, end_user_node_two, ip_node_two, ip, assign_to_self_node
def setUp(self): self.flow_ip = FlowFactory(label=Flow.Label.IMPLEMENTING_PARTNER) FlowFactory(label=Flow.Label.END_USER) FlowFactory(label=Flow.Label.MIDDLE_MAN) super(AlertEndpointTest, self).setUp()
def test_delivery_flow_is_ipflow_for_ip(self): ip_flow = FlowFactory(label=Flow.Label.IMPLEMENTING_PARTNER) runnable = DeliveryFactory() self.assertEqual(runnable.flow(), ip_flow)