Exemplo n.º 1
0
 def test_get_smsc_handler(self):
     """
     success message send test case
     """
     handler = get_handler('sms.handlers.SMSC', **self.attrs)
     responses.add(responses.RequestsMock.POST,
                   handler.SEND_MESSAGE_URL,
                   body=self.post_success, status=200,
                   content_type='application/json')
     response = handler.send(message='тестовое сообщение',
                             phone='79149009900')
     self.assertEqual(response['status'], const.STATUS_OK)
Exemplo n.º 2
0
    def test_on_message_send(self):
        """
        sends message
        """
        count = models.Log.objects.count()
        handler = get_handler('apps.sms.handlers.MyProvider')
        #: fake response
        responses.add(responses.RequestsMock.POST,
                      handler.SEND_MESSAGE_URL,
                      body=self.post_success,
                      status=200,
                      content_type='application/json')

        handler.send(message='сообщение', phone='79149009900')
        self.assertEqual(count + 1, models.Log.objects.count())

        log = models.Log.objects.latest('pk')
        self.assertEqual(log.message, 'сообщение')
        self.assertEqual(log.phone, '79149009900')
        self.assertEqual(log.status,
                         force_text(models.Log.STATUS_CHOICES_DICT['ok']))
Exemplo n.º 3
0
    def test_on_message_send(self):
        """
        sends message
        """
        count = models.Log.objects.count()
        handler = get_handler('apps.sms.handlers.MyProvider')
        #: fake response
        responses.add(responses.RequestsMock.POST,
                      handler.SEND_MESSAGE_URL,
                      body=self.post_success, status=200,
                      content_type='application/json')

        handler.send(message='сообщение', phone='79149009900')
        self.assertEqual(count + 1, models.Log.objects.count())

        log = models.Log.objects.latest('pk')
        self.assertEqual(log.message, 'сообщение')
        self.assertEqual(log.phone, '79149009900')
        self.assertEqual(
            log.status, force_text(models.Log.STATUS_CHOICES_DICT['ok'])
        )
Exemplo n.º 4
0
    def test_on_message_send_failure_params(self):
        """
        sends message with wrong params so sms gate should return an error
        """
        count = models.Log.objects.count()
        handler = get_handler('apps.sms.handlers.MyProvider')

        #: fake response
        responses.add(responses.RequestsMock.POST,
                      handler.SEND_MESSAGE_URL,
                      body=self.post_failure,
                      status=400,
                      content_type='application/json')

        handler.send(message='сообщение', phone='error phone')
        self.assertEqual(count + 1, models.Log.objects.count())

        log = models.Log.objects.latest('pk')
        self.assertEqual(log.message, 'сообщение')
        self.assertEqual(log.phone, 'error phone')
        self.assertEqual(log.status,
                         force_text(models.Log.STATUS_CHOICES_DICT['error']))
Exemplo n.º 5
0
    def test_on_message_send_failure_params(self):
        """
        sends message with wrong params so sms gate should return an error
        """
        count = models.Log.objects.count()
        handler = get_handler('apps.sms.handlers.MyProvider')

        #: fake response
        responses.add(responses.RequestsMock.POST,
                      handler.SEND_MESSAGE_URL,
                      body=self.post_failure, status=400,
                      content_type='application/json')

        handler.send(message='сообщение', phone='error phone')
        self.assertEqual(count + 1, models.Log.objects.count())

        log = models.Log.objects.latest('pk')
        self.assertEqual(log.message, 'сообщение')
        self.assertEqual(log.phone, 'error phone')
        self.assertEqual(
            log.status, force_text(models.Log.STATUS_CHOICES_DICT['error'])
        )
Exemplo n.º 6
0
 def test_get_unregistered_handler(self):
     """
     unregistered handler get
     """
     with self.assertRaises(exceptions.RegistryException):
         get_handler('sms.handlers.SMSTraffic')