Exemplo n.º 1
0
    def test_should_save_numeric_answer(self):
        numeric_question = NumericQuestionFactory(text='How old are you?')
        number = 20
        params = {'text': number}

        numeric_question.create_answer(params, self.run)
        answers = numeric_question.numericanswer_set.all()

        self.assertEqual(answers.count(), 1)
        self.assertEqual(answers.first().value, number)
Exemplo n.º 2
0
    def test_should_mark_run_returned_by_dequeue_as_started(
            self, mock_run_queue_dequeue, *_):
        uuid = '18aed9e2-125c-4c6d-a73d-c7ecdb53aa8c'

        question = NumericQuestionFactory(
            text='How much was received?',
            label='amountReceived',
            flow=self.flow,
        )
        self.flow.final_end_nodes = [[question.id, Flow.NO_OPTION]]
        self.flow.save()

        current_node = DeliveryNodeFactory()
        next_node = copy.deepcopy(current_node)

        RunFactory(runnable=current_node, phone=self.PHONE)
        next_run_queue = RunQueueFactory(
            runnable=next_node,
            contact_person_id=current_node.contact_person_id)

        mock_run_queue_dequeue.return_value = next_run_queue

        url_params = self._create_rapid_pro_url_params(self.PHONE, uuid, '42',
                                                       None, 'amountReceived')
        self.client.post(HOOK_URL, url_params)

        run_returned_by_dequeue = RunQueue.objects.get(id=next_run_queue.id)

        self.assertEqual(run_returned_by_dequeue.status,
                         RunQueue.STATUS.started)
Exemplo n.º 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])
Exemplo n.º 4
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
Exemplo n.º 5
0
    def test_should_mark_run_as_complete_when_question_is_final(
            self, mock_run_queue_dequeue, mock_schedule_next_run, *_):
        mock_schedule_next_run.return_value = None
        uuid = '18aed9e2-125c-4c6d-a73d-c7ecdb53aa8c'

        question = NumericQuestionFactory(text='How much was received?',
                                          label='amountReceived',
                                          flow=self.flow)

        node = DeliveryNodeFactory()
        run = RunFactory(runnable=node,
                         phone=self.PHONE,
                         status=Run.STATUS.scheduled)

        mock_run_queue_dequeue.return_value = RunQueueFactory(
            runnable=node, contact_person_id=node.contact_person_id)
        self.flow.end_nodes = [[question.id, Flow.NO_OPTION]]
        self.flow.save()

        url_params = self._create_rapid_pro_url_params(self.PHONE, uuid, '42',
                                                       None, 'amountReceived')
        self.client.post(HOOK_URL, url_params)

        run = Run.objects.get(id=run.id)
        self.assertEqual(run.status, Run.STATUS.completed)
Exemplo n.º 6
0
 def __login_and_update_existing_numeric_answer(self, login_func,
                                                updated_numeric_answer):
     login_func()
     numeric_question = NumericQuestionFactory(label='amountReceived')
     numeric_answer = NumericAnswerFactory(value=1,
                                           question=numeric_question)
     return self.client.patch(ENDPOINT_URL + str(numeric_answer.id) + "/",
                              updated_numeric_answer,
                              format='json')
Exemplo n.º 7
0
    def test_questions_should_have_type_with_default_values(self):
        text_question = TextQuestionFactory()
        self.assertEqual(text_question.type, 'text')

        numeric_question = NumericQuestionFactory()
        self.assertEqual(numeric_question.type, 'numeric')

        multiple_choice_question = MultipleChoiceQuestionFactory()
        self.assertEqual(multiple_choice_question.type, 'multipleChoice')
Exemplo n.º 8
0
    def test_should_serialise_node_with_value_lost(self):
        po_item = PurchaseOrderItemFactory(quantity=108, value=33)
        node = DeliveryNodeFactory(quantity=100, item=po_item)
        amount_received_qn = NumericQuestionFactory(label='amountReceived')
        run = RunFactory(runnable=node)
        NumericAnswerFactory(question=amount_received_qn, run=run, value=53)

        serialised = serialise_nodes([node])
        self.assertDictContainsSubset({'value_lost': 14.36}, serialised[0])
