Esempio n. 1
0
    def test_should_provide_quantity_delivered_for_node_alert(self):
        node = DeliveryNodeFactory(quantity=20)
        alert = AlertFactory(runnable=node)
        delivery_alert = AlertFactory(runnable=DeliveryFactory())

        self.assertEqual(alert.quantity_delivered(), 20)
        self.assertEqual(delivery_alert.quantity_delivered(), None)
Esempio n. 2
0
    def test_admin_should_view_alert(self):
        AlertFactory()
        AlertFactory()
        AlertFactory()

        response = self.client.get(ENDPOINT_URL)

        self.assertEqual(response.status_code, HTTP_200_OK)
Esempio n. 3
0
    def test_should_show_alerts_count(self):
        AlertFactory(is_resolved=False)
        AlertFactory(is_resolved=True)

        response = self.client.get(ENDPOINT_URL + "count/")

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['total'], 2)
        self.assertEqual(response.data['unresolved'], 1)
Esempio n. 4
0
    def test_should_return_multiple_alerts_when_multiple_exist(self):
        AlertFactory()
        AlertFactory()
        AlertFactory()

        response = self.client.get('%s?type=delivery' % ENDPOINT_URL)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 3)
Esempio n. 5
0
 def test_should_paginate_alert_list_on_request(self):
     AlertFactory()
     AlertFactory()
     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)
Esempio n. 6
0
    def test_consignee_should_not_view_alert(self):
        AlertFactory()
        AlertFactory()
        AlertFactory()

        self.logout()
        self.log_consignee_in(ConsigneeFactory())

        response = self.client.get(ENDPOINT_URL)

        self.assertEqual(response.status_code, HTTP_403_FORBIDDEN)
Esempio n. 7
0
    def test_should_provide_location_for_runnable(self):
        node_location = "Kampala"
        node = DeliveryNodeFactory(location=node_location)

        delivery_location = "Wakiso"
        delivery = DeliveryNodeFactory(location=("%s" % delivery_location))

        alert = AlertFactory(runnable=node)
        delivery_alert = AlertFactory(runnable=delivery)

        self.assertEqual(alert.location(), node_location)
        self.assertEqual(delivery_alert.location(), delivery_location)
Esempio n. 8
0
    def test_should_provide_delivery_date_for_runnable(self):
        node_date = datetime.strptime('24052010', "%d%m%Y").date()
        node = DeliveryNodeFactory(delivery_date=node_date)

        delivery_date = datetime.strptime('24052011', "%d%m%Y").date()
        delivery = DeliveryNodeFactory(location=delivery_date)

        alert = AlertFactory(runnable=node)
        delivery_alert = AlertFactory(runnable=delivery)

        self.assertEqual(alert.date_shipped(), node_date)
        self.assertEqual(delivery_alert.location(), delivery_date)
Esempio n. 9
0
    def setUp(self):
        Alert.objects.all().delete()

        self.item_alert_1 = AlertFactory(order_number=81020737,
                                         runnable=DeliveryNodeFactory())
        self.item_alert_2 = AlertFactory(order_number=81035556,
                                         runnable=DeliveryNodeFactory())
        self.delivery_alert = AlertFactory(order_number=81025778,
                                           runnable=DeliveryFactory())
        self.distribution_alert = AlertFactory(
            order_number=81034568,
            runnable=DeliveryFactory(),
            issue=Alert.ISSUE_TYPES.distribution_expired)
Esempio n. 10
0
    def test_should_provide_total_value_of_the_runnable(self):
        po_item_one = PurchaseOrderItemFactory(value=400, quantity=200)
        po_item_two = PurchaseOrderItemFactory(value=600, quantity=100)

        delivery = DeliveryFactory()
        node = DeliveryNodeFactory(distribution_plan=delivery, item=po_item_one, quantity=50)
        DeliveryNodeFactory(distribution_plan=delivery, item=po_item_two, quantity=30)

        node_alert = AlertFactory(runnable=node)
        delivery_alert = AlertFactory(runnable=delivery)

        self.assertEqual(node_alert.total_value(), 100)
        self.assertEqual(delivery_alert.total_value(), 280)
