def test_missing_notification(self): """Inspect the generated notifcation for a non-reporting facility.""" 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_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_product_type_filter(self): """User can recieve missing 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) other_product = Product(domain=self.TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') other_product2 = Product(domain=self.TEST_DOMAIN, name='Test Product3', code_='tp3', unit='each') other_product.save() other_product2.save() assign_products_to_location( self.facility, [self.product, other_product, other_product2]) 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_facility_in_district(self): """Facility location can be any child of the district.""" make_loc('test-faciity2', 'Test Facility2', self.TEST_DOMAIN, 'Polyclinic', self.district) 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_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_multiple_users(self): """Each user will get their own notification.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.district, password='******', email='*****@*****.**', user_data={} ) generated = list(OnGoingNonReporting(self.TEST_DOMAIN).get_notifications()) self.assertEqual(len(generated), 2) self.assertEqual( {notification.user.get_id for notification in generated}, {other_user.get_id, self.user.get_id} )
def on_going_non_reporting(): domains = EWSGhanaConfig.get_all_enabled_domains() for domain in domains: OnGoingNonReporting(domain).send()
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)