Example #1
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)
Example #2
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_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_all_facility_not_report(self):
        """Send a notification because all 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])

        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_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}
        )
Example #7
0
def urgent_non_reporting():
    domains = EWSGhanaConfig.get_all_enabled_domains()
    for domain in domains:
        UrgentNonReporting(domain).send()