Exemplo n.º 1
0
 def test_send_message(self):
     from sendsms.message import SmsMessage
     with self.settings(
             SENDSMS_BACKEND='sendsms.backends.yuntongxun.SmsBackend'):
         body = {'template_id': '185733', 'datas': ['潘运来', '20', '迪康基因']}
         obj = SmsMessage(body=body, from_phone='', to=['17798553635'])
         obj.send()
    def test_send_simple_sms(self):
        from sendsms.message import SmsMessage

        obj = SmsMessage(body="test", from_phone="111111111", to=["222222222"])
        obj.send()

        self.assertEqual(len(sendsms.outbox), 1)
Exemplo n.º 3
0
 def create_otp_for_number(cls, number):
     # The max otps generated for a number in a day are only 10.
     # Any more than 10 attempts returns False for the day.
     today_min = datetime.datetime.combine(datetime.date.today(),
                                           datetime.time.min)
     today_max = datetime.datetime.combine(datetime.date.today(),
                                           datetime.time.max)
     otps = cls.objects.filter(phone_number=number,
                               timestamp__range=(today_min, today_max))
     if otps.count() <= getattr(settings, 'PHONE_LOGIN_ATTEMPTS', 10):
         otp = cls.generate_otp(
             length=getattr(settings, 'PHONE_LOGIN_OTP_LENGTH', 6))
         phone_token = PhoneToken(phone_number=number, otp=otp)
         phone_token.save()
         from_phone = getattr(settings, 'SENDSMS_FROM_NUMBER')
         message = SmsMessage(body=render_to_string(
             "otp_sms.txt", {
                 "otp":
                 otp,
                 "id":
                 phone_token.reference_id,
                 "sitename":
                 getattr(settings, 'PHONE_LOGIN_SITENAME', "MyProjectName")
             }),
                              from_phone=from_phone,
                              to=[number])
         message.send()
         return phone_token
     else:
         return False
    def test_send_message_should_use_configured_backend(
            self, LocmemBackend, TwilioBackend):
        from sendsms.message import SmsMessage

        with self.settings(
                SENDSMS_BACKEND="sendsms.backends.celery.SmsBackend"):
            with self.settings(
                    CELERY_SENDSMS_BACKEND=
                    "sendsms.backends.twiliorest.SmsBackend"):  # noqa
                from sendsms.backends import celery

                backend = TwilioBackend()
                message = SmsMessage(body="Hello!",
                                     from_phone="29290",
                                     to=["+639123456789"])
                celery.send_messages([message])
                backend.send_messages.assert_called_once_with([message])

            with self.settings(
                    CELERY_SENDSMS_BACKEND="sendsms.backends.locmem.SmsBackend"
            ):  # noqa
                reload(celery)

                backend = LocmemBackend()
                message = SmsMessage(body="Hello!",
                                     from_phone="29290",
                                     to=["+639123456789"])
                celery.send_messages([message])
                backend.send_messages.assert_called_once_with([message])
Exemplo n.º 5
0
    def test_send_message_should_use_configured_backend(self, LocmemBackend,
                                                        TwilioBackend):
        from sendsms.message import SmsMessage

        with self.settings(SENDSMS_BACKEND='sendsms.backends.rq.SmsBackend'):
            with self.settings(RQ_SENDSMS_BACKEND='sendsms.backends.twiliorest.SmsBackend'):  # noqa
                from sendsms.backends import rq

                backend = TwilioBackend()
                message = SmsMessage(
                    body='Hello!',
                    from_phone='29290',
                    to=['+639123456789']
                )
                rq.send_messages([message])
                backend.send_messages.assert_called_once_with([message])

            with self.settings(RQ_SENDSMS_BACKEND='sendsms.backends.locmem.SmsBackend'):  # noqa
                reload(rq)

                backend = LocmemBackend()
                message = SmsMessage(
                    body='Hello!',
                    from_phone='29290',
                    to=['+639123456789']
                )
                rq.send_messages([message])
                backend.send_messages.assert_called_once_with([message])
