Example #1
0
    def send_token(self,
                   phone_number,
                   obj,
                   slug=None,
                   context=None,
                   template_slug='token-validation'):
        """
        Invalidate old tokens, create validation token and send key inside sms to selected phone_number
        """

        context = context or {}

        # Invalidate old tokens
        self.filter(validating_type=ContentType.objects.get_for_model(obj),
                    validating_id=obj.pk,
                    is_active=True).update(is_active=False)

        # Create new token
        token = self.create(validating_obj=obj,
                            phone_number=phone_number,
                            slug=slug)
        context.update({'key': token.key})

        try:
            return not sender.send_template(
                phone_number, slug=template_slug, context=context).failed
        except sender.SMSSendingError:
            return False
    def test_sms_template_should_be_immediately_send(self):
        responses.add(responses.POST, settings.ATS_URL, content_type='text/xml',
                      body=self.ATS_SINGLE_SMS_REQUEST_RESPONSE_SENT.format(245), status=200)
        sms1 = send_template('+420777111222', slug='test', context={'variable': 'context works'}, pk=245)

        sms1 = OutputSMS.objects.get(pk=sms1.pk)

        assert_equal(sms1.state, ATS_STATES.OK)
        assert_true('context works' in sms1.content)
        assert_is_not_none(sms1.sent_at)
Example #3
0
    def test_sms_template_should_be_immediately_send(self):
        responses.add(responses.POST, settings.ATS_SMS_URL, content_type='text/xml',
                      body=self.ATS_SINGLE_SMS_REQUEST_RESPONSE_SENT.format(245), status=200)
        sms1 = send_template('+420777111222', slug='test', context={'variable': 'context works'}, pk=245)

        sms1 = OutputSMS.objects.get(pk=sms1.pk)

        assert_equal(sms1.state, ATS_STATES.OK)
        assert_true('context works' in sms1.content)
        assert_is_not_none(sms1.sent_at)
Example #4
0
    def send_token(self, phone_number, obj, slug=None, context=None, template_slug='token-validation'):
        """
        Invalidate old tokens, create validation token and send key inside sms to selected phone_number
        """

        context = context or {}

        # Invalidate old tokens
        self.filter(validating_type=ContentType.objects.get_for_model(obj),
                    validating_id=obj.pk, is_active=True).update(is_active=False)

        # Create new token
        token = self.create(validating_obj=obj, phone_number=phone_number, slug=slug)
        context.update(
            {'key': token.key}
        )

        try:
            return not sender.send_template(phone_number, slug=template_slug, context=context).failed
        except sender.SMSSendingError:
            return False