Beispiel #1
0
    def test_send_blocked(self):
        r = PhoneReceiver.objects.create(number="+18023390056",
                                         service_number="+18023390056",
                                         is_blocked=True)
        with mock.patch(
                "universal_notifications.backends.sms.engines.twilio.get_twilio_client"
        ) as call_mock:
            call_mock.return_value.messages.create.return_value.sid = 123
            send_sms("+18023390056", u"foo😄")

            self.assertEqual(call_mock.call_count, 0)
            s = PhoneSent.objects.all()
            self.assertEqual(s.count(), 1)
            self.assertEqual(s[0].receiver, r)
            self.assertEqual(s[0].status, PhoneSent.STATUS_FAILED)
Beispiel #2
0
    def test_add_to_proxy(self):
        def new_message(i, priority, from_phone="+18023390050"):
            m = PhonePendingMessages.objects.all().order_by("-id")
            self.assertEqual(m.count(), i)
            self.assertEqual(m[0].from_phone, from_phone)
            self.assertEqual(m[0].priority, priority)
            self.assertEqual(redis_mock.call_count, i)

        with mock.patch(
                "universal_notifications.backends.sms.engines.twilio.StrictRedis"
        ) as redis_mock:
            send_sms("+18023390051", "foo")
            new_message(1, 9999)

            send_sms("+18023390051", "foo", priority=1)
            new_message(2, 1)
    def test_send(self):
        with mock.patch("universal_notifications.backends.sms.engines.amazonsns.get_sns_client") as call_mock:
            call_mock.return_value.publish.return_value = {"MessageId": "mid"}
            send_sms("+18023390056", u"foo😄")

        mocked_data = {
            "Message": "foo",
            "PhoneNumber": "+18023390056",
        }
        self.assertEqual(call_mock.return_value.publish.call_args[1], mocked_data)
        r = PhoneReceiver.objects.get(number="+18023390056")
        s = PhoneSent.objects.all()
        self.assertEqual(s.count(), 1)
        self.assertEqual(s[0].receiver, r)
        self.assertEqual(s[0].sms_id, "mid")
        self.assertEqual(s[0].status, PhoneSent.STATUS_SENT)
        self.assertEqual(s[0].text, "foo")  # Strip emoji - hard to setup with mysql base settings
Beispiel #4
0
    def test_send(self):
        with mock.patch(
                "universal_notifications.backends.sms.engines.twilio.get_twilio_client"
        ) as call_mock:
            call_mock.return_value.messages.create.return_value.sid = 123
            send_sms("+18023390056", u"foo😄")

            mocked_data = {
                "body": "foo",
                "to": "+18023390056",
                "from_": "+18023390050",
            }
            self.assertEqual(
                call_mock.return_value.messages.create.call_args[1],
                mocked_data)
            r = PhoneReceiver.objects.get(number="+18023390056")
            s = PhoneSent.objects.all()
            self.assertEqual(s.count(), 1)
            self.assertEqual(s[0].receiver, r)
            self.assertEqual(s[0].status, PhoneSent.STATUS_SENT)
            self.assertEqual(
                s[0].text,
                "foo")  # Strip emoji - hard to setup with mysql base settings
Beispiel #5
0
 def send_inner(self, prepared_receivers, prepared_message):
     for receiver in prepared_receivers:
         send_sms(receiver, prepared_message, send_async=self.send_async)
 def send_inner(self, prepared_receivers, prepared_message):
     for receiver in prepared_receivers:
         self.context["receiver"] = receiver
         send_sms(receiver.phone,
                  self.prepare_message(),
                  send_async=self.send_async)