Esempio n. 11
0
 def test_should_filter_alerts_by_runnable_type_when_delivery(self):
     delivery_alert = AlertFactory(runnable=DeliveryFactory())
     delivery_alert_ids, delivery_alerts = self.__respond_by_alert_type(
         'delivery')
     self.assertEqual(Alert.objects.count(), 1)
     self.assertEqual(len(delivery_alerts), 1)
     self.assertIn(delivery_alert.id, delivery_alert_ids)
Esempio n. 12
0
    def test_should_not_update_alert_when_id_does_not_exist(self):
        alert = AlertFactory()

        response = self.client.patch('%s%s/' % (ENDPOINT_URL, alert.id),
                                     data={'alert_remarks': 'some remarks'})
        updated_alert = Alert.objects.get(pk=alert.id)

        self.assertEqual(response.status_code, 400)
        self.assertEqual(updated_alert.remarks, None)
        self.assertEqual(updated_alert.is_resolved, False)
Esempio n. 13
0
    def log_and_assert_change_alert_permission(self, log_func, status_code):
        log_func()

        alert = AlertFactory()
        response = self.client.patch('%s%s/' % (ENDPOINT_URL, alert.id),
                                     data={
                                         'remarks': 'hello world',
                                         'is_resolved': True
                                     })

        self.assertEqual(response.status_code, status_code)
Esempio n. 14
0
    def test_admin_should_update_alert(self):
        PermissionsTestCase.setUpClass()
        alert = AlertFactory()

        response = self.client.patch('%s%s/' % (ENDPOINT_URL, alert.id),
                                     data={
                                         'remarks': 'hello world',
                                         'is_resolved': True
                                     })

        self.assertEqual(response.status_code, HTTP_200_OK)
Esempio n. 15
0
    def test_should_provide_quantity_delivered_for_node_alert(self):
        node = DeliveryNodeFactory(quantity=20)
        alert = AlertFactory(runnable=node)
        delivery_alert = AlertFactory(runnable=DeliveryFactory())

        self.assertEqual(alert.quantity_delivered(), 20)
        self.assertEqual(delivery_alert.quantity_delivered(), None)
Esempio n. 16
0
    def test_should_update_alert(self):
        alert = AlertFactory()

        response = self.client.patch('%s%s/' % (ENDPOINT_URL, alert.id),
                                     data={
                                         'remarks': 'some remarks',
                                         'is_resolved': True
                                     })
        updated_alert = Alert.objects.get(pk=alert.id)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(updated_alert.remarks, 'some remarks')
        self.assertEqual(updated_alert.is_resolved, True)
Esempio n. 17
0
 def setUp(self):
     self.item_alert = AlertFactory(order_number=81020737,
                                    item_description='Microsoft windows 7 Proefessional OLP NL F',
                                    issue=Alert.ISSUE_TYPES.not_received,
                                    is_resolved=False,
                                    remarks='Operating system',
                                    consignee_name='WAKISO DHO',
                                    runnable=DeliveryNodeFactory())
     self.delivery_alert = AlertFactory(order_number=81025778,
                                        item_description='Safety box f.used syrgs/ndls 5lt/BOX-25 B',
                                        issue=Alert.ISSUE_TYPES.damaged,
                                        is_resolved=False,
                                        remarks='Goods',
                                        consignee_name='MUBENDE DHO',
                                        runnable=DeliveryFactory())
     self.distribution_alert = AlertFactory(order_number=81034568,
                                            item_description='IEHK2006,kit,suppl.1-drugs',
                                            issue=Alert.ISSUE_TYPES.distribution_expired,
                                            is_resolved=False,
                                            remarks='Medicine',
                                            consignee_name='NAPAK DHO',
                                            runnable=DeliveryFactory())
