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)
Example #2
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)
Example #3
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)
Example #4
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)
Example #5
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)