def test_all_products_stocked(self): """No notification if all products are stocked.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_all_products_stocked(self): """No notification if all products are stocked.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_incomplete_with_filter(self): """ User with product type filter will get notification all products of that type are missing reports. """ self.user.get_domain_membership( self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() self.product.program_id = self.program.get_id self.product.save() create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow() - timedelta(days=365)) other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list( OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_reminders(self): products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(len(products_reported), 0) self.assertEqual(len(products_not_reported), 0) assign_products_to_location(self.facility, [self.commodity]) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(len(products_reported), 0) sql_commodity = SQLProduct.objects.get(product_id=self.commodity.get_id) self.assertEqual(products_not_reported[0], sql_commodity) sql_commodity2 = SQLProduct.objects.get(product_id=self.commodity2.get_id) create_stock_report(self.facility, {'ab': 10}) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(products_reported[0], sql_commodity) self.assertEqual(len(products_not_reported), 0) assign_products_to_location(self.facility, [self.commodity, self.commodity2]) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(products_reported[0], sql_commodity) self.assertEqual(products_not_reported[0], sql_commodity2) create_stock_report(self.facility, {'cd': 10}) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertTrue(sql_commodity in products_reported) self.assertTrue(sql_commodity2 in products_reported) self.assertEqual(len(products_not_reported), 0)
def test_reminders(self): products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(len(products_reported), 0) self.assertEqual(len(products_not_reported), 0) assign_products_to_location(self.facility, [self.commodity]) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(len(products_reported), 0) sql_commodity = SQLProduct.objects.get(product_id=self.commodity.get_id) self.assertEqual(products_not_reported[0], sql_commodity) sql_commodity2 = SQLProduct.objects.get(product_id=self.commodity2.get_id) create_stock_report(self.facility, {'ab': 10}) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(products_reported[0], sql_commodity) self.assertEqual(len(products_not_reported), 0) assign_products_to_location(self.facility, [self.commodity, self.commodity2]) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertEqual(products_reported[0], sql_commodity) self.assertEqual(products_not_reported[0], sql_commodity2) create_stock_report(self.facility, {'cd': 10}) products_reported, products_not_reported = report_status(self.facility.sql_location, days_until_late=1) self.assertTrue(sql_commodity in products_reported) self.assertTrue(sql_commodity2 in products_reported) self.assertEqual(len(products_not_reported), 0)
def test_simple_stockout(self): """Single product, single report with 0 quantity.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_simple_stockout(self): """Single product, single report with 0 quantity.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_partial_duration_stockout(self): """Some reports indicate a stockout but did not last the entire period. No notification.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp': 1}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_partial_duration_stockout(self): """Some reports indicate a stockout but did not last the entire period. No notification.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp': 1}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_product_type_filter(self): """User can recieve notifications for only certain product type.""" bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=self.program.get_id ) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1)
def test_product_type_filter(self): """User can recieve notifications for only certain product type.""" bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=self.program.get_id ) create_stock_report(self.facility, {'tp': 0}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1)
def test_urgent_non_reporting_alert(self): urgent_non_reporting = UrgentNonReporting(TEST_DOMAIN) urgent_non_reporting.send() self.assertEqual(SMS.objects.count(), 1) self.assertEqual(SMS.objects.all().first().text, URGENT_NON_REPORTING % self.district.name) create_stock_report(self.loc1, {'tp2': 0}) create_stock_report(self.loc2, {'tp2': 0}) now = datetime.utcnow() self.assertEqual(SMS.objects.filter(date__gte=now).count(), 0)
def test_urgent_non_reporting_alert(self): urgent_non_reporting = UrgentNonReporting(TEST_DOMAIN) urgent_non_reporting.send() self.assertEqual(SMS.objects.count(), 1) self.assertEqual(SMS.objects.all().first().text, URGENT_NON_REPORTING % self.district.name) create_stock_report(self.loc1, {'tp2': 0}) create_stock_report(self.loc2, {'tp2': 0}) now = datetime.utcnow() self.assertEqual(SMS.objects.filter(date__gte=now).count(), 0)
def test_majority_facility_not_report(self): """Send a notification because > 50% of the facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_majority_facility_not_report(self): """Send a notification because > 50% of the facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_minority_facility_stockout(self): """No notification because < 50% of the facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.other_facility, {'tp': 10}) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_minority_facility_stockout(self): """No notification because < 50% of the facilities don't send report.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.other_facility, {'tp': 10}) create_stock_report(self.last_facility, {'tp': 10}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_incomplete_report2(self): create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow()) self.product.program_id = self.program2.get_id self.product.save() other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_incomplete_report2(self): create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow()) self.product.program_id = self.program2.get_id self.product.save() other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_partial_stock_coverage(self): """ Handle the case when not all facilities are expected to have stocked a given product. i.e. if only one facility is expected to have a certain product and it is stocked out then that is an urgent stockout. """ assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_partial_product_stockout(self): """Multiple products but only one is stocked out. Should be reported.""" other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp2': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_partial_stock_coverage(self): """ Handle the case when not all facilities are expected to have stocked a given product. i.e. if only one facility is expected to have a certain product and it is stocked out then that is an urgent stockout. """ assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_multiple_users(self): """Each user will get their own notification.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={} ) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id})
def test_partial_product_stockout(self): """Multiple products but only one is stocked out. Should be reported.""" other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.facility, {'tp2': 10}) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_multiple_users(self): """Each user will get their own notification.""" assign_products_to_location(self.facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={} ) generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id})
def test_ongoing_stockouts(self): OnGoingStockouts(TEST_DOMAIN).send() self.assertEqual(SMS.objects.count(), 0) create_stock_report(self.loc1, {'tp': 0}) now = datetime.utcnow() OnGoingStockouts(TEST_DOMAIN).send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 1) self.assertEqual(smses[0].text, ONGOING_STOCKOUT_AT_SDP % 'Test Facility') create_stock_report(self.loc2, {'tp': 0}) now = datetime.utcnow() OnGoingStockouts(TEST_DOMAIN).send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 1) self.assertEqual(smses[0].text, ONGOING_STOCKOUT_AT_SDP % 'Test Facility, Test Facility 2') create_stock_report(self.loc1, {'tp': 10}) create_stock_report(self.loc2, {'tp': 10}) now = datetime.utcnow() OnGoingStockouts(TEST_DOMAIN).send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 0)
def test_ongoing_stockouts_rms(self): OnGoingStockoutsRMS(TEST_DOMAIN).send() self.assertEqual(SMS.objects.count(), 0) create_stock_report(self.rms, {'tp': 0}) create_stock_report(self.rms2, {'tp': 0}) now = datetime.utcnow() OnGoingStockoutsRMS(TEST_DOMAIN).send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 2) self.assertEqual(smses[0].text, ONGOING_STOCKOUT_AT_RMS % 'Test Medical Store, Test Medical Store 2') create_stock_report(self.rms2, {'tp': 15}) now = datetime.utcnow() OnGoingStockoutsRMS(TEST_DOMAIN).send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 2) self.assertEqual(smses[0].text, ONGOING_STOCKOUT_AT_RMS % 'Test Medical Store') create_stock_report(self.rms, {'tp': 15}) now = datetime.utcnow() OnGoingStockoutsRMS(TEST_DOMAIN).send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 0)
def test_ongoing_stockouts(self): on_going_stockout() self.assertEqual(SMS.objects.count(), 0) now = datetime.utcnow() create_stock_report(self.loc1, {'tp': 0}) on_going_stockout() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 1) self.assertEqual(smses[0].text, ONGOING_STOCKOUT_AT_SDP % 'Test Facility') on_going_stockout() # Shouldn't be send again self.assertEqual(SMS.objects.filter(date__gte=now).count(), 1)
def test_ongoing_stockouts(self): on_going_stockout() self.assertEqual(SMS.objects.count(), 0) now = datetime.utcnow() create_stock_report(self.loc1, {'tp': 0}) on_going_stockout() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 1) self.assertEqual(smses[0].text, ONGOING_STOCKOUT_AT_SDP % 'Test Facility') on_going_stockout() # Shouldn't be send again self.assertEqual(SMS.objects.filter(date__gte=now).count(), 1)
def test_ongoing_stockouts_rms(self): on_going_stockout() self.assertEqual(SMS.objects.count(), 0) create_stock_report(self.rms, {'tp': 0}) create_stock_report(self.rms2, {'tp': 0}) now = datetime.utcnow() on_going_stockout() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 2) self.assertEqual(smses[0].text, ONGOING_STOCKOUT_AT_RMS % 'Test Medical Store, Test Medical Store 2') on_going_stockout() # Shouldn't be send again self.assertEqual(SMS.objects.filter(date__gte=now).count(), 2)
def test_ongoing_stockouts_rms(self): on_going_stockout() self.assertEqual(SMS.objects.count(), 0) create_stock_report(self.rms, {'tp': 0}) create_stock_report(self.rms2, {'tp': 0}) now = datetime.utcnow() on_going_stockout() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 2) self.assertEqual(smses[0].text, ONGOING_STOCKOUT_AT_RMS % 'Test Medical Store, Test Medical Store 2') on_going_stockout() # Shouldn't be send again self.assertEqual(SMS.objects.filter(date__gte=now).count(), 2)
def test_product_type_filter(self): """ Notifications will not be sent if the stockout is a product type does not interest the user. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() program = Program(domain=self.TEST_DOMAIN, name='Test Program 2') program.save() bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=program.get_id ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_product_type_filter(self): """ Notifications will not be sent if the stockout is a product type does not interest the user. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() program = Program(domain=self.TEST_DOMAIN, name='Test Program 2') program.save() bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={}, program_id=program.get_id ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_incomplete_with_filter(self): """ User with product type filter will get notification all products of that type are missing reports. """ self.user.get_domain_membership(self.TEST_DOMAIN).program_id = self.program.get_id self.user.save() self.product.program_id = self.program.get_id self.product.save() create_stock_report(self.facility, {'tp': 100}, date=datetime.utcnow() - timedelta(days=365)) other_product = Product( domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each', program_id=self.program.get_id ) other_product.save() assign_products_to_location(self.facility, [self.product, other_product]) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_ongoing_non_reporting(self): OnGoingNonReporting(TEST_DOMAIN).send() self.assertEqual(SMS.objects.count(), 1) smses = SMS.objects.all() self.assertEqual(smses[0].text, ONGOING_NON_REPORTING % 'Test Facility, Test Facility 2') create_stock_report(self.loc1, {'tp': 1}) now = datetime.utcnow() OnGoingNonReporting(TEST_DOMAIN).send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 1) self.assertEqual(smses[0].text, ONGOING_NON_REPORTING % 'Test Facility 2') create_stock_report(self.loc2, {'tp2': 1}) now = datetime.utcnow() OnGoingNonReporting(TEST_DOMAIN).send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 0)
def test_all_facility_stockout(self): """Send a notification because all facilities are stocked out of a product.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_all_facility_stockout(self): """Send a notification because all facilities are stocked out of a product.""" assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 1) self.assertEqual(generated[0].user.get_id, self.user.get_id)
def test_country_user(self): """Country as well as region users should get notifications.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.country, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id})
def test_country_user(self): """Country as well as region users should get notifications.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.country, password='******', email='*****@*****.**', user_data={} ) assign_products_to_location(self.facility, [self.product]) assign_products_to_location(self.other_facility, [self.product]) assign_products_to_location(self.last_facility, [self.product]) create_stock_report(self.facility, {'tp': 0}) create_stock_report(self.other_facility, {'tp': 0}) create_stock_report(self.last_facility, {'tp': 0}) generated = list(UrgentStockoutAlert(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual({generated[0].user.get_id, generated[1].user.get_id}, {self.user.get_id, other_user.get_id})
def test_all_facilities_reported(self): """No notifications generated if all have reported.""" create_stock_report(self.facility, {'tp': 5}) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)
def test_urgent_stockout_alert(self): urgent_stockout_alert = UrgentStockoutAlert(TEST_DOMAIN) urgent_stockout_alert.send() self.assertEqual(SMS.objects.count(), 0) create_stock_report(self.loc1, {'tp2': 0}) create_stock_report(self.loc2, {'tp2': 0}) create_stock_report(self.loc3, {'tp2': 0}) urgent_stockout_alert.send() self.assertEqual(SMS.objects.count(), 1) self.assertEqual(SMS.objects.all().first().text, URGENT_STOCKOUT % { 'location': self.district.name, 'products': "Test Product2", }) create_stock_report(self.loc1, {'tp': 0}) create_stock_report(self.loc2, {'tp': 0}) create_stock_report(self.loc3, {'tp': 0}) now = datetime.utcnow() urgent_stockout_alert.send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 1) self.assertEqual(smses.first().text, URGENT_STOCKOUT % { 'location': self.district.name, 'products': "Test Product, Test Product2", })
def test_get_products_function(self): urgent_stockout_alert = UrgentStockoutAlert(TEST_DOMAIN) self.assertEqual(len(urgent_stockout_alert.get_sql_products_list(self.district.sql_location)), 0) create_stock_report(self.loc1, {'tp': 0}) self.assertEqual(len(urgent_stockout_alert.get_sql_products_list(self.district.sql_location)), 0) create_stock_report(self.loc2, {'tp': 0}) self.assertEqual(len(urgent_stockout_alert.get_sql_products_list(self.district.sql_location)), 0) create_stock_report(self.loc3, {'tp': 0}) self.assertEqual(len(urgent_stockout_alert.get_sql_products_list(self.district.sql_location)), 1) create_stock_report(self.loc1, {'tp2': 0}) create_stock_report(self.loc2, {'tp2': 0}) create_stock_report(self.loc3, {'tp2': 0}) self.assertEqual(len(urgent_stockout_alert.get_sql_products_list(self.district.sql_location)), 2)
def test_get_products_function(self): urgent_stockout_alert = UrgentStockoutAlert(TEST_DOMAIN) self.assertEqual( len( urgent_stockout_alert.get_sql_products_list( self.district.sql_location)), 0) create_stock_report(self.loc1, {'tp': 0}) self.assertEqual( len( urgent_stockout_alert.get_sql_products_list( self.district.sql_location)), 0) create_stock_report(self.loc2, {'tp': 0}) self.assertEqual( len( urgent_stockout_alert.get_sql_products_list( self.district.sql_location)), 0) create_stock_report(self.loc3, {'tp': 0}) self.assertEqual( len( urgent_stockout_alert.get_sql_products_list( self.district.sql_location)), 1) create_stock_report(self.loc1, {'tp2': 0}) create_stock_report(self.loc2, {'tp2': 0}) create_stock_report(self.loc3, {'tp2': 0}) self.assertEqual( len( urgent_stockout_alert.get_sql_products_list( self.district.sql_location)), 2)
def test_urgent_stockout_alert(self): urgent_stockout_alert = UrgentStockoutAlert(TEST_DOMAIN) urgent_stockout_alert.send() self.assertEqual(SMS.objects.count(), 0) create_stock_report(self.loc1, {'tp2': 0}) create_stock_report(self.loc2, {'tp2': 0}) create_stock_report(self.loc3, {'tp2': 0}) urgent_stockout_alert.send() self.assertEqual(SMS.objects.count(), 1) self.assertEqual( SMS.objects.all().first().text, URGENT_STOCKOUT % { 'location': self.district.name, 'products': "Test Product2", }) create_stock_report(self.loc1, {'tp': 0}) create_stock_report(self.loc2, {'tp': 0}) create_stock_report(self.loc3, {'tp': 0}) now = datetime.utcnow() urgent_stockout_alert.send() smses = SMS.objects.filter(date__gte=now) self.assertEqual(smses.count(), 1) self.assertEqual( smses.first().text, URGENT_STOCKOUT % { 'location': self.district.name, 'products': "Test Product, Test Product2", })
def test_all_facilities_reported(self): """No notifications generated if all have reported.""" create_stock_report(self.facility, {'tp': 5}) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)