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)
def test_admin_should_view_alert(self): AlertFactory() AlertFactory() AlertFactory() response = self.client.get(ENDPOINT_URL) self.assertEqual(response.status_code, HTTP_200_OK)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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())
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)
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' })
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)
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])
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])
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))
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)
# 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)