def prepare_message(self): """ Returns a django ``EmailMessage`` or ``EmailMultiAlternatives`` object, depending on whether html_message is empty. """ if self.template is not None: _context = Context(self.context) message = Template(self.template.content).render(_context) else: message = self.message conf = getattr(settings, 'TEXT_OFFICE') backend_conf = conf['BACKENDS'].get(self.backend_alias or 'default') klass = backend_conf.get('class') connection = get_connection( klass, **backend_conf.get('settings', {}) ) sms = SmsMessage( body=message, from_phone=self.sender, to=[text_type(self.recipient), ], connection=connection ) self._cached_sms = sms return sms
def setUp(self): self.func = django_gearman_proxy.backends.sms.submit_job django_gearman_proxy.backends.sms.submit_job = lambda task_name, data: ( task_name, data) self.connection = get_connection( path='django_gearman_proxy.backends.sms.SmsBackend') self.message = SmsMessage(body='body', from_phone='0001', to=['0002'])
def test_send_esendex_sandbox(self): from sendsms.message import SmsMessage from sendsms.api import get_connection connection = get_connection('sendsms.backends.esendex.SmsBackend') obj = SmsMessage(body="test", from_phone='111111111', to=['222222222'], connection=connection) res = obj.send() self.assertEqual(res, 1)
def unserialize(serialized): """Util for unserializing json data and constructing new SmsMessage object. :param serialized: json serialized SmsMessage object :type serialized: string :returns: SmsMessage object constructed from json representation :rtype: sendsms.message.SmsMessage """ sms_props = json.loads(serialized) return SmsMessage(sms_props.get('body'), from_phone=sms_props.get('from_phone'), to=sms_props.get('to'), flash=sms_props.get('flash'), connection=get_connection(path=sms_props.get('connection')))
def send_sms(body, from_phone, to, flash=False, fail_silently=False, auth_user=None, auth_password=None, connection=None): """ Easy wrapper for send a single SMS to a recipient list. :returns: the number of SMSs sent. """ from sendsms.message import SmsMessage connection = connection or get_connection( username = auth_user, password = auth_password, fail_silently = fail_silently ) return SmsMessage(body=body, from_phone=from_phone, to=to, \ flash=flash, connection=connection).send()
def send_mass_sms(datatuple, fail_silently=False, auth_user=None, auth_password=None, connection=None): """ Given a datatuple of (message, from_phone, to, flash), sends each message to each recipient list. :returns: the number of SMSs sent. """ from sendsms.message import SmsMessage connection = connection or get_connection( username = auth_user, password = auth_password, fail_silently = fail_silently ) messages = [SmsMessage(message=message, from_phone=from_phone, to=to, flash=flash) for message, from_phone, to, flash in datatuple] connection.send_messages(messages)
def send_sms(body, from_phone, to, flash=False, fail_silently=False, auth_user=None, auth_password=None, connection=None): """ Easy wrapper for send a single SMS to a recipient list. :returns: the number of SMSs sent. """ from sendsms.message import SmsMessage connection = connection or get_connection(username=auth_user, password=auth_password, fail_silently=fail_silently) return SmsMessage(body=body, from_phone=from_phone, to=to, \ flash=flash, connection=connection).send()
def send_mass_sms(datatuple, fail_silently=False, auth_user=None, auth_password=None, connection=None): """ Given a datatuple of (message, from_phone, to, flash), sends each message to each recipient list. :returns: the number of SMSs sent. """ from sendsms.message import SmsMessage connection = connection or get_connection(username=auth_user, password=auth_password, fail_silently=fail_silently) messages = [ SmsMessage(message=message, from_phone=from_phone, to=to, flash=flash) for message, from_phone, to, flash in datatuple ] connection.send_messages(messages)
def get_connection(self, fail_silently=False): if not self.connection: self.connection = get_connection(fail_silently=fail_silently) return self.connection
def send_messages(messages): connection = get_connection(RQ_SENDSMS_BACKEND) connection.send_messages(messages)
def setUp(self): self.func = django_gearman_proxy.backends.sms.submit_job django_gearman_proxy.backends.sms.submit_job = lambda task_name, data: (task_name, data) self.connection = get_connection(path='django_gearman_proxy.backends.sms.SmsBackend') self.message = SmsMessage(body='body', from_phone='0001', to=['0002'])
def test_submit_mail_job_fail_silently(self): self.connection = get_connection(backend='django_gearman_proxy.backends.sms.SmsBackend', fail_silently=True) result = self.connection.send_messages([{}]) self.assertEqual(result, 0)
def get_connection(self, fail_silently=False): if not self.backend: return self.connection = get_connection(path=self.backend, fail_silently=fail_silently) return self.connection
def test_submit_mail_job_fail_silently(self): self.connection = get_connection( backend='django_gearman_proxy.backends.sms.SmsBackend', fail_silently=True) result = self.connection.send_messages([{}]) self.assertEqual(result, 0)
def send_messages(messages): connection = get_connection(CELERY_SENDSMS_BACKEND) connection.send_messages(messages)