Exemplo n.º 6
0
def send_sms(recipients, body, from_phone="ZConnect"):
    """ Send an sms message to a set of users

    Args:
        recipients (list of zconnect.modesl.User): A list of users who should recieve
            this message
        body (str): The message content. Should be short!
        from_phone (str, optional): Either a phone number or up-to 11 Alphanumeric chars.

    Returns:
        None: This function fails silently

    Raises:
        django.core.exceptions.ImproperlyConfigured - when an SMS backend is not properly
            configured.

    """
    numbers = [format_number(recipient.phone_number, PhoneNumberFormat.INTERNATIONAL) \
                for recipient in recipients if recipient.phone_number]
    logger.debug("Sending SMS to: %s", numbers)
    sms = SmsMessage(
        to=numbers,
        body=body,
        from_phone=from_phone,
    )
    sms.send()
def sendsms(request):
    from sendsms.message import SmsMessage
    message = SmsMessage(body='lolcats make me hungry',
                         from_phone='+919713872684',
                         to=['+918792414595'])
    message.send()
    return HttpResponseRedirect('/gifts')
Exemplo n.º 8
0
    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)
Exemplo n.º 9
0
    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)
Exemplo n.º 10
0
    def test_should_queue_sms(self, send_messages_mock):
        from sendsms.message import SmsMessage

        with self.settings(SENDSMS_BACKEND='sendsms.backends.rq.SmsBackend'):
            message = SmsMessage(body='Hello!',
                                 from_phone='29290',
                                 to=['+639123456789'])
            message.send()

        send_messages_mock.delay.assert_called_with([message])
    def test_should_queue_sms(self, send_messages_mock):
        from sendsms.message import SmsMessage

        with self.settings(
                SENDSMS_BACKEND="sendsms.backends.celery.SmsBackend"):
            message = SmsMessage(body="Hello!",
                                 from_phone="29290",
                                 to=["+639123456789"])
            message.send()

        send_messages_mock.delay.assert_called_with([message])
Exemplo n.º 12
0
def index(request):
   # all_album = Album.objects.all()
  #  template = loader.get_template('music/index.html')
  #  context = {
      # 'all_album':all_album
  # }
    message = SmsMessage(body='lolcats make me hungry', from_phone='+918146417711', to=['+919780088660'])
    s  = message.send()


    return HttpResponse("jfsdngkdfkgb;dgth");
Exemplo n.º 13
0
def index(request):
    # all_album = Album.objects.all()
    #  template = loader.get_template('music/index.html')
    #  context = {
    # 'all_album':all_album
    # }
    message = SmsMessage(body='lolcats make me hungry',
                         from_phone='+918146417711',
                         to=['+919780088660'])
    s = message.send()

    return HttpResponse("jfsdngkdfkgb;dgth")
Exemplo n.º 14
0
def send_email(mail):
    context = {'mail': mail}
    template = get_template('correo.html')
    content = template.render()
    email = EmailMultiAlternatives('Un correo de prueba', 'codigofacilito',
                                   settings.EMAIL_HOST_USER, [mail])
    email.attach_alternative(content, 'text/html')
    email.send()
    #api.send_sms(body='I can haz txt', from_phone='+57 3183679592', to=['+57 3183679592'])
    message = SmsMessage(body='I can haz txt',
                         from_phone='573183443996',
                         to=['573183679592'])
    message.send()
Exemplo n.º 15
0
 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'])
Exemplo n.º 16
0
Arquivo: api.py Projeto: marscj/eletec
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()
Exemplo n.º 17
0
    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
