Пример #1
0
    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
Пример #2
0
    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)
Пример #3
0
    def test_gets_all_response_for_node_consignee(self):
        multichoice_question = MultipleChoiceQuestionFactory(label='productReceived')
        yes_option = OptionFactory(text='Yes', question=multichoice_question)
        no_option = OptionFactory(text='No', question=multichoice_question)

        sugar = ItemFactory(description='Sugar')
        salt = ItemFactory(description='Salt')

        numeric_question = NumericQuestionFactory(label='AmountReceived')
        item = SalesOrderItemFactory(item=salt, description='10 bags of salt')

        salt_node = DeliveryNodeFactory(quantity=100, item=PurchaseOrderItemFactory(sales_order_item=item))
        run = RunFactory(runnable=salt_node, status='completed')

        sugar_item = SalesOrderItemFactory(item=sugar, description='10 bags of sugar')
        sugar_node = DeliveryNodeFactory(quantity=100, item=PurchaseOrderItemFactory(sales_order_item=sugar_item))
        sugar_run = RunFactory(runnable=sugar_node, status='completed')

        multiple_answer_one = MultipleChoiceAnswerFactory(run=run, question=multichoice_question, value=yes_option)
        numeric_answer_one = NumericAnswerFactory(run=run, value=80, question=numeric_question)

        multiple_answer_two = MultipleChoiceAnswerFactory(run=sugar_run, question=multichoice_question, value=no_option)
        numeric_answer_two = NumericAnswerFactory(run=sugar_run, value=80, question=numeric_question)
        salt_node_responses = salt_node.responses()
        sugar_node_responses = sugar_node.responses()

        self.assertIn(multiple_answer_one, salt_node_responses[run])
        self.assertIn(numeric_answer_one, salt_node_responses[run])

        self.assertIn(multiple_answer_two, sugar_node_responses[sugar_run])
        self.assertIn(numeric_answer_two, sugar_node_responses[sugar_run])
Пример #4
0
    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'])
Пример #5
0
    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 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')
Пример #7
0
    def test_should_add_node_related_to_changed_multiple_choice_answer_to_sync_data(
            self, mock_scan):
        node = DeliveryNodeFactory()
        question = MultipleChoiceQuestionFactory()
        answer = MultipleChoiceAnswerFactory(
            value=OptionFactory(question=question),
            question=question,
            run=RunFactory(runnable=node))

        self.check_update_happens(node, answer, {
            'field': 'value',
            'value': OptionFactory(question=question)
        }, {'term': {
            'responses.id': [answer.id]
        }}, mock_scan)
Пример #8
0
    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)
Пример #9
0
    def create_questions_and_items(self):
        self.multiple_choice_question_two = MultipleChoiceQuestionFactory(
            label='satisfiedWithProduct')
        self.multiple_choice_question = MultipleChoiceQuestionFactory(
            label='productReceived')

        self.yes_option = OptionFactory(text='Yes',
                                        question=self.multiple_choice_question)
        OptionFactory(text='No', question=self.multiple_choice_question)

        self.numeric_question = NumericQuestionFactory(label='amountReceived')

        salt = ItemFactory(description='Salt')
        self.sales_order_item = SalesOrderItemFactory(
            item=salt, description='10 bags of salt')
        self.item = PurchaseOrderItemFactory(item=salt, value=1000)
Пример #10
0
    def test_should_return_false_when_delivery_run_was_cancelled(self):
        delivery = DeliveryFactory()
        question = MultipleChoiceQuestionFactory(label='deliveryReceived')
        option = OptionFactory(text='Yes', question=question)
        run = RunFactory(runnable=delivery, status=Run.STATUS.cancelled)

        MultipleChoiceAnswerFactory(run=run, question=question, value=option)
        self.assertFalse(delivery.is_received())
Пример #11
0
    def test_should_return_false_when_delivery_is_received_and_there_are_no_answers_for_some_nodes(
            self):
        delivery = DeliveryFactory()
        question = MultipleChoiceQuestionFactory(label='deliveryReceived')
        option = OptionFactory(text='Yes', question=question)
        run = RunFactory(runnable=delivery)

        MultipleChoiceAnswerFactory(run=run, question=question, value=option)

        node_one = DeliveryNodeFactory(distribution_plan=delivery)
        DeliveryNodeFactory(distribution_plan=delivery)

        item_question = MultipleChoiceQuestionFactory(label='itemReceived')
        yes_node_option = OptionFactory(text='Yes', question=item_question)
        MultipleChoiceAnswerFactory(run=RunFactory(runnable=node_one),
                                    question=item_question,
                                    value=yes_node_option)

        self.assertFalse(delivery.is_received())