Exemplo n.º 9
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)
Exemplo n.º 10
0
    def test_should_add_node_related_to_changed_numeric_answer_to_sync_data(
            self, mock_scan):
        node = DeliveryNodeFactory()
        answer = NumericAnswerFactory(value=50,
                                      question=NumericQuestionFactory(),
                                      run=RunFactory(runnable=node))

        self.check_update_happens(node, answer, {
            'field': 'value',
            'value': 100
        }, {'term': {
            'responses.id': [answer.id]
        }}, mock_scan)
Exemplo n.º 11
0
    def test_should_update_numeric_answers(self):
        numeric_question = NumericQuestionFactory(label='amountReceived')
        numeric_answer = NumericAnswerFactory(value=1,
                                              question=numeric_question)
        updated_numeric_answer_details = {"value": 2}
        response = self.client.patch(ENDPOINT_URL + str(numeric_answer.id) +
                                     "/",
                                     updated_numeric_answer_details,
                                     format='json')

        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(updated_numeric_answer_details,
                                      response.data)
Exemplo n.º 12
0
 def test_should_add_node_related_to_deleted_numeric_answer_to_sync_data(
         self, mock_scan):
     node = DeliveryNodeFactory()
     answer = NumericAnswerFactory(run=RunFactory(runnable=node),
                                   question=NumericQuestionFactory())
     self.check_update_happens(
         node,
         answer,
         delete=True,
         mock_scan=mock_scan,
         expected_match_clause={'term': {
             'id': [node.id]
         }})
Exemplo n.º 13
0
    def test_should_create_numeric_answers(self):
        numeric_question = NumericQuestionFactory(label='dateOfReceipt')
        run = RunFactory()
        numeric_answer_details = {
            "value": 1,
            "question": numeric_question.id,
            "run": run.id
        }
        response = self.client.post(ENDPOINT_URL,
                                    numeric_answer_details,
                                    format='json')

        self.assertEqual(response.status_code, 201)
        self.assertDictContainsSubset(numeric_answer_details, response.data)
Exemplo n.º 14
0
    def test_should_get_Numeric_answers(self):
        numeric_question = NumericQuestionFactory(label='amountReceived')
        numeric_answer = NumericAnswerFactory(value=1,
                                              question=numeric_question)
        numeric_answer_details = {
            "id": numeric_answer.id,
            "value": numeric_answer.value,
            "question": numeric_answer.question_id,
            "run": numeric_answer.run_id
        }
        response = self.client.get(ENDPOINT_URL)

        self.assertEqual(response.status_code, 200)
        self.assertDictContainsSubset(numeric_answer_details, response.data[0])
Exemplo n.º 15
0
    def log_and_assert_create_web_answer_permission(self, log_func, expected_status_code):
        log_func()
        self.setup_flow_with_questions(Flow.Label.WEB)
        web_flow = Flow.objects.filter(label=Flow.Label.WEB).first()
        NumericQuestionFactory(label='quantityDelivered', flow=web_flow)

        node = DeliveryNodeFactory()
        request_body = {
            'runnable': node.id, 'answers': [
                {'question_label': 'deliveryReceived', 'value': 'Yes'},
                {'question_label': 'quantityDelivered', 'value': '2'}
            ]}

        response = self.client.post(ENDPOINT_URL, data=json.dumps(request_body), content_type='application/json')
        self.assertEqual(response.status_code, expected_status_code)
Exemplo n.º 16
0
    def test_should_save_numeric_answers(self):
        self.setup_flow_with_questions(Flow.Label.WEB)
        web_flow = Flow.objects.filter(label=Flow.Label.WEB).first()
        NumericQuestionFactory(label='quantityDelivered', flow=web_flow)

        node = DeliveryNodeFactory()
        data = {
            'runnable': node.id, 'answers': [
                {'question_label': 'deliveryReceived', 'value': 'Yes'},
                {'question_label': 'quantityDelivered', 'value': '2'}
            ]}

        self.client.post(ENDPOINT_URL, data=json.dumps(data), content_type='application/json')

        self.assertEqual(len(NumericAnswer.objects.filter(question__flow=web_flow)), 1)
        self.assertTrue(self.mock_distribution_alert_raise.delay.called)