Exemplo n.º 18
0
def index(request):
    send_mail(
        'Test Pentest send Mail',
        'Bonjour a tous juste un test ',
        'patrick.dagouagauvci.edu.ci',
        ['patrick.dagouagagmail.com'],
        fail_silently=False,
    )
    print(
        "~~~~~~~~~~~~~~~~~~~~~~~~~~~MESSAGES ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n"
    )

    message = SmsMessage(body='Bonjour a tous ',
                         from_phone='+41791111111',
                         to=['+79962642'])
    message.send()
    return render(request, 'pages/index.html')
Exemplo n.º 19
0
 def create_otp_for_number(cls, number):
     # The max otps generated for a number in a day are only 10.
     # Any more than 10 attempts returns False for the day.
     today_min = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
     today_max = datetime.datetime.combine(datetime.date.today(), datetime.time.max)
     otps = cls.objects.filter(phone_number=number, timestamp__range=(today_min, today_max))
     if otps.count() <= 10:
         otp = cls.generate_otp(length=getattr(settings, 'PHONE_LOGIN_OTP_LENGTH', 6))
         phone_token = PhoneToken(phone_number=number, otp=otp)
         phone_token.save()
         message = SmsMessage(
                         body=render_to_string("otp_sms.txt", {"otp":otp, "id":phone_token.id}),
                         to=[number]
                     )
         message.send()
         return phone_token
     else:
         return False
Exemplo n.º 20
0
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')))
Exemplo n.º 21
0
 def create_otp_for_number(cls, number):
     # The max otps generated for a number in a day are only 10.
     # Any more than 10 attempts returns False for the day.
     today_min = datetime.datetime.combine(datetime.date.today(), datetime.time.min)
     today_max = datetime.datetime.combine(datetime.date.today(), datetime.time.max)
     otps = cls.objects.filter(phone_number=number, timestamp__range=(today_min, today_max))
     if otps.count() <= getattr(settings, 'PHONE_LOGIN_ATTEMPTS', 10):
         otp = cls.generate_otp(length=getattr(settings, 'PHONE_LOGIN_OTP_LENGTH', 6))
         phone_token = PhoneToken(phone_number=number, otp=otp)
         phone_token.save()
         message = SmsMessage(
             body=render_to_string(
                 "auth/otp_sms.txt",
                 {"otp": otp, "id": phone_token.id}
             ),
             to=[number]
         )
         message.send()
         return phone_token
     else:
         return False
Exemplo n.º 22
0
 def test_send_message(self):
     from sendsms.message import SmsMessage
     import json
     with self.settings(
             SENDSMS_BACKEND='sendsms.backends.aliyun.SmsBackend',
             ALIYUN_ACCESS_ID='LTAI4Fs5mnQwbw1seSDFFSTc',
             ALIYUN_ACCESS_SECRET='0pSY02mWdcZqYZCuBHQQJy90AxEhFV',
             ALIYUN_REGION=''):
         body = {
             'template_id': 'SMS_58960014',
             'datas': {
                 "code": "1234",
                 "product": "测试产品"
             },
             'sign_name': '身份验证a'
         }
         obj = SmsMessage(body=body, from_phone='', to=['17368588130'])
         res = obj.send()
         json_res = json.loads(res)
         print(json_res)
         self.assertEqual(json_res['Message'], 'OK')
Exemplo n.º 23
0
def order(request):
    multiple_form = MultiplePizzaForm()
    if request.method == 'POST':
        created_pizza_pk = None
        filled_form = PizzaForm(request.POST)
        if filled_form.is_valid():
            created_pizza = filled_form.save()
            created_pizza_pk = created_pizza.id
            note = 'Thanks for ordering! Your %s %s and %s pizza is on its way!' % (
                filled_form.cleaned_data['size'],
                filled_form.cleaned_data['Main_Course'],
                filled_form.cleaned_data['Side_Dish'],
            )
            filled_form = PizzaForm()
            SENDSMS_BACKEND = 'myapp.mysmsbackend.SmsBackend'
            api.send_sms(body='I can text',
                         from_phone='+12263406180',
                         to=['+12263406180'])
            message = SmsMessage(body='lolcats make me hungry',
                                 from_phone='+12263406180',
                                 to=['+12263406180'])
            message.send()
        else:
            note = 'Order was not created, please try again'
        new_form = PizzaForm()
        return render(
            request, 'pizza/order.html', {
                'multiple_form': multiple_form,
                'pizzaform': filled_form,
                'note': note,
                'created_pizza_pk': created_pizza_pk
            })
    else:
        form = PizzaForm()
        return render(request, 'pizza/order.html', {
            'multiple_form': multiple_form,
            'pizzaform': form
        })
