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_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 setUpClass(cls): super(EWSTestCase, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(TEST_DOMAIN) cls.national = make_loc(code='national', name='National', type='country', domain=TEST_DOMAIN) cls.region = make_loc(code="region", name="Test Region", type="region", domain=TEST_DOMAIN, parent=cls.national) cls.rms = make_loc(code="rms", name="Test Medical Store", type="Regional Medical Store", domain=TEST_DOMAIN, parent=cls.region) cls.rms2 = make_loc(code="rms2", name="Test Medical Store 2", type="Regional Medical Store", domain=TEST_DOMAIN, parent=cls.region) cls.district = make_loc(code="district", name="Test District", type="district", domain=TEST_DOMAIN) cls.loc1 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN, parent=cls.district) cls.loc2 = make_loc(code="tf2", name="Test Facility 2", type="Hospital", domain=TEST_DOMAIN, parent=cls.district) cls.user1 = bootstrap_web_user( username='******', phone_number='1111', location=cls.district, domain=TEST_DOMAIN, first_name='test', last_name='test1', user_data={ 'role': [] }, email='*****@*****.**', password='******' ) set_sms_notifications(TEST_DOMAIN, cls.user1, True) cls.national_user = bootstrap_web_user( username='******', phone_number='2222', location=cls.national, domain=TEST_DOMAIN, first_name='test', last_name='test2', user_data={ 'role': [] }, email='*****@*****.**', password='******' ) set_sms_notifications(TEST_DOMAIN, cls.national_user, True) cls.regional_user = bootstrap_web_user( username='******', phone_number='4444', location=cls.region, domain=TEST_DOMAIN, first_name='test', last_name='test4', user_data={ 'role': [] }, email='*****@*****.**', password='******' ) set_sms_notifications(TEST_DOMAIN, cls.regional_user, True) cls.product = Product(domain=TEST_DOMAIN, name='Test Product', code_='tp', unit='each') cls.product.save() cls.product2 = Product(domain=TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') cls.product2.save() assign_products_to_location(cls.loc1, [cls.product]) assign_products_to_location(cls.loc2, [cls.product, cls.product2]) assign_products_to_location(cls.rms, [cls.product, cls.product2])
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 setUpClass(cls): super(TestUrgentAlerts, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(TEST_DOMAIN) cls.district = make_loc(code="district", name="Test District", type="district", domain=TEST_DOMAIN) cls.loc1 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN, parent=cls.district) cls.loc2 = make_loc(code="tf2", name="Test Facility 2", type="Hospital", domain=TEST_DOMAIN, parent=cls.district) cls.loc3 = make_loc(code="tf3", name="Test Facility 3", type="Hospital", domain=TEST_DOMAIN, parent=cls.district) cls.loc4 = make_loc(code="tf4", name="Test Facility 4", type="Hospital", domain=TEST_DOMAIN, parent=cls.district) cls.product = Product(domain=TEST_DOMAIN, name='Test Product', code_='tp', unit='each') cls.product.save() cls.product2 = Product(domain=TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each') cls.product2.save() cls.user1 = bootstrap_web_user( username='******', phone_number='1111', location=cls.district, domain=TEST_DOMAIN, first_name='test', last_name='test1', user_data={ 'role': [] }, email='*****@*****.**', password='******' ) set_sms_notifications(TEST_DOMAIN, cls.user1, True)
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() other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.region, 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]) generated = list(UrgentNonReporting(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_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 setUp(self): self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district') self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.district, email='*****@*****.**', password='******' ) set_sms_notifications(self.domain, self.user, True) self.notification = Notification(self.TEST_DOMAIN, self.user, 'test')
def setUp(self): self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district') self.facility = make_loc('test-faciity', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.district, email='*****@*****.**', password='******', user_data={} ) self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each') self.product.save()
def setUp(self): super(SMSNotificationTestCase, self).setUp() self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district') self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.district, email='*****@*****.**', password='******' ) set_sms_notifications(self.domain, self.user, True) self.notification = Notification(self.TEST_DOMAIN, self.user, 'test')
def setUp(self): super(MissingReportNotificationTestCase, self).setUp() self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district') self.facility = make_loc('test-faciity', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.district, email='*****@*****.**', password='******', user_data={} ) self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each') self.product.save()
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_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 test_multiple_users(self): """Each user will get their own urgent stockout notification.""" other_user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+44445', location=self.region, 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]) generated = list(UrgentNonReporting(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]) generated = list(UrgentNonReporting(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 setUp(self): self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each', program_id=self.program.get_id) self.product.save() self.country = make_loc('test-country', 'Test country', self.TEST_DOMAIN, 'country') self.region = make_loc('test-region', 'Test Region', self.TEST_DOMAIN, 'region', parent=self.country) self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district', parent=self.region) self.facility = make_loc('test-facility', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.other_facility = make_loc('test-facility2', 'Test Facility 2', self.TEST_DOMAIN, 'Polyclinic', self.district) self.last_facility = make_loc('test-facility3', 'Test Facility 3', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.region, email='*****@*****.**', password='******', user_data={} )
def setUp(self): super(UrgentNonReportingNotificationTestCase, self).setUp() self.product = Product(domain=self.TEST_DOMAIN, name='Test Product', code_='tp', unit='each', program_id=self.program.get_id) self.product.save() self.country = make_loc('test-country', 'Test country', self.TEST_DOMAIN, 'country') self.region = make_loc('test-region', 'Test Region', self.TEST_DOMAIN, 'region', parent=self.country) self.district = make_loc('test-district', 'Test District', self.TEST_DOMAIN, 'district', parent=self.region) self.facility = make_loc('test-facility', 'Test Facility', self.TEST_DOMAIN, 'Polyclinic', self.district) self.other_facility = make_loc('test-facility2', 'Test Facility 2', self.TEST_DOMAIN, 'Polyclinic', self.district) self.last_facility = make_loc('test-facility3', 'Test Facility 3', self.TEST_DOMAIN, 'Polyclinic', self.district) self.user = bootstrap_web_user( username='******', domain=self.TEST_DOMAIN, phone_number='+4444', location=self.region, email='*****@*****.**', password='******', user_data={} )
def setUpClass(cls): super(TestReminders, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(TEST_DOMAIN) cls.loc1 = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=TEST_DOMAIN) cls.loc2 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN) cls.region = make_loc(code="region", name="Test Region", type="region", domain=TEST_DOMAIN) cls.user1 = bootstrap_user( username="******", phone_number="1111", home_loc=cls.loc2, domain=TEST_DOMAIN, first_name="test", last_name="test1", user_data={"role": []}, ) cls.user2 = bootstrap_user( username="******", phone_number="2222", home_loc=cls.loc1, domain=TEST_DOMAIN, first_name="test", last_name="test2", user_data={"role": ["Other"], "needs_reminders": "False"}, ) cls.user3 = bootstrap_user( username="******", phone_number="3333", home_loc=cls.loc2, domain=TEST_DOMAIN, first_name="test", last_name="test3", user_data={"role": ["Nurse"], "needs_reminders": "True"}, ) cls.in_charge = bootstrap_user( username="******", phone_number="4444", home_loc=cls.loc2, domain=TEST_DOMAIN, first_name="test", last_name="test4", user_data={"role": ["In Charge"]}, ) cls.web_user = bootstrap_web_user( domain=TEST_DOMAIN, username="******", password="******", email="*****@*****.**", location=cls.loc2, phone_number="5555", ) EWSExtension.objects.create( domain=TEST_DOMAIN, user_id=cls.web_user.get_id, sms_notifications=True, location_id=cls.loc2.get_id ) cls.web_user2 = bootstrap_web_user( domain=TEST_DOMAIN, username="******", password="******", email="*****@*****.**", location=cls.region, phone_number="6666", ) set_sms_notifications(TEST_DOMAIN, cls.web_user2, True) FacilityInCharge.objects.create(user_id=cls.in_charge.get_id, location=cls.loc2.sql_location) cls.product = Product(domain=TEST_DOMAIN, name="Test Product", code_="tp", unit="each") cls.product.save() cls.product2 = Product(domain=TEST_DOMAIN, name="Test Product2", code_="tp2", unit="each") cls.product2.save() sql_product = SQLProduct.objects.get(product_id=cls.product.get_id) sql_product2 = SQLProduct.objects.get(product_id=cls.product2.get_id) sql_location1 = cls.loc1.sql_location sql_location2 = cls.loc2.sql_location sql_location1.products = [sql_product] sql_location2.products = [sql_product, sql_product2] sql_location1.save() sql_location2.save()
def setUpClass(cls): cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(TEST_DOMAIN) cls.loc1 = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=TEST_DOMAIN) cls.loc2 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN) cls.region = make_loc(code="region", name="Test Region", type="region", domain=TEST_DOMAIN) cls.user1 = bootstrap_user( username='******', phone_number='1111', home_loc=cls.loc2, domain=TEST_DOMAIN, first_name='test', last_name='test1', user_data={ 'role': [] } ) cls.user2 = bootstrap_user( username='******', phone_number='2222', home_loc=cls.loc1, domain=TEST_DOMAIN, first_name='test', last_name='test2', user_data={ 'role': ['Other'], 'needs_reminders': "False" } ) cls.user3 = bootstrap_user( username='******', phone_number='3333', home_loc=cls.loc2, domain=TEST_DOMAIN, first_name='test', last_name='test3', user_data={ 'role': ['Nurse'], 'needs_reminders': "True" } ) cls.in_charge = bootstrap_user( username='******', phone_number='4444', home_loc=cls.loc2, domain=TEST_DOMAIN, first_name='test', last_name='test4', user_data={ 'role': ['In Charge'] } ) cls.web_user = bootstrap_web_user( domain=TEST_DOMAIN, username='******', password='******', email='*****@*****.**', location=cls.loc2, phone_number='5555' ) EWSExtension.objects.create( domain=TEST_DOMAIN, user_id=cls.web_user.get_id, sms_notifications=True, location_id=cls.loc2.get_id ) cls.web_user2 = bootstrap_web_user( domain=TEST_DOMAIN, username='******', password='******', email='*****@*****.**', location=cls.region, phone_number='6666' ) set_sms_notifications(TEST_DOMAIN, cls.web_user2, True) FacilityInCharge.objects.create( user_id=cls.in_charge.get_id, location=cls.loc2.sql_location ) cls.product = Product( domain=TEST_DOMAIN, name='Test Product', code_='tp', unit='each' ) cls.product.save() cls.product2 = Product( domain=TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each' ) cls.product2.save() sql_product = SQLProduct.objects.get(product_id=cls.product.get_id) sql_product2 = SQLProduct.objects.get(product_id=cls.product2.get_id) sql_location1 = cls.loc1.sql_location sql_location2 = cls.loc2.sql_location sql_location1.products = [sql_product] sql_location2.products = [sql_product, sql_product2] sql_location1.save() sql_location2.save()
def setUpClass(cls): super(TestReminders, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(TEST_DOMAIN) cls.loc1 = make_loc(code="garms", name="Test RMS", type="Regional Medical Store", domain=TEST_DOMAIN) cls.loc2 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN) cls.region = make_loc(code="region", name="Test Region", type="region", domain=TEST_DOMAIN) cls.user1 = bootstrap_user( username='******', phone_number='1111', home_loc=cls.loc2, domain=TEST_DOMAIN, first_name='test', last_name='test1', user_data={ 'role': [] } ) cls.user2 = bootstrap_user( username='******', phone_number='2222', home_loc=cls.loc1, domain=TEST_DOMAIN, first_name='test', last_name='test2', user_data={ 'role': ['Other'], 'needs_reminders': "False" } ) cls.user3 = bootstrap_user( username='******', phone_number='3333', home_loc=cls.loc2, domain=TEST_DOMAIN, first_name='test', last_name='test3', user_data={ 'role': ['Nurse'], 'needs_reminders': "True" } ) cls.in_charge = bootstrap_user( username='******', phone_number='4444', home_loc=cls.loc2, domain=TEST_DOMAIN, first_name='test', last_name='test4', user_data={ 'role': ['In Charge'] } ) cls.web_user = bootstrap_web_user( domain=TEST_DOMAIN, username='******', password='******', email='*****@*****.**', location=cls.loc2, phone_number='5555' ) EWSExtension.objects.create( domain=TEST_DOMAIN, user_id=cls.web_user.get_id, sms_notifications=True, location_id=cls.loc2.get_id ) cls.web_user2 = bootstrap_web_user( domain=TEST_DOMAIN, username='******', password='******', email='*****@*****.**', location=cls.region, phone_number='6666' ) set_sms_notifications(TEST_DOMAIN, cls.web_user2, True) FacilityInCharge.objects.create( user_id=cls.in_charge.get_id, location=cls.loc2.sql_location ) cls.product = Product( domain=TEST_DOMAIN, name='Test Product', code_='tp', unit='each' ) cls.product.save() cls.product2 = Product( domain=TEST_DOMAIN, name='Test Product2', code_='tp2', unit='each' ) cls.product2.save() sql_product = SQLProduct.objects.get(product_id=cls.product.get_id) sql_product2 = SQLProduct.objects.get(product_id=cls.product2.get_id) sql_location1 = cls.loc1.sql_location sql_location2 = cls.loc2.sql_location sql_location1.products = [sql_product] sql_location2.products = [sql_product, sql_product2] sql_location1.save() sql_location2.save()
def setUpClass(cls): cls.domain = prepare_domain(TEST_DOMAIN) cls.sms_backend_mapping, cls.backend = create_backend() cls.national = make_loc(code="national", name="National", type="country", domain=TEST_DOMAIN) cls.region = make_loc(code="region", name="Test Region", type="region", domain=TEST_DOMAIN, parent=cls.national) cls.rms = make_loc( code="rms", name="Test Medical Store", type="Regional Medical Store", domain=TEST_DOMAIN, parent=cls.region ) cls.rms2 = make_loc( code="rms2", name="Test Medical Store 2", type="Regional Medical Store", domain=TEST_DOMAIN, parent=cls.region, ) cls.district = make_loc(code="district", name="Test District", type="district", domain=TEST_DOMAIN) cls.loc1 = make_loc(code="tf", name="Test Facility", type="Hospital", domain=TEST_DOMAIN, parent=cls.district) cls.loc2 = make_loc( code="tf2", name="Test Facility 2", type="Hospital", domain=TEST_DOMAIN, parent=cls.district ) cls.user1 = bootstrap_web_user( username="******", phone_number="1111", location=cls.district, domain=TEST_DOMAIN, first_name="test", last_name="test1", user_data={"role": []}, email="*****@*****.**", password="******", ) set_sms_notifications(TEST_DOMAIN, cls.user1, True) cls.national_user = bootstrap_web_user( username="******", phone_number="2222", location=cls.national, domain=TEST_DOMAIN, first_name="test", last_name="test2", user_data={"role": []}, email="*****@*****.**", password="******", ) set_sms_notifications(TEST_DOMAIN, cls.national_user, True) cls.regional_user = bootstrap_web_user( username="******", phone_number="4444", location=cls.region, domain=TEST_DOMAIN, first_name="test", last_name="test4", user_data={"role": []}, email="*****@*****.**", password="******", ) set_sms_notifications(TEST_DOMAIN, cls.regional_user, True) cls.product = Product(domain=TEST_DOMAIN, name="Test Product", code_="tp", unit="each") cls.product.save() cls.product2 = Product(domain=TEST_DOMAIN, name="Test Product2", code_="tp2", unit="each") cls.product2.save() assign_products_to_location(cls.loc1, [cls.product]) assign_products_to_location(cls.loc2, [cls.product, cls.product2]) assign_products_to_location(cls.rms, [cls.product, cls.product2])