예제 #1
0
class TestStartEnterpriseBackendRequest(TestCase):
    def setUp(self):
        self.backend = StartEnterpriseBackend()
        self.backend.set_extra_fields(
            username=TEST_USERNAME,
            password=TEST_PASSWORD,
            sender_id=TEST_SENDER_ID,
        )

    def test_unicode(self):
        queued_sms = QueuedSMS(
            phone_number=TEST_PHONE_NUMBER,
            text=TEST_UNICODE_MESSAGE,
        )
        self.assertEqual(
            self.backend.get_params(queued_sms), {
                'usr': TEST_USERNAME,
                'pass': TEST_PASSWORD,
                'msisdn': strip_plus(TEST_PHONE_NUMBER),
                'sid': TEST_SENDER_ID,
                'mt': LONG_UNICODE_MSG_TYPE,
                'msg': '0928092E0938094D09240947',
            })

    def test_phone_number_is_valid(self):
        self.assertFalse(StartEnterpriseBackend.phone_number_is_valid('+91'))
        self.assertFalse(
            StartEnterpriseBackend.phone_number_is_valid('+123456789'))
        self.assertTrue(
            StartEnterpriseBackend.phone_number_is_valid('+910123456789'))
예제 #2
0
    def test_handle_success(self):
        backend = StartEnterpriseBackend()
        queued_sms = QueuedSMS()

        backend.handle_response(queued_sms, 200, SUCCESSFUL_RESPONSE)
        self.assertEqual(queued_sms.backend_message_id, SUCCESSFUL_RESPONSE)
        self.assertFalse(queued_sms.error)
예제 #3
0
 def setUp(self):
     self.backend = StartEnterpriseBackend()
     self.backend.set_extra_fields(
         username=TEST_USERNAME,
         password=TEST_PASSWORD,
         sender_id=TEST_SENDER_ID,
     )
예제 #4
0
    def test_handle_success(self):
        backend = StartEnterpriseBackend()
        queued_sms = QueuedSMS(couch_id=uuid.uuid4().hex)

        backend.handle_response(queued_sms, 200, SUCCESSFUL_RESPONSE)
        dlr = StartEnterpriseDeliveryReceipt.objects.get(sms_id=queued_sms.couch_id)
        self.addCleanup(dlr.delete)
        self.assertEqual(dlr.message_id, SUCCESSFUL_RESPONSE)
        self.assertFalse(queued_sms.error)
예제 #5
0
    def test_handle_success(self):
        backend = StartEnterpriseBackend()
        queued_sms = QueuedSMS(couch_id=uuid.uuid4().hex)

        backend.handle_response(queued_sms, 200, SUCCESSFUL_RESPONSE)
        dlr = StartEnterpriseDeliveryReceipt.objects.get(
            sms_id=queued_sms.couch_id)
        self.addCleanup(dlr.delete)
        self.assertEqual(dlr.message_id, SUCCESSFUL_RESPONSE)
        self.assertFalse(queued_sms.error)
예제 #6
0
    def test_handle_failure(self):
        backend = StartEnterpriseBackend()
        queued_sms = QueuedSMS()

        with patch(
                'corehq.messaging.smsbackends.start_enterprise.models.notify_exception'
        ) as notify_patch:
            backend.handle_response(queued_sms, 200, RECOGNIZED_ERROR_MESSAGE)
            self.assertEqual(queued_sms.system_error_message,
                             SMS.ERROR_TOO_MANY_UNSUCCESSFUL_ATTEMPTS)
            self.assertTrue(queued_sms.error)
            notify_patch.assert_called_once_with(
                None, "Error with the Start Enterprise Backend: %s" %
                RECOGNIZED_ERROR_MESSAGE)

        with self.assertRaisesMessage(StartEnterpriseBackendException,
                                      "Received unexpected status code: 500"):
            backend.handle_response(queued_sms, 500, '')

        with self.assertRaisesMessage(
                StartEnterpriseBackendException,
                "Unrecognized response from Start Enterprise gateway: %s" %
                UNRECOGNIZED_ERROR_MESSAGE):
            backend.handle_response(queued_sms, 200,
                                    UNRECOGNIZED_ERROR_MESSAGE)
