Exemplo n.º 1
0
    def test_should_get_sender_name(self):
        sender_name = 'Save the children'
        root_node = DeliveryNodeFactory(consignee=ConsigneeFactory(name=sender_name))
        self.assertEqual(root_node.sender_name(), 'UNICEF')

        node = DeliveryNodeFactory(parents=[(root_node, 5)])
        self.assertEqual(node.sender_name(), sender_name)
Exemplo n.º 2
0
    def test_delivery_node_knows_its_item_description(self):
        purchase_order = PurchaseOrderFactory(order_number=200)
        description = "some description"
        item = ItemFactory(description=description)
        po_node = DeliveryNodeFactory(item=PurchaseOrderItemFactory(purchase_order=purchase_order, item=item))

        self.assertEqual(po_node.item_description(), description)
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 test_should_create_alert_with_item_description(self, mock_contact):
        purchase_order = PurchaseOrderFactory(order_number=5678)
        description = "some description"
        item = ItemFactory(description=description)
        purchase_order_item = PurchaseOrderItemFactory(purchase_order=purchase_order, item=item)
        consignee = ConsigneeFactory(name="Liverpool FC")

        contact_person_id = 'some_id'
        contact = {u'_id': contact_person_id,
                   u'firstName': u'Chris',
                   u'lastName': u'George',
                   u'phone': u'+256781111111'}
        mock_contact.return_value = contact

        node = DeliveryNodeFactory(item=purchase_order_item, consignee=consignee, contact_person_id=contact_person_id)

        node.create_alert(Alert.ISSUE_TYPES.not_received)

        alerts = Alert.objects.filter(consignee_name="Liverpool FC", order_number=5678)
        self.assertEqual(alerts.count(), 1)
        alert = alerts.first()
        self.assertEqual(alert.order_type, PurchaseOrderItem.PURCHASE_ORDER)
        self.assertEqual(alert.order_number, 5678)
        self.assertEqual(alert.consignee_name, "Liverpool FC")
        self.assertEqual(alert.contact['contact_name'], "Chris George")
        self.assertEqual(alert.issue, Alert.ISSUE_TYPES.not_received)
        self.assertFalse(alert.is_resolved)
        self.assertIsNone(alert.remarks)
        self.assertEqual(alert.runnable, node)
        self.assertEqual(alert.item_description, description)
Exemplo n.º 5
0
    def test_should_delete_node_from_elasticsearch_when_deleted(self):
        node = DeliveryNodeFactory()
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)

        node.delete()
        nodes_to_delete = list_nodes_to_delete()

        self.assertIn(node.id, nodes_to_delete)
Exemplo n.º 6
0
    def test_should_return_parent_consignee_name_as_sender_for_node_when_parent(
            self):
        parent_consignee = ConsigneeFactory(name="Arsenal Fan Club")
        parent_node = DeliveryNodeFactory(consignee=parent_consignee)
        child_node = DeliveryNodeFactory(parents=[(parent_node, 5)])
        message = DeliveryRunMessage(child_node)

        self.assertEqual(message.sender_name(), "Arsenal Fan Club")
Exemplo n.º 7
0
    def test_should_delete_tracked_node_on_update_with_zero_quantity(self):
        node = DeliveryNodeFactory(quantity=10, track=True)
        self.assertEqual(DeliveryNode.objects.count(), 1)

        node.quantity = 0
        returned_node = node.save()
        self.assertEqual(DeliveryNode.objects.count(), 0)
        self.assertTrue(isinstance(returned_node, DeliveryNode))
Exemplo n.º 8
0
    def test_should_delete_tracked_node_on_update_with_zero_quantity(self):
        node = DeliveryNodeFactory(quantity=10, track=True)
        self.assertEqual(DeliveryNode.objects.count(), 1)

        node.quantity = 0
        returned_node = node.save()
        self.assertEqual(DeliveryNode.objects.count(), 0)
        self.assertTrue(isinstance(returned_node, DeliveryNode))