Exemplo n.º 24
0
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 test_should_call_proper_url(self, _call_url_mock):
        from sendsms.message import SmsMessage

        with self.settings(
                SENDSMS_BACKEND="sendsms.backends.ovhsms.OvhSmsBackend",
                OVH_API_URL="http://fakeurl/",
                OVH_API_ACCOUNT="myaccount",
                OVH_API_LOGIN="******",
                OVH_API_PASSWORD="******",
                OVH_API_FROM="mysender",
                OVH_API_NO_STOP=False,
        ):

            message = SmsMessage(
                body="Hello!",
                from_phone="29290",  # overrides OVH_API_FROM
                to=["+639123456789"],
            )
            res = message.send()
            self.assertEqual(res, [{"result": "42"}])

        expected = (
            "http://fakeurl/?account=myaccount&class=1&contentType=text%2Fjson&from=29290&login=mylogin&"
            "message=Hello%21&noStop=0&password=mypwd&smsCoding=2&to=%2B639123456789",
        )

        self.assertEqual(_call_url_mock.call_args, (expected, ))

        with self.settings(
                SENDSMS_BACKEND="sendsms.backends.ovhsms.OvhSmsBackend",
                OVH_API_ACCOUNT="myaccount",
                OVH_API_LOGIN="******",
                OVH_API_PASSWORD="******",
                OVH_API_FROM="mysender",
        ):

            message = SmsMessage(
                body="Wêlcome à vous\nHenrï & Jack!\r\n",
                from_phone="thierry",  # overrides OVH_API_FROM
                to=["0699"],
            )
            res = message.send()
            self.assertEqual(res, [{"result": "42"}])

            expected = (
                "https://www.ovh.com/cgi-bin/sms/http2sms.cgi?account=myaccount&class=1&contentType=text%2Fjson&"
                "from=thierry&login=mylogin&message=W%C3%AAlcome+%C3%A0+vous%0DHenr%C3%AF+%26+Jack%21%0D&"
                "noStop=1&password=mypwd&smsCoding=2&to=0699", )
            self.assertEqual(_call_url_mock.call_args, (expected, ))
 def setUp(self):
     self.sms_message = SmsMessage('sms body', from_phone='0001', to=['0002', '0003'], flash=True)
     serializer = load_object(django_gearman_proxy.settings.GEARMAN_SMS_SERIALIZER)
     self.serialized = json.loads(serializer(self.sms_message))
Exemplo n.º 27
0
def sendsms(request):
    from sendsms.message import SmsMessage

    message = SmsMessage(body="lolcats make me hungry", from_phone="+919713872684", to=["+918792414595"])
    message.send()
    return HttpResponseRedirect("/gifts")
Exemplo n.º 28
0
    def test_send_simple_sms(self):
        from sendsms.message import SmsMessage
        obj = SmsMessage(body="test", from_phone='111111111', to=['222222222'])
        obj.send()

        self.assertEqual(len(sendsms.outbox), 1)
Exemplo n.º 29
0
 def sms(self):
     return SmsMessage(
         to=[self.phone],
         body=self.body(),
     )
Exemplo n.º 30
0
def sendsms(request):
    from sendsms.message import SmsMessage
    message = SmsMessage(body='lolcats make me hungry', from_phone='+919713872684', to=['+918792414595'])
    message.send()
    return HttpResponseRedirect('/gifts')