예제 #7
0
class TestStartEnterpriseBackendRequest(TestCase):

    def setUp(self):
        self.backend = StartEnterpriseBackend()
        self.backend.set_extra_fields(
            username=TEST_USERNAME,
            password=TEST_PASSWORD,
            sender_id=TEST_SENDER_ID,
        )

    def test_ascii(self):
        queued_sms = QueuedSMS(
            phone_number=TEST_PHONE_NUMBER,
            text=TEST_TEXT_MESSAGE,
        )
        self.assertEqual(
            self.backend.get_params(queued_sms),
            {
                'usr': TEST_USERNAME,
                'pass': TEST_PASSWORD,
                'msisdn': strip_plus(TEST_PHONE_NUMBER),
                'sid': TEST_SENDER_ID,
                'mt': LONG_TEXT_MSG_TYPE,
                'msg': TEST_TEXT_MESSAGE,
            }
        )

    def test_unicode(self):
        queued_sms = QueuedSMS(
            phone_number=TEST_PHONE_NUMBER,
            text=TEST_UNICODE_MESSAGE,
        )
        self.assertEqual(
            self.backend.get_params(queued_sms),
            {
                'usr': TEST_USERNAME,
                'pass': TEST_PASSWORD,
                'msisdn': strip_plus(TEST_PHONE_NUMBER),
                'sid': TEST_SENDER_ID,
                'mt': LONG_UNICODE_MSG_TYPE,
                'msg': '0928092E0938094D09240947',
            }
        )

    def test_phone_number_is_valid(self):
        self.assertFalse(StartEnterpriseBackend.phone_number_is_valid('+91'))
        self.assertFalse(StartEnterpriseBackend.phone_number_is_valid('+123456789'))
        self.assertTrue(StartEnterpriseBackend.phone_number_is_valid('+910123456789'))
예제 #8
0
 def setUp(self):
     self.backend = StartEnterpriseBackend()
     self.backend.set_extra_fields(
         username=TEST_USERNAME,
         password=TEST_PASSWORD,
         sender_id=TEST_SENDER_ID,
     )
예제 #9
0
    def test_handle_failure(self):
        backend = StartEnterpriseBackend()
        queued_sms = QueuedSMS()

        with patch('corehq.messaging.smsbackends.start_enterprise.models.notify_exception') as notify_patch:
            backend.handle_response(queued_sms, 200, RECOGNIZED_ERROR_MESSAGE)
            self.assertEqual(queued_sms.system_error_message, SMS.ERROR_TOO_MANY_UNSUCCESSFUL_ATTEMPTS)
            self.assertTrue(queued_sms.error)
            notify_patch.assert_called_once_with(
                None,
                "Error with the Start Enterprise Backend: %s" % RECOGNIZED_ERROR_MESSAGE
            )

        with self.assertRaisesMessage(
            StartEnterpriseBackendException,
            "Received unexpected status code: 500"
        ):
            backend.handle_response(queued_sms, 500, '')

        with self.assertRaisesMessage(
            StartEnterpriseBackendException,
            "Unrecognized response from Start Enterprise gateway: %s" % UNRECOGNIZED_ERROR_MESSAGE
        ):
            backend.handle_response(queued_sms, 200, UNRECOGNIZED_ERROR_MESSAGE)
예제 #10
0
 def test_phone_number_is_valid(self):
     self.assertFalse(StartEnterpriseBackend.phone_number_is_valid('+91'))
     self.assertFalse(StartEnterpriseBackend.phone_number_is_valid('+123456789'))
     self.assertTrue(StartEnterpriseBackend.phone_number_is_valid('+910123456789'))
예제 #11
0
 def test_phone_number_is_valid(self):
     self.assertFalse(StartEnterpriseBackend.phone_number_is_valid('+91'))
     self.assertFalse(StartEnterpriseBackend.phone_number_is_valid('+123456789'))
     self.assertTrue(StartEnterpriseBackend.phone_number_is_valid('+910123456789'))