Exemplo n.º 9
0
    def test_should_ignore_updates_to_quantity_on_non_root_node(self):
        node_one = DeliveryNodeFactory()
        node = DeliveryNodeFactory(parents=[{'id': node_one.id, 'quantity': 7}])

        node.quantity = 50
        node.save()

        self.assertEqual(node.quantity_in(), 7)
Exemplo n.º 10
0
    def test_delivery_node_knows_its_item_description(self):
        purchase_order = PurchaseOrderFactory(order_number=200)
        description = "some description"
        item = ItemFactory(description=description)
        po_node = DeliveryNodeFactory(item=PurchaseOrderItemFactory(
            purchase_order=purchase_order, item=item))

        self.assertEqual(po_node.item_description(), description)
Exemplo n.º 11
0
    def test_should_know_its_order_number(self):
        purchase_order = PurchaseOrderFactory(order_number=200)
        po_node = DeliveryNodeFactory(item=PurchaseOrderItemFactory(purchase_order=purchase_order))
        self.assertEqual(po_node.order_number(), 200)

        release_order = ReleaseOrderFactory(waybill=300)
        ro_node = DeliveryNodeFactory(item=ReleaseOrderItemFactory(release_order=release_order))
        self.assertEqual(ro_node.order_number(), 300)
Exemplo n.º 12
0
    def test_should_schedule_flow_to_start_after_buffer_when_calculated_send_time_is_in_past(self):
        some_date = FakeDate.today() - datetime.timedelta(days=10)
        node = NodeFactory(delivery_date=some_date)
        node.build_contact = MagicMock(return_value=self.contact)

        schedule_run_for(node)

        self.assertEqual(mock_celery.invoked_after, 10.0)
    def test_returned_nodes_should_have_order_type_field(self):
        po_node = DeliveryNodeFactory(item=PurchaseOrderItemFactory(purchase_order=(PurchaseOrderFactory())))
        ro_node = DeliveryNodeFactory(item=ReleaseOrderItemFactory(release_order=(ReleaseOrderFactory())))

        response = self.client.get(ENDPOINT_URL)
        node_order_types = [node['order_type'] for node in response.data]

        self.assertItemsEqual([po_node.type(), ro_node.type()], node_order_types)
    def setup_responses(self):
        DeliveryNode.objects.all().delete()
        MultipleChoiceQuestion.objects.all().delete()
        MultipleChoiceAnswer.objects.all().delete()
        from eums.fixtures.ip_questions import seed_ip_questions
        questions, options, _ = seed_ip_questions()

        self.programme = ProgrammeFactory(name='my-program')
        self.ip = ConsigneeFactory()

        self.today = FakeDate.today()
        po_item = PurchaseOrderItemFactory(quantity=100, value=1000)
        ip_delivery_one = DeliveryFactory(location='some location',
                                          track=True,
                                          programme=self.programme,
                                          consignee=self.ip,
                                          ip=self.ip,
                                          delivery_date=self.today +
                                          datetime.timedelta(days=3))

        DeliveryNodeFactory(tree_position=DeliveryNode.IMPLEMENTING_PARTNER,
                            quantity=10,
                            item=po_item,
                            distribution_plan=ip_delivery_one,
                            consignee=self.ip)

        other_delivery = DeliveryFactory(location='Other location',
                                         delivery_date=self.today,
                                         track=True)
        DeliveryNodeFactory(tree_position=DeliveryNode.IMPLEMENTING_PARTNER,
                            quantity=20,
                            item=po_item,
                            distribution_plan=other_delivery)

        MultipleChoiceAnswerFactory(
            run=RunFactory(runnable=ip_delivery_one,
                           status=Run.STATUS.scheduled),
            question=questions['WAS_DELIVERY_RECEIVED'],
            value=options['DELIVERY_WAS_RECEIVED'])

        MultipleChoiceAnswerFactory(
            run=RunFactory(runnable=ip_delivery_one,
                           status=Run.STATUS.scheduled),
            question=questions['IS_DELIVERY_IN_GOOD_ORDER'],
            value=options['IN_GOOD_CONDITION'])

        non_response_delivery_one = DeliveryFactory(delivery_date=self.today +
                                                    datetime.timedelta(days=4),
                                                    location='some location',
                                                    track=True)

        DeliveryNodeFactory(tree_position=DeliveryNode.IMPLEMENTING_PARTNER,
                            quantity=30,
                            item=po_item,
                            distribution_plan=non_response_delivery_one)

        RunFactory(runnable=non_response_delivery_one,
                   status=Run.STATUS.scheduled)