Exemplo n.º 17
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)
Exemplo n.º 18
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)
Exemplo n.º 19
0
    def test_should_call_alert_handler_when_last_question_answered(
            self, mock_run_queue_dequeue, mock_dequeue_next_run,
            mock_response_alert_handler_process, *_):
        question = NumericQuestionFactory(text='some text',
                                          label='someLabel',
                                          flow=self.flow)

        node = DeliveryNodeFactory()
        RunFactory(runnable=node,
                   phone=self.PHONE,
                   status=Run.STATUS.scheduled)

        self.flow.final_end_nodes = [[question.id, Flow.NO_OPTION]]
        self.flow.save()

        url_params = self._create_rapid_pro_url_params(self.PHONE, '1234',
                                                       '42', None, 'someLabel')
        self.client.post(HOOK_URL, url_params)

        self.assertTrue(mock_response_alert_handler_process.called)
Exemplo n.º 20
0
    def test_should_record_an_answer_of_type_numeric_for_a_node_from_request_data(
            self, *_):
        uuid = '18aed9e2-125c-4c6d-a73d-c7ecdb53aa8c'

        NumericQuestionFactory(text='How much was received?',
                               label='amountReceived',
                               flow=self.flow)

        run = RunFactory(phone=('%s' % self.PHONE))
        url_params = self._create_rapid_pro_url_params(self.PHONE, uuid, 42,
                                                       None, 'amountReceived')

        response = self.client.post(HOOK_URL, url_params)

        answers = NumericAnswer.objects.filter(
            question__label='amountReceived', run=run)
        created_answer = answers.first()

        self.assertEqual(response.status_code, 200)
        self.assertEqual(created_answer.value, 42)
Exemplo n.º 21
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)
        self.run = RunFactory(runnable=self.node)

        self.amount_received = NumericQuestion.objects.get(
            label='amountReceived', flow=web_flow)
        self.run = RunFactory(runnable=self.node)
Exemplo n.º 22
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)
Exemplo n.º 23
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)
Exemplo n.º 24
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)
Exemplo n.º 25
0
    def test_should_dequeue_next_node_when_question_is_a_final_end_node(
            self, mock_run_queue_dequeue, mock_dequeue_next_run, *_):
        uuid = '18aed9e2-125c-4c6d-a73d-c7ecdb53aa8c'
        question = NumericQuestionFactory(text='How much was received?',
                                          label='amountReceived',
                                          flow=self.flow)
        self.flow.final_end_nodes = [[question.id, Flow.NO_OPTION]]
        self.flow.save()

        node = DeliveryNodeFactory()
        next_node = copy.deepcopy(node)
        current_run = RunFactory(runnable=node, phone=self.PHONE)
        next_runqueue = RunQueueFactory(
            runnable=next_node, contact_person_id=node.contact_person_id)

        mock_run_queue_dequeue.return_value = next_runqueue

        url_params = self._create_rapid_pro_url_params(self.PHONE, uuid, '42',
                                                       None, 'amountReceived')
        self.client.post(HOOK_URL, url_params)

        mock_dequeue_next_run.assert_called_with(node.contact_person_id, 10)
Exemplo n.º 26
0
 def setup_questions(self):
     TextQuestionFactory(label='dateOfReceipt', flow=self.ip_flow)
     NumericQuestionFactory(label='amountReceived', flow=self.ip_flow)
Exemplo n.º 27
0
    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'])
Exemplo n.º 28
0
    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)
Exemplo n.º 29
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
Exemplo n.º 30
0
 def prepare_test_data(self):
     numeric_question = NumericQuestionFactory(label='dateOfReceipt')
     run = RunFactory()
     return numeric_question, run