Пример #12
0
    def test_should_provide_shipment_received_value_from_api(self):
        delivery = DeliveryFactory()
        question = MultipleChoiceQuestionFactory(label='deliveryReceived')
        option = OptionFactory(text='Yes', question=question)
        run = RunFactory(runnable=delivery)
        MultipleChoiceAnswerFactory(run=run, question=question, value=option)

        response = self.client.get(ENDPOINT_URL)

        self.assertEqual(response.data[0]['shipment_received'], True)
Пример #13
0
    def test_should_return_true_when_delivery_is_partially_received(self):
        delivery = DeliveryFactory()
        question = MultipleChoiceQuestionFactory(label='deliveryReceived')
        option = OptionFactory(text='Yes', question=question)
        run = RunFactory(runnable=delivery)

        self.assertFalse(delivery.is_received())

        MultipleChoiceAnswerFactory(run=run, question=question, value=option)

        self.assertTrue(delivery.is_partially_received())
Пример #14
0
    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)
Пример #15
0
 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)
Пример #16
0
    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 _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')
Пример #18
0
    def test_should_return_true_when_delivery_is_received_and_all_node_answers_are_received(
            self):
        delivery = DeliveryFactory()
        question = MultipleChoiceQuestionFactory(label='deliveryReceived')
        option = OptionFactory(text='Yes', question=question)
        run = RunFactory(runnable=delivery)

        MultipleChoiceAnswerFactory(run=run, question=question, value=option)

        node_one = DeliveryNodeFactory(distribution_plan=delivery)
        node_two = DeliveryNodeFactory(distribution_plan=delivery)

        item_question = MultipleChoiceQuestionFactory(label='itemReceived')
        option_two = OptionFactory(text='Yes', question=item_question)
        MultipleChoiceAnswerFactory(run=RunFactory(runnable=node_one),
                                    question=item_question,
                                    value=option_two)
        MultipleChoiceAnswerFactory(run=RunFactory(runnable=node_two),
                                    question=item_question,
                                    value=option_two)

        self.assertTrue(delivery.is_received())
Пример #19
0
    def test_should_return_false_when_delivery_is_received_but_no_answers_have_been_received_for_its_nodes(
            self):
        delivery = DeliveryFactory()
        question = MultipleChoiceQuestionFactory(label='deliveryReceived')
        option = OptionFactory(text='Yes', question=question)

        run = RunFactory(runnable=delivery)

        DeliveryNodeFactory(distribution_plan=delivery)
        DeliveryNodeFactory(distribution_plan=delivery)

        MultipleChoiceAnswerFactory(run=run, question=question, value=option)

        self.assertFalse(delivery.is_received())
Пример #20
0
    def test_should_confirm_delivery_when_all_nodes_are_answered(self):
        delivery = DeliveryFactory()
        node_one = DeliveryNodeFactory(distribution_plan=delivery)
        node_two = DeliveryNodeFactory(distribution_plan=delivery)

        item_question = MultipleChoiceQuestionFactory(label='itemReceived')
        option_one = OptionFactory(text='Yes', question=item_question)
        option_two = OptionFactory(text='No', question=item_question)

        delivery.confirm()
        self.assertFalse(delivery.confirmed)

        MultipleChoiceAnswerFactory(run=RunFactory(runnable=node_one),
                                    question=item_question,
                                    value=option_one)
        delivery.confirm()
        self.assertFalse(delivery.confirmed)

        MultipleChoiceAnswerFactory(run=RunFactory(runnable=node_two),
                                    question=item_question,
                                    value=option_two)
        delivery.confirm()
        self.assertTrue(delivery.confirmed)
Пример #21
0
    def test_should_return_true_when_shipment_is_received_regardless_of_confirmation_of_items(
            self):
        delivery = DeliveryFactory()
        question = MultipleChoiceQuestionFactory(label='deliveryReceived')
        option = OptionFactory(text='Yes', question=question)

        run = RunFactory(runnable=delivery)

        DeliveryNodeFactory(distribution_plan=delivery)
        DeliveryNodeFactory(distribution_plan=delivery)

        MultipleChoiceAnswerFactory(run=run, question=question, value=option)

        self.assertTrue(delivery.shipment_received())
Пример #22
0
    def test_is_shipment_received_but_not_distributed_should_return_false(
            self):
        delivery = DeliveryFactory()
        question = MultipleChoiceQuestionFactory(
            label=Question.LABEL.deliveryReceived)
        option = OptionFactory(text='Yes', question=question)
        run = RunFactory(runnable=delivery)
        DeliveryNodeFactory(distribution_plan=delivery)
        DeliveryNodeFactory(distribution_plan=delivery,
                            tree_position=Flow.Label.IMPLEMENTING_PARTNER)
        MultipleChoiceAnswerFactory(run=run, question=question, value=option)

        self.assertFalse(
            self.flow_scheduler.is_shipment_received_but_not_distributed(
                delivery))