Exemplo n.º 15
0
    def test_node_should_calculate_total_value_from_order_item_value(self):
        po_item_one = PurchaseOrderItemFactory(value=400, quantity=200)
        po_item_two = PurchaseOrderItemFactory(value=600, quantity=100)

        node_one = DeliveryNodeFactory(item=po_item_one, quantity=50)
        node_two = DeliveryNodeFactory(item=po_item_two, quantity=50)

        self.assertEqual(node_one.total_value, 100)
        self.assertEqual(node_two.total_value, 300)
Exemplo n.º 16
0
    def test_should_queue_run_for_a_contact_if_contact_has_current_run_for_a_different_runnable(self,
                                                                                                mock_run_queue_enqueue):
        RunFactory(runnable=self.node)
        node_two = NodeFactory(contact_person_id=self.node.contact_person_id)
        node_two.build_contact = MagicMock(return_value=self.contact)
        mock_run_queue_enqueue.return_value = None
        schedule_run_for(node_two)

        mock_run_queue_enqueue.assert_called_with(node_two, ANY)
Exemplo n.º 17
0
    def test_should_queue_run_for_a_contact_if_contact_has_current_run_for_a_different_runnable(
            self, mock_run_queue_enqueue):
        RunFactory(runnable=self.node)
        node_two = NodeFactory(contact_person_id=self.node.contact_person_id)
        node_two.build_contact = MagicMock(return_value=self.contact)
        mock_run_queue_enqueue.return_value = None
        self.flow_scheduler.schedule_run_for(node_two)

        mock_run_queue_enqueue.assert_called_with(node_two, ANY)
Exemplo n.º 18
0
    def test_should_schedule_flow_to_start_after_buffer_when_calculated_send_time_is_in_past(
            self):
        some_date = FakeDate.today() - datetime.timedelta(days=10)
        node = NodeFactory(delivery_date=some_date)
        node.build_contact = MagicMock(return_value=self.contact)

        self.flow_scheduler.schedule_run_for(node)

        self.assertEqual(self.mock_celery.invoked_after, 10.0)
 def _create_node(self, delivery, is_purchase, order_number, track, tree_position, location='Madagascar'):
     if is_purchase:
         DeliveryNodeFactory(
                 track=track, distribution_plan=delivery, tree_position=tree_position, location=location,
                 item=PurchaseOrderItemFactory(purchase_order=PurchaseOrderFactory(order_number=order_number)))
     else:
         DeliveryNodeFactory(
                 track=track, distribution_plan=delivery, tree_position=tree_position, location=location,
                 item=ReleaseOrderItemFactory(release_order=ReleaseOrderFactory(waybill=order_number)))
Exemplo n.º 20
0
    def test_should_schedule_end_user_flow_if_node_tree_position_is_end_user(self):
        node = NodeFactory(tree_position=Node.END_USER)
        node.build_contact = MagicMock(return_value=self.contact)

        Runnable.objects.get = MagicMock(return_value=node)

        self.flow_scheduler.schedule_run_for(node)

        self.mocked_create_run.assert_called_with(self.contact, self.end_user_flow, ANY, ANY)
Exemplo n.º 21
0
    def test_nodes_should_be_saved_with_their_ip(self):
        consignee = ConsigneeFactory()
        root = DeliveryNodeFactory(consignee=consignee, quantity=100)
        child = DeliveryNodeFactory(parents=[(root, 60)])
        grandchild = DeliveryNodeFactory(parents=[(child, 30)])

        self.assertEqual(root.ip, consignee)
        self.assertEqual(child.ip, consignee)
        self.assertEqual(grandchild.ip, consignee)
Exemplo n.º 22
0
    def test_should_return_no_results_when_from_date_greater_than_all_dates_on_nodes(self):
        DeliveryNodeFactory(delivery_date=datetime.date(2015, 10, 1), tree_position=Flow.Label.IMPLEMENTING_PARTNER)
        DeliveryNodeFactory(delivery_date=datetime.date(2015, 11, 1), tree_position=Flow.Label.IMPLEMENTING_PARTNER)

        endpoint_url = BACKEND_URL + 'stock-report?fromDate=2015-11-15'
        response = self.client.get(endpoint_url)

        results = response.data['results']
        self.assertEqual(len(results), 0)
Exemplo n.º 23
0
    def test_should_compute_quantity_out_from_outgoing_arcs(self):
        node_one = DeliveryNodeFactory(quantity=50)
        node_two = DeliveryNodeFactory()
        ArcFactory(source=node_one, target=node_two, quantity=50)
        self.assertEqual(node_one.quantity_out(), 50)
        self.assertEqual(node_two.quantity_out(), 0)

        Arc.objects.all().delete()
        self.assertEqual(node_one.quantity_out(), 0)
Exemplo n.º 24
0
    def test_should_schedule_middleman_flow_if_node_tree_position_is_middleman(self):
        node = NodeFactory(tree_position=Node.MIDDLE_MAN)
        node.build_contact = MagicMock(return_value=self.contact)

        Runnable.objects.get = MagicMock(return_value=node)

        self.flow_scheduler.schedule_run_for(node)

        self.mocked_create_run.assert_called_with(self.contact, self.middle_man_flow, ANY, ANY)
Exemplo n.º 25
0
    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)
Exemplo n.º 26
0
    def test_should_return_list_of_children(self):
        parent_node = DeliveryNodeFactory(quantity=100)
        child_one = DeliveryNodeFactory(parents=[(parent_node, 30)])
        child_two = DeliveryNodeFactory(parents=[(parent_node, 20)])

        children = parent_node.children()
        self.assertEqual(children.count(), 2)
        self.assertIn(child_one, children)
        self.assertIn(child_two, children)
Exemplo n.º 27
0
 def test_should_filter_distribution_plan_nodes_by_contact_person_id(self):
     contact_person_id = '8541BD02-E862-48FD-952D-470445347DAE'
     DeliveryNodeFactory()
     node = DeliveryNodeFactory(contact_person_id=contact_person_id, additional_remarks='It is very good')
     self.assertEqual(DeliveryNode.objects.count(), 2)
     response = self.client.get('%s?contact_person_id=%s' % (ENDPOINT_URL, contact_person_id))
     self.assertEqual(len(response.data), 1)
     self.assertEqual(response.data[0]['id'], node.id)
     self.assertEqual(response.data[0]['additional_remarks'], node.additional_remarks)
Exemplo n.º 28
0
    def test_should_return_list_of_children(self):
        parent_node = DeliveryNodeFactory(quantity=100)
        child_one = DeliveryNodeFactory(parents=[(parent_node, 30)])
        child_two = DeliveryNodeFactory(parents=[(parent_node, 20)])

        children = parent_node.children()
        self.assertEqual(children.count(), 2)
        self.assertIn(child_one, children)
        self.assertIn(child_two, children)
Exemplo n.º 29
0
    def test_should_compute_quantity_in_from_incoming_arcs(self):
        node = DeliveryNodeFactory(quantity=0)
        ArcFactory(source=None, target=node, quantity=50)
        self.assertEqual(node.quantity_in(), 50)

        ArcFactory(source=None, target=node, quantity=50)
        self.assertEqual(node.quantity_in(), 100)

        Arc.objects.all().delete()
        self.assertEqual(node.quantity_in(), 0)
Exemplo n.º 30
0
    def test_should_add_changed_node_to_sync_data(self, *_):
        node = DeliveryNodeFactory(location='Kampala')
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        list_nodes_to_update()

        node.location = 'Changed location'
        node.save()
        nodes_to_sync = list_nodes_to_update()

        self.assertIn(node, nodes_to_sync)
Exemplo n.º 31
0
    def test_should_schedule_end_user_flow_if_node_tree_position_is_end_user(self):
        node = NodeFactory(tree_position=Node.END_USER)
        node.build_contact = MagicMock(return_value=self.contact)

        Runnable.objects.get = MagicMock(return_value=node)

        schedule_run_for(node)

        mock_start_delivery_run.assert_called_with(contact_person=self.contact, flow=self.END_USER_FLOW_ID,
                                                   item_description=ANY, sender=ANY)
Exemplo n.º 32
0
    def test_should_compute_quantity_in_from_incoming_arcs(self):
        node = DeliveryNodeFactory(quantity=0)
        ArcFactory(source=None, target=node, quantity=50)
        self.assertEqual(node.quantity_in(), 50)

        ArcFactory(source=None, target=node, quantity=50)
        self.assertEqual(node.quantity_in(), 100)

        Arc.objects.all().delete()
        self.assertEqual(node.quantity_in(), 0)
Exemplo n.º 33
0
    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)
Exemplo n.º 34
0
    def test_update_should_leave_parents_intact_if_parents_are_not_specified(self):
        node_one = DeliveryNodeFactory()
        node_two = DeliveryNodeFactory()

        node = DeliveryNodeFactory(parents=[{'id': node_one.id, 'quantity': 8}, {'id': node_two.id, 'quantity': 10}])

        node.location = 'Changed'
        node.save()
        self.assertEqual(node.quantity_in(), 18)
        self.assertEqual(node.location, 'Changed')
Exemplo n.º 35
0
    def test_should_add_changed_node_to_sync_data(self, *_):
        node = DeliveryNodeFactory(location='Kampala')
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        list_nodes_to_update()

        node.location = 'Changed location'
        node.save()
        nodes_to_sync = list_nodes_to_update()

        self.assertIn(node, nodes_to_sync)
Exemplo n.º 36
0
    def test_should_update_delivery_node_parents(self):
        node_one = DeliveryNodeFactory()
        node = DeliveryNodeFactory(parents=[{'id': node_one.id, 'quantity': 5}])

        changes = {'parents': [{'id': node_one.id, 'quantity': 8}]}
        path = '%s%d/' % (ENDPOINT_URL, node.id)
        response = self.client.patch(path, data=json.dumps(changes), content_type='application/json')

        self.assertEqual(response.status_code, 200)
        self.assertEqual(node.quantity_in(), 8)
Exemplo n.º 37
0
    def test_should_include_order_number_in_delivery_node_fields(self):
        purchase_order = PurchaseOrderFactory(order_number=200)
        DeliveryNodeFactory(item=PurchaseOrderItemFactory(purchase_order=purchase_order))

        release_order = ReleaseOrderFactory(waybill=300)
        DeliveryNodeFactory(item=ReleaseOrderItemFactory(release_order=release_order))

        response = self.client.get(ENDPOINT_URL)
        node_order_numbers = [node['order_number'] for node in response.data]
        self.assertItemsEqual([300, 200], node_order_numbers)
Exemplo n.º 38
0
    def test_should_set_total_value_on_multiple_parent_node_when_saved(self):
        parent_one = DeliveryNodeFactory(quantity=100)
        parent_two = DeliveryNodeFactory(quantity=100)
        po_item = PurchaseOrderItemFactory(quantity=100, value=1000.0)

        node = DeliveryNodeFactory(parents=[(parent_one, 50),
                                            (parent_two, 40)],
                                   item=po_item)

        self.assertEqual(node.total_value, 900)
Exemplo n.º 39
0
    def test_should_get_a_nodes_ip_from_the_root_node_of_the_node_delivery(
            self):
        delivery = DeliveryFactory()

        root_node = DeliveryNodeFactory(distribution_plan=delivery)
        self.assertEqual(
            root_node.get_ip(), {
                'id': root_node.id,
                'consignee': root_node.consignee,
                'location': root_node.location
            })

        intermediary_node = DeliveryNodeFactory(distribution_plan=delivery,
                                                parents=[(root_node, 5)])
        self.assertEqual(
            intermediary_node.get_ip(), {
                'id': root_node.id,
                'consignee': root_node.consignee,
                'location': root_node.location
            })

        leaf_node = DeliveryNodeFactory(parents=[(intermediary_node, 3)],
                                        distribution_plan=delivery)
        self.assertEqual(
            leaf_node.get_ip(), {
                'id': root_node.id,
                'consignee': root_node.consignee,
                'location': root_node.location
            })
Exemplo n.º 40
0
    def setUp(self):
        self.po_item_one = PurchaseOrderItemFactory(value=400, quantity=200)
        self.po_item_two = PurchaseOrderItemFactory(value=600, quantity=100)

        self.delivery = DeliveryFactory()
        self.node_one = DeliveryNodeFactory(distribution_plan=self.delivery,
                                            item=self.po_item_one,
                                            quantity=50)
        DeliveryNodeFactory(distribution_plan=self.delivery,
                            item=self.po_item_two,
                            quantity=30)
Exemplo n.º 41
0
    def test_should_schedule_end_user_flow_if_node_tree_position_is_end_user(
            self):
        node = NodeFactory(tree_position=Node.END_USER)
        node.build_contact = MagicMock(return_value=self.contact)

        Runnable.objects.get = MagicMock(return_value=node)

        self.flow_scheduler.schedule_run_for(node)

        self.mocked_create_run.assert_called_with(self.contact,
                                                  self.end_user_flow, ANY, ANY)
Exemplo n.º 42
0
    def test_should_search_nodes_by_date(self):
        delivery_node = DeliveryNodeFactory(delivery_date=datetime(2014, 04, 14))
        DeliveryNodeFactory(delivery_date=datetime(2015, 04, 23))

        response = self.client.get('%s?search=%s' % (ENDPOINT_URL, '2014-04'))

        nodes = response.data
        node_ids = [node['id'] for node in nodes]

        self.assertEqual(len(nodes), 1)
        self.assertItemsEqual([delivery_node.id], node_ids)
Exemplo n.º 43
0
    def test_should_not_include_match_clauses_with_empty_id_lists(self, mock_scan):
        node = DeliveryNodeFactory(location='Kampala')
        SyncInfo.objects.create(status=SyncInfo.STATUS.SUCCESSFUL)
        list_nodes_to_update()

        node.location = 'Changed location'
        node.save()
        nodes_to_sync = list_nodes_to_update()

        self.assertFalse(mock_scan.called)
        self.assertIn(node, nodes_to_sync)
Exemplo n.º 44
0
    def test_should_build_contact_with_details_from_contacts_service(self, mock_get):
        contact_id = '54335c56b3ae9d92f038abb0'
        fake_contact_json = {'firstName': "test", 'lastName': "user1", 'phone': "+256 782 443439", '_id': contact_id}
        fake_response = FakeResponse(fake_contact_json, 200)
        node = NodeFactory(contact_person_id=contact_id)
        mock_get.return_value = fake_response

        contact = node.build_contact()

        self.assertEqual(contact, fake_contact_json)
        mock_get.assert_called_with("%s%s/" % (settings.CONTACTS_SERVICE_URL, contact_id))
Exemplo n.º 45
0
    def test_should_return_number_of_items_on_a_delivery(self):
        po = PurchaseOrderFactory(order_number=123456)
        po_item_one = PurchaseOrderItemFactory(purchase_order=po)
        po_item_two = PurchaseOrderItemFactory(purchase_order=po)
        delivery = DeliveryFactory()
        DeliveryNodeFactory(distribution_plan=delivery, item=po_item_one)

        self.assertEqual(delivery.number_of_items(), 1)

        DeliveryNodeFactory(distribution_plan=delivery, item=po_item_two)
        self.assertEqual(delivery.number_of_items(), 2)
Exemplo n.º 46
0
    def test_should_filter_nodes_by_location(self):
        kagoma_one = DeliveryNodeFactory(location='Kagoma')
        DeliveryNodeFactory(location='Kabaale')
        kagoma_two = DeliveryNodeFactory(location='Kagoma')

        response = self.client.get('%s?search=%s' % (ENDPOINT_URL, 'Kag'))

        nodes = response.data
        node_ids = [node['id'] for node in nodes]
        self.assertEqual(len(nodes), 2)
        self.assertItemsEqual([kagoma_one.id, kagoma_two.id], node_ids)
Exemplo n.º 47
0
    def test_should_create_itself_with_any_type_of_order_item(self):
        purchase_order_item = PurchaseOrderItemFactory()
        release_order_item = ReleaseOrderItemFactory()

        node_with_po_item = DeliveryNodeFactory(item=purchase_order_item)
        node_with_ro_item = DeliveryNodeFactory(item=release_order_item)

        self.assertEqual(DeliveryNode.objects.get(item=purchase_order_item),
                         node_with_po_item)
        self.assertEqual(DeliveryNode.objects.get(item=release_order_item),
                         node_with_ro_item)
Exemplo n.º 48
0
    def test_should_paginate_items_list_on_request(self):
        DeliveryNodeFactory()
        DeliveryNodeFactory()
        response = self.client.get('%s?paginate=true' % ENDPOINT_URL)

        self.assertIn('results', response.data)
        self.assertIn('count', response.data)
        self.assertIn('next', response.data)
        self.assertIn('previous', response.data)
        self.assertIn('pageSize', response.data)
        self.assertEqual(len(response.data['results']), 2)
Exemplo n.º 49
0
    def test_should_create_delivery_node_with_parents(self):
        node_one = DeliveryNodeFactory()
        node_two = DeliveryNodeFactory()
        self.node_details['parents'] = [{'id': node_one.id, 'quantity': 5}, {'id': node_two.id, 'quantity': 6}]

        response = self.client.post(ENDPOINT_URL, data=json.dumps(self.node_details), content_type='application/json')
        node = DeliveryNode.objects.get(pk=response.data['id'])

        self.assertEqual(response.status_code, 201)
        self.assertTrue(node.quantity_in(), 11)
        self.assertTrue(node_one.quantity_out(), 5)
        self.assertTrue(node_two.quantity_out(), 6)
Exemplo n.º 50
0
    def test_should_update_parent_total_value_if_root_node_when_saved(self):
        po_item = PurchaseOrderItemFactory(quantity=100, value=1000.0)
        parent = DeliveryFactory()
        DeliveryNodeFactory(quantity=80,
                            item=po_item,
                            distribution_plan=parent)
        self.assertEqual(parent.total_value, 800)

        DeliveryNodeFactory(quantity=90,
                            item=po_item,
                            distribution_plan=parent)
        self.assertEqual(parent.total_value, 1700)
Exemplo n.º 51
0
 def create_nodes(self):
     self.ip_node = DeliveryNodeFactory(quantity=100)
     self.middle_man_node = DeliveryNodeFactory(
         parents=[(self.ip_node, 100)],
         tree_position=DistributionPlanNode.MIDDLE_MAN,
         distribution_plan=self.ip_node.distribution_plan,
         item=self.item)
     self.end_user_node = DeliveryNodeFactory(
         parents=[(self.middle_man_node, 100)],
         tree_position=DistributionPlanNode.END_USER,
         distribution_plan=self.ip_node.distribution_plan,
         item=self.item)
Exemplo n.º 52
0
    def test_should_filter_based_on_to_date(self):
        DeliveryNodeFactory(distribution_plan=DeliveryFactory(track=True), delivery_date=datetime.date(2015, 10, 1),
                            tree_position=Flow.Label.IMPLEMENTING_PARTNER)
        DeliveryNodeFactory(distribution_plan=DeliveryFactory(track=True), delivery_date=datetime.date(2015, 11, 1),
                            tree_position=Flow.Label.IMPLEMENTING_PARTNER)

        endpoint_url = BACKEND_URL + 'stock-report?toDate=2015-10-15'
        response = self.client.get(endpoint_url)

        results = response.data['results']
        self.assertEqual(len(results), 1)
        self.assertEqual(results[0]['last_shipment_date'], '2015-10-01')
Exemplo n.º 53
0
    def test_should_schedule_flow_with_sender_as_parent_node_consignee_name_if_node_has_parent(self):
        sender_org_name = "Dwelling Places"
        sender_org = ConsigneeFactory(name=sender_org_name)
        parent_node = NodeFactory(consignee=sender_org)
        node = NodeFactory(consignee=sender_org, parents=[(parent_node, 10)])
        node.build_contact = MagicMock(return_value=self.contact)

        Runnable.objects.get = MagicMock(return_value=node)
        node.consignee.build_contact = MagicMock(return_value=self.contact)

        self.flow_scheduler.schedule_run_for(node)

        self.mocked_create_run.assert_called_with(self.contact, ANY, node.item.item.description, sender_org_name)
Exemplo n.º 54
0
    def test_should_ignore_quantity_on_update_if_parents_are_specified(self):
        node_one = DeliveryNodeFactory()

        node = DeliveryNodeFactory(quantity=0)

        node.parents = [{'id': node_one.id, 'quantity': 7}]
        node.quantity = 50
        node.save()
        self.assertEqual(node.quantity_in(), 7)

        node.parents = []
        node.save()
        self.assertEqual(node.quantity_in(), 0)
Exemplo n.º 55
0
    def test_should_update_balance_when_node_quantities_change(self):
        node = DeliveryNodeFactory(quantity=100, acknowledged=100)
        child = DeliveryNodeFactory(parents=[(node, 50)])

        self.assertEqual(child.balance, 50)
        self.assertEqual(DeliveryNode.objects.get(id=node.id).balance, 50)

        child_two = DeliveryNodeFactory(parents=[(node, 40)])
        self.assertEqual(child_two.balance, 40)
        self.assertEqual(DeliveryNode.objects.get(id=node.id).balance, 10)

        child_two.delete()
        self.assertEqual(DeliveryNode.objects.get(id=node.id).balance, 50)
Exemplo n.º 56
0
    def test_should_schedule_flow_with_sender_as_parent_node_consignee_name_if_node_has_parent(self):
        sender_org_name = "Dwelling Places"
        sender_org = ConsigneeFactory(name=sender_org_name)
        parent_node = NodeFactory(consignee=sender_org)
        node = NodeFactory(consignee=sender_org, parents=[(parent_node, 10)])
        node.build_contact = MagicMock(return_value=self.contact)

        Runnable.objects.get = MagicMock(return_value=node)
        node.consignee.build_contact = MagicMock(return_value=self.contact)

        schedule_run_for(node)

        mock_start_delivery_run.assert_called_with(contact_person=self.contact, flow=ANY, sender=sender_org_name,
                                                   item_description=node.item.item.description)
Exemplo n.º 57
0
    def test_update_should_override_parents_when_parents_list_is_passed(self):
        node_one = DeliveryNodeFactory()
        node_two = DeliveryNodeFactory()

        node = DeliveryNodeFactory(parents=[{'id': node_one.id, 'quantity': 8}, {'id': node_two.id, 'quantity': 10}])
        self.assertEqual(node.quantity_in(), 18)

        node.parents = [{'id': node_one.id, 'quantity': 7}]
        node.save()
        self.assertEqual(node.quantity_in(), 7)

        node.parents = []
        node.save()
        self.assertEqual(node.quantity_in(), 0)
Exemplo n.º 58
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)