def test_should_fetch_name_from_contacts_and_adds_alert_attribute(self, requests_mocker):
        answer_values = [
            {"category": {"base": "No"}, "label": Question.LABEL.deliveryReceived},
            {"category": {"base": "Yes"}, "label": Question.LABEL.isDeliveryInGoodOrder},
        ]
        purchase_order = PurchaseOrderFactory(order_number=5678)
        purchase_order_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
        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",
        }

        delivery = DeliveryFactory(consignee=consignee, contact_person_id=contact_person_id)
        DeliveryNodeFactory(item=purchase_order_item, distribution_plan=delivery)

        requests_mocker.get("%s%s/" % (settings.CONTACTS_SERVICE_URL, contact_person_id), json=contact)

        response_alert_handler = ResponseAlertHandler(runnable=delivery, answer_values=answer_values)
        response_alert_handler.process()

        alert = Alert.objects.get(consignee_name="Liverpool FC", order_number=5678)
        self.assertEqual(alert.contact_name, "chris george")
    def test_should_not_create_alert_when_non_delivery_question_are_answered_no(self):
        answer_values = [
            {"category": {"base": "No"}, "label": "This is not a delivery question"},
            {"category": {"base": "Yes"}, "label": Question.LABEL.isDeliveryInGoodOrder},
        ]
        delivery = DeliveryFactory()

        response_alert_handler = ResponseAlertHandler(runnable=delivery, answer_values=answer_values)
        response_alert_handler.process()

        self.assertEqual(Alert.objects.count(), 0)
    def test_should_not_create_alert_when_no_issues_with_delivery(self):
        answer_values = [
            {"category": {"base": "Yes"}, "label": Question.LABEL.deliveryReceived},
            {"category": {"base": "Yes"}, "label": Question.LABEL.isDeliveryInGoodOrder},
        ]
        delivery = DeliveryFactory()

        response_alert_handler = ResponseAlertHandler(runnable=delivery, answer_values=answer_values)
        response_alert_handler.process()

        self.assertEqual(Alert.objects.count(), 0)
Exemplo n.º 4
0
    def test_should_not_create_alert_when_non_delivery_question_are_answered_no(self):
        answer_values = [
            {"category": {"base": "No"}, "label": "This is not a delivery question"},
            {"category": {"base": "Yes"}, "label": Question.LABEL.isDeliveryInGoodOrder}
        ]
        delivery = DeliveryFactory()

        response_alert_handler = ResponseAlertHandler(runnable=delivery, answer_values=answer_values)
        response_alert_handler.process()

        self.assertEqual(Alert.objects.count(), 0)
Exemplo n.º 5
0
    def test_should_not_create_alert_when_no_issues_with_delivery(self):
        answer_values = [
            {"category": {"base": "Yes"}, "label": Question.LABEL.deliveryReceived},
            {"category": {"base": "Yes"}, "label": Question.LABEL.isDeliveryInGoodOrder}
        ]
        delivery = DeliveryFactory()

        response_alert_handler = ResponseAlertHandler(runnable=delivery, answer_values=answer_values)
        response_alert_handler.process()

        self.assertEqual(Alert.objects.count(), 0)
    def test_should_create_alert_when_item_is_not_received(self, requests_mocker):
        answer_values = [{"category": {"base": "No"}, "label": Question.LABEL.itemReceived}]
        purchase_order = PurchaseOrderFactory(order_number=5679)
        purchase_order_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
        consignee = ConsigneeFactory(name="Liverpool FC")
        delivery = DeliveryFactory(consignee=consignee)
        DeliveryNodeFactory(item=purchase_order_item, distribution_plan=delivery)

        requests_mocker.get("%s%s/" % (settings.CONTACTS_SERVICE_URL, delivery.contact_person_id), json={})

        response_alert_handler = ResponseAlertHandler(runnable=delivery, answer_values=answer_values)
        response_alert_handler.process()

        alert = Alert.objects.get(consignee_name="Liverpool FC", order_number=5679)
        self.assertEqual(alert.issue, Alert.ISSUE_TYPES.not_received)
Exemplo n.º 7
0
    def test_should_fetch_name_from_contacts_and_adds_alert_attribute(self):
        answer_values = [
            {"category": {"base": "No"}, "label": Question.LABEL.deliveryReceived},
            {"category": {"base": "Yes"}, "label": Question.LABEL.isDeliveryInGoodOrder}
        ]
        purchase_order = PurchaseOrderFactory(order_number=5678)
        purchase_order_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
        consignee = ConsigneeFactory(name="Liverpool FC - Unique")

        contact_person_id = 'some_id'
        contact = {u'_id': contact_person_id,
                   u'firstName': u'chris',
                   u'lastName': u'george',
                   u'phone': u'+256781111111'}

        delivery = DeliveryFactory(consignee=consignee, contact_person_id=contact_person_id)
        DeliveryNodeFactory(item=purchase_order_item, distribution_plan=delivery)

        response = MagicMock(json=MagicMock(return_value=contact), status_code=200)
        requests.get = MagicMock(return_value=response)

        ResponseAlertHandler(runnable=delivery, answer_values=answer_values).process()

        alert = Alert.objects.get(consignee_name="Liverpool FC - Unique", order_number=5678)
        self.assertEqual(alert.contact['contact_name'], "chris george")
Exemplo n.º 8
0
    def test_should_create_alert_when_item_is_not_received(self, requests_mocker):
        answer_values = [
            {"category": {"base": "No"}, "label": Question.LABEL.itemReceived}
        ]
        purchase_order = PurchaseOrderFactory(order_number=5679)
        purchase_order_item = PurchaseOrderItemFactory(purchase_order=purchase_order)
        consignee = ConsigneeFactory(name="Liverpool FC")
        delivery = DeliveryFactory(consignee=consignee)
        DeliveryNodeFactory(item=purchase_order_item, distribution_plan=delivery)

        requests_mocker.get("%s%s/" % (settings.CONTACTS_SERVICE_URL, delivery.contact_person_id), json={})

        response_alert_handler = ResponseAlertHandler(runnable=delivery, answer_values=answer_values)
        response_alert_handler.process()

        alert = Alert.objects.get(consignee_name="Liverpool FC", order_number=5679)
        self.assertEqual(alert.issue, Alert.ISSUE_TYPES.not_received)
Exemplo n.º 9
0
def _create_alert(runnable, params):
    handler = ResponseAlertHandler(runnable, params)
    handler.process()
Exemplo n.º 10
0
def _raise_alert(params, runnable):
    answer_values = ast.literal_eval(params['values'])
    handler = ResponseAlertHandler(runnable, answer_values)
    handler.process()
Exemplo n.º 11
0
Arquivo: hook.py Projeto: yaroing/eums
def _raise_alert(params, runnable):
    answer_values = ast.literal_eval(params['values'])
    handler = ResponseAlertHandler(runnable, answer_values)
    handler.process()
Exemplo n.º 12
0
def _create_alert(runnable, params):
    handler = ResponseAlertHandler(runnable, params)
    handler.process()