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_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_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_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_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 on_going_stockout(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: OnGoingStockouts(domain).send() OnGoingStockoutsRMS(domain).send()
def test_missing_notification(self): """No notification if there were no reports. Covered by missing report.""" generated = list(OnGoingStockouts(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 0)