コード例 #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
ファイル: test_response.py プロジェクト: dimagi/commcare-hq
    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
ファイル: test_request.py プロジェクト: dimagi/commcare-hq
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
ファイル: test_request.py プロジェクト: dimagi/commcare-hq
 def setUp(self):
     self.backend = StartEnterpriseBackend()
     self.backend.set_extra_fields(
         username=TEST_USERNAME,
         password=TEST_PASSWORD,
         sender_id=TEST_SENDER_ID,
     )
コード例 #9
0
ファイル: test_response.py プロジェクト: dimagi/commcare-hq
    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
ファイル: test_request.py プロジェクト: dimagi/commcare-hq
 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'))