Esempio n. 18
0
    def test_unicef_viewer_should_not_update_alert(self):
        PermissionsTestCase.setUpClass()
        AlertFactory()

        self.logout()
        self.log_unicef_viewer_in()

        response = self.client.patch('%s%s/' % (ENDPOINT_URL, 'someId'),
                                     data={
                                         'id': 'someId',
                                         'remarks': 'hello world'
                                     })

        self.assertEqual(response.status_code, HTTP_403_FORBIDDEN)
Esempio n. 19
0
    def test_should_provide_delivery_date_for_runnable(self):
        node_date = datetime.strptime('24052010', "%d%m%Y").date()
        node = DeliveryNodeFactory(delivery_date=node_date)

        delivery_date = datetime.strptime('24052011', "%d%m%Y").date()
        delivery = DeliveryNodeFactory(location=delivery_date)

        alert = AlertFactory(runnable=node)
        delivery_alert = AlertFactory(runnable=delivery)

        self.assertEqual(alert.date_shipped(), node_date)
        self.assertEqual(delivery_alert.location(), delivery_date)
Esempio n. 20
0
    def test_should_provide_location_for_runnable(self):
        node_location = "Kampala"
        node = DeliveryNodeFactory(location=node_location)

        delivery_location = "Wakiso"
        delivery = DeliveryNodeFactory(location=("%s" % delivery_location))

        alert = AlertFactory(runnable=node)
        delivery_alert = AlertFactory(runnable=delivery)

        self.assertEqual(alert.location(), node_location)
        self.assertEqual(delivery_alert.location(), delivery_location)
Esempio n. 21
0
    def test_should_return_information_on_an_alert(self):
        contact_id = '54335c56b3ae9d92f038abb0'
        runnable = DeliveryFactory(contact_person_id=contact_id)
        AlertFactory(order_type=ReleaseOrderItem.WAYBILL,
                     order_number=123456,
                     issue=Alert.ISSUE_TYPES.not_received,
                     is_resolved=False,
                     remarks='some remarks',
                     consignee_name='wakiso',
                     item_description="some description",
                     runnable=runnable)

        fake_contact = {
            'firstName': "test",
            'lastName': "user1",
            'phone': "+256 782 443439",
            '_id': contact_id
        }
        response = MagicMock(json=MagicMock(return_value=fake_contact),
                             status_code=200)
        requests.get = MagicMock(return_value=response)

        response = self.client.get('%s?type=delivery' % ENDPOINT_URL)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        first_alert = response.data[0]
        self.assertIsNotNone(first_alert['id'])
        self.assertEqual(first_alert['order_type'], ReleaseOrderItem.WAYBILL)
        self.assertEqual(first_alert['order_number'], 123456)
        self.assertEqual(first_alert['issue'], Alert.ISSUE_TYPES.not_received)
        self.assertEqual(first_alert['is_resolved'], False)
        self.assertEqual(first_alert['remarks'], 'some remarks')
        self.assertEqual(first_alert['consignee_name'], 'wakiso')
        self.assertEqual(first_alert['item_description'], 'some description')
        self.assertEqual(first_alert['issue_display_name'],
                         Alert.ISSUE_TYPES[Alert.ISSUE_TYPES.not_received])
        self.assertEqual(first_alert['contact'], {
            'contact_name': 'test user1',
            'contact_phone': '+256 782 443439'
        })
Esempio n. 22
0
    def test_should_provide_total_value_of_the_runnable(self):
        po_item_one = PurchaseOrderItemFactory(value=400, quantity=200)
        po_item_two = PurchaseOrderItemFactory(value=600, quantity=100)

        delivery = DeliveryFactory()
        node = DeliveryNodeFactory(distribution_plan=delivery,
                                   item=po_item_one,
                                   quantity=50)
        DeliveryNodeFactory(distribution_plan=delivery,
                            item=po_item_two,
                            quantity=30)

        node_alert = AlertFactory(runnable=node)
        delivery_alert = AlertFactory(runnable=delivery)

        self.assertEqual(node_alert.total_value(), 100)
        self.assertEqual(delivery_alert.total_value(), 280)