Пример #23
0
    def test_should_add_node_related_to_changed_option_to_sync_data(
            self, mock_scan):
        node = DeliveryNodeFactory()
        question = MultipleChoiceQuestionFactory()
        option = OptionFactory(question=question, text='Yes')
        MultipleChoiceAnswerFactory(value=option,
                                    question=question,
                                    run=RunFactory(runnable=node))

        self.check_update_happens(node, option, {
            'field': 'text',
            'value': 'Yes was received'
        }, {'term': {
            'responses.value_id': [option.id]
        }}, mock_scan)
Пример #24
0
 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)
Пример #25
0
    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)
Пример #26
0
    def test_should_get_latest_response(self):
        multichoice_question = MultipleChoiceQuestionFactory(label='productReceived')
        no_option = OptionFactory(text='No', question=multichoice_question)

        sugar = ItemFactory(description='Sugar')

        numeric_question = NumericQuestionFactory(label='AmountReceived')

        node = DeliveryNodeFactory(quantity=100, item=PurchaseOrderItemFactory(item=sugar))
        run = RunFactory(runnable=node, status='completed')

        self.assertIsNone(node.latest_response())

        multiple_answer = MultipleChoiceAnswerFactory(run=run, question=multichoice_question, value=no_option)
        self.assertEqual(node.latest_response(), multiple_answer)

        numeric_answer = NumericAnswerFactory(run=run, value=80, question=numeric_question)
        self.assertEqual(node.latest_response(), numeric_answer)
Пример #27
0
    def test_should_only_return_implementing_partner_responses(self):
        question = MultipleChoiceQuestionFactory(label='productReceived')
        yes_option = OptionFactory(text='Yes', question=question)

        item = ItemFactory(description='Salt')
        order_item = PurchaseOrderItemFactory(item=item, value=1000)

        node_ip_one = DeliveryNodeFactory(
            tree_position=DistributionPlanNode.IMPLEMENTING_PARTNER,
            item=order_item)
        node_end_user = DeliveryNodeFactory(
            tree_position=DistributionPlanNode.END_USER, item=order_item)

        run_one = RunFactory(runnable=node_ip_one, status='completed')
        run_two = RunFactory(runnable=node_end_user, status='completed')

        answer_one = MultipleChoiceAnswerFactory(run=run_one,
                                                 question=question,
                                                 value=yes_option)
        MultipleChoiceAnswerFactory(run=run_two,
                                    question=question,
                                    value=yes_option)

        response = self.client.get(IP_ENDPOINT_URL, format='json')

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)

        node_item = response.data[0]

        self.assertEqual(node_item['item'], 'Salt')
        self.assertEqual(
            node_item['programme'], {
                'id': node_ip_one.distribution_plan.programme.id,
                'name': node_ip_one.distribution_plan.programme.name
            })
        self.assertEqual(node_item['ip'], {
            'id': node_ip_one.ip.id,
            'location': unicode(node_ip_one.ip.location)
        })
        self.assertEqual(node_item[question.label], answer_one.format())
Пример #28
0
    def test_should_get_all_questions_and_responses(self):
        run = RunFactory()

        item_received_question = MultipleChoiceQuestionFactory(
            label='product_received')
        yes = OptionFactory(question=item_received_question, text='Yes')
        item_received_question.answers.create(value=yes, run=run)

        date_received_question = TextQuestionFactory(label='date_received')
        date_received_question.textanswer_set.create(value='2014-01-01',
                                                     run=run)

        quantity_received_question = NumericQuestionFactory(
            label='quantity_received')
        quantity_received_question.numericanswer_set.create(value=12, run=run)

        expected_data = {
            'product_received': 'Yes',
            'quantity_received': 12,
            'date_received': '2014-01-01'
        }
        self.assertDictEqual(run.questions_and_responses(), expected_data)
Пример #29
0
 def __prepare_for_is_distribution_expired_test(self, delivery):
     flow = Flow.objects.get(label=Flow.Label.IMPLEMENTING_PARTNER)
     question_is_received = MultipleChoiceQuestionFactory(
         label=Question.LABEL.deliveryReceived, flow=flow)
     question_received_date = TextQuestionFactory(
         label=Question.LABEL.dateOfReceipt, flow=flow)
     option_is_received = OptionFactory(text='Yes',
                                        question=question_is_received)
     run = RunFactory(runnable=delivery)
     DeliveryNodeFactory(distribution_plan=delivery,
                         tree_position=Flow.Label.IMPLEMENTING_PARTNER)
     DeliveryNodeFactory(distribution_plan=delivery,
                         tree_position=Flow.Label.IMPLEMENTING_PARTNER)
     MultipleChoiceAnswerFactory(run=run,
                                 question=question_is_received,
                                 value=option_is_received)
     datetime_span = (
         datetime.datetime.today() -
         datetime.timedelta(days=8)).strftime('%Y-%m-%dT%H:%M:%S')
     TextAnswerFactory(run=run,
                       question=question_received_date,
                       value=datetime_span)
Пример #30
0
    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