Esempio n. 1
0
    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)
Esempio n. 2
0
    def test_stockout_reminder(self):
        stockout_notification_to_web_supers()
        smses = SMS.objects.all()
        self.assertEqual(smses.count(), 0)

        create_stock_report(
            self.loc2, {
                'tp': 0
            }
        )

        stockout_notification_to_web_supers()
        smses = SMS.objects.all()
        self.assertEqual(smses.count(), 1)

        last_modified_date = StockState.objects.latest('last_modified_date').last_modified_date.strftime('%b %d')

        self.assertEqual(
            smses[0].text,
            STOCKOUT_REPORT % {
                'name': self.web_user.full_name,
                'facility': self.loc2.name,
                'products': 'Test Product',
                'date': last_modified_date
            }
        )

        set_sms_notifications(TEST_DOMAIN, self.web_user, False)
        self.web_user.save()

        now = datetime.utcnow()
        stockout_notification_to_web_supers()
        smses = SMS.objects.filter(date__gte=now)
        self.assertEqual(smses.count(), 0)
Esempio n. 3
0
    def test_stockout_reminder(self):
        stockout_notification_to_web_supers()
        smses = SMS.objects.all()
        self.assertEqual(smses.count(), 0)

        create_stock_report(
            self.loc2, {
                'tp': 0
            }
        )

        stockout_notification_to_web_supers()
        smses = SMS.objects.all()
        self.assertEqual(smses.count(), 1)

        last_modified_date = StockState.objects.latest('last_modified_date').last_modified_date.strftime('%b %d')

        self.assertEqual(
            smses[0].text,
            STOCKOUT_REPORT % {
                'name': self.web_user.full_name,
                'facility': self.loc2.name,
                'products': 'Test Product',
                'date': last_modified_date
            }
        )

        set_sms_notifications(TEST_DOMAIN, self.web_user, False)
        self.web_user.save()

        now = datetime.utcnow()
        stockout_notification_to_web_supers()
        smses = SMS.objects.filter(date__gte=now)
        self.assertEqual(smses.count(), 0)
Esempio n. 4
0
    def test_stockout_reminder(self):
        stockout_notification_to_web_supers()
        smses = SMS.objects.all()
        self.assertEqual(smses.count(), 0)

        create_stock_report(self.loc2, {"tp": 0})

        stockout_notification_to_web_supers()
        smses = SMS.objects.all()
        self.assertEqual(smses.count(), 1)

        last_modified_date = StockState.objects.latest("last_modified_date").last_modified_date.strftime("%b %d")

        self.assertEqual(
            smses[0].text,
            STOCKOUT_REPORT
            % {
                "name": self.web_user.full_name,
                "facility": self.loc2.name,
                "products": "Test Product",
                "date": last_modified_date,
            },
        )

        set_sms_notifications(TEST_DOMAIN, self.web_user, False)
        self.web_user.save()

        now = datetime.utcnow()
        stockout_notification_to_web_supers()
        smses = SMS.objects.filter(date__gte=now)
        self.assertEqual(smses.count(), 0)
Esempio n. 5
0
    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)
Esempio n. 6
0
 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')
Esempio n. 7
0
 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')
Esempio n. 8
0
    def test_visit_reminder(self):
        reminder_to_visit_website()
        smses = SMS.objects.all()
        self.assertEqual(smses.count(), 0)
        now = datetime.utcnow()
        self.web_user2.last_login = now - timedelta(weeks=14)
        self.web_user2.save()

        reminder_to_visit_website()

        smses = SMS.objects.filter(date__gte=now)
        self.assertEqual(smses.count(), 1)

        set_sms_notifications(TEST_DOMAIN, self.web_user2, False)
        self.web_user2.save()

        now = datetime.utcnow()
        reminder_to_visit_website()

        smses = SMS.objects.filter(date__gte=now)
        self.assertEqual(smses.count(), 0)
Esempio n. 9
0
    def test_visit_reminder(self):
        reminder_to_visit_website()
        smses = SMS.objects.all()
        self.assertEqual(smses.count(), 0)
        now = datetime.utcnow()
        self.web_user2.last_login = now - timedelta(weeks=14)
        self.web_user2.save()

        reminder_to_visit_website()

        smses = SMS.objects.filter(date__gte=now)
        self.assertEqual(smses.count(), 1)

        set_sms_notifications(TEST_DOMAIN, self.web_user2, False)
        self.web_user2.save()

        now = datetime.utcnow()
        reminder_to_visit_website()

        smses = SMS.objects.filter(date__gte=now)
        self.assertEqual(smses.count(), 0)
Esempio n. 10
0
    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])
Esempio n. 11
0
 def test_opt_out(self):
     """No message will be sent if the user has opted out of the notifications."""
     set_sms_notifications(self.domain, self.user, False)
     with mock.patch('custom.ewsghana.alerts.alert.send_sms') as send:
         self.notification.send()
         self.assertFalse(send.called)
Esempio n. 12
0
    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()
Esempio n. 13
0
 def test_opt_out(self):
     """No message will be sent if the user has opted out of the notifications."""
     set_sms_notifications(self.domain, self.user, False)
     with mock.patch('custom.ewsghana.alerts.alert.send_sms') as send:
         self.notification.send()
         self.assertFalse(send.called)
Esempio n. 14
0
    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()
Esempio n. 15
0
    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()
Esempio n. 16
0
    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])