Esempio n. 23
0
    def test_should_filter_alerts_by_runnable_type_when_distribution(self):
        delivery = DeliveryFactory(time_limitation_on_distribution=3)
        question_received_date = TextQuestionFactory(
            label=Question.LABEL.dateOfReceipt, flow=self.flow_ip)
        run = RunFactory(runnable=delivery)
        DeliveryNodeFactory(distribution_plan=delivery,
                            tree_position=Flow.Label.IMPLEMENTING_PARTNER)
        received_date = '2015-11-20T16:00:00'
        TextAnswerFactory(run=run,
                          question=question_received_date,
                          value=received_date)

        distribution_alert = AlertFactory(
            runnable=delivery, issue=Alert.ISSUE_TYPES.distribution_expired)
        distribution_alert_ids, distribution_alerts = self.__respond_by_alert_type(
            'distribution')

        self.assertEqual(Alert.objects.count(), 1)
        self.assertTrue(distribution_alerts[0]['date_received'])
        self.assertEqual(distribution_alerts[0]['date_received'],
                         received_date)
        self.assertEqual(len(distribution_alerts), 1)
        self.assertIn(distribution_alert.id, distribution_alert_ids)
Esempio n. 24
0
 def test_should_provide_display_name_for_issue_type_of_not_received(self):
     alert = AlertFactory(issue=Alert.ISSUE_TYPES.not_received)
     self.assertEqual(alert.issue_display_name(),
                      Alert.ISSUE_TYPES[alert.issue])
Esempio n. 25
0
 def test_should_provide_display_name_for_issue_type_of_not_received(self):
     alert = AlertFactory(issue=Alert.ISSUE_TYPES.not_received)
     self.assertEqual(alert.issue_display_name(), Alert.ISSUE_TYPES[alert.issue])
Esempio n. 26
0
 def test_should_provide_display_name_for_issue_type_of_bad_condition(self):
     alert = AlertFactory(issue=Alert.ISSUE_TYPES.bad_condition)
     self.assertEqual(alert.issue_display_name(), Alert.ISSUE_TYPES[alert.issue])
Esempio n. 27
0
 def test_is_distribution_expired_alert_not_raised_should_return_false(
         self):
     alert = AlertFactory(issue=Alert.ISSUE_TYPES.distribution_expired)
     self.assertFalse(
         self.flow_scheduler.is_distribution_expired_alert_not_raised(
             alert.runnable))
Esempio n. 28
0
 def test_should_filter_alerts_by_runnable_type_when_item(self):
     item_alert = AlertFactory(runnable=DeliveryNodeFactory())
     item_alert_ids, item_alerts = self.__respond_by_alert_type('item')
     self.assertEqual(Alert.objects.count(), 1)
     self.assertEqual(len(item_alerts), 1)
     self.assertIn(item_alert.id, item_alert_ids)
Esempio n. 29
0
 def test_should_provide_display_name_for_issue_type_of_bad_condition(self):
     alert = AlertFactory(issue=Alert.ISSUE_TYPES.bad_condition)
     self.assertEqual(alert.issue_display_name(),
                      Alert.ISSUE_TYPES[alert.issue])
Esempio n. 30
0
# alerts
from eums.client.test.functional.fixtures.mapdata_deliveries import delivery_46, delivery_45
from eums.models import Alert, PurchaseOrderItem
from eums.test.factories.alert_factory import AlertFactory

AlertFactory(order_type=PurchaseOrderItem.PURCHASE_ORDER,
             order_number=12345,
             runnable=delivery_46)
AlertFactory(order_type=PurchaseOrderItem.PURCHASE_ORDER,
             order_number=654321,
             runnable=delivery_45,
             issue=Alert.ISSUE_TYPES.bad_condition,
             is_resolved=True)