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 get_notifications(self): for sql_location in self.get_sql_locations(): products = self.get_sql_products_list(sql_location) for user in self.get_users(sql_location): message = self.get_message(sql_location.name, user, products) if message: yield Notification(self.domain, user, message)
def get_notifications(self): for sql_location in self.get_sql_locations(): message = self.get_message(sql_location) if not message: continue for user in self.get_users(sql_location): yield Notification(self.domain, user, message)
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')
class SMSNotificationTestCase(EWSTestCase): """Saved notifications should trigger SMS to users with associated contacts.""" TEST_DOMAIN = 'notifications-test-ews5' @classmethod def setUpClass(cls): super(SMSNotificationTestCase, cls).setUpClass() cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) 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 tearDown(self): for location in Location.by_domain(self.TEST_DOMAIN): location.delete() for user in WebUser.by_domain(self.TEST_DOMAIN): user.delete() delete_domain_phone_numbers(self.TEST_DOMAIN) super(SMSNotificationTestCase, self).tearDown() def test_send_sms(self): """Successful SMS sent.""" with mock.patch('custom.ewsghana.alerts.alert.send_sms') as send: self.notification.send() self.assertTrue(send.called) args, kwargs = send.call_args domain, user, phone_number, text = args self.assertEqual(self.notification.message, text) self.assertEqual(phone_number, '+4444') def test_no_connections(self): """No message will be sent if contact doesn't have an associated connection.""" self.user.phone_numbers = [] self.user.save() with mock.patch('custom.ewsghana.alerts.alert.send_sms') as send: self.notification.send() self.assertFalse(send.called) 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)
class SMSNotificationTestCase(TestCase): """Saved notifications should trigger SMS to users with associated contacts.""" TEST_DOMAIN = 'notifications-test-ews5' @classmethod def setUpClass(cls): cls.backend, cls.sms_backend_mapping = setup_default_sms_test_backend() cls.domain = prepare_domain(cls.TEST_DOMAIN) @classmethod def tearDownClass(cls): cls.sms_backend_mapping.delete() cls.backend.delete() 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 tearDown(self): for location in Location.by_domain(self.TEST_DOMAIN): location.delete() for user in WebUser.by_domain(self.TEST_DOMAIN): user.delete() for vn in VerifiedNumber.by_domain(self.TEST_DOMAIN): vn.delete() def test_send_sms(self): """Successful SMS sent.""" with mock.patch('custom.ewsghana.alerts.alert.send_sms') as send: self.notification.send() self.assertTrue(send.called) args, kwargs = send.call_args domain, user, phone_number, text = args self.assertEqual(self.notification.message, text) self.assertEqual(phone_number, '+4444') def test_no_connections(self): """No message will be sent if contact doesn't have an associated connection.""" self.user.phone_numbers = [] self.user.save() with mock.patch('custom.ewsghana.alerts.alert.send_sms') as send: self.notification.send() self.assertFalse(send.called) 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)