def test_render_exceptions(self): """ `SmsNotificationService.render_POST` logs any exceptions that occur during processing and writes a SOAP fault back to the request. """ def process(*a, **kw): raise ValueError('What is this') service = SmsNotificationService(None, None) service.process = process request = DummyRequest([]) request.content = StringIO(tostring(soap_envelope('hello'))) d = request.notifyFinish() service.render_POST(request) self.successResultOf(d) self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode) failures = self.flushLoggedErrors(ValueError) self.assertEqual(1, len(failures)) self.assertEqual( { str(SOAP_ENV.Envelope): { str(SOAP_ENV.Body): { str(SOAP_ENV.Fault): { 'faultcode': 'soapenv:Server', 'faultstring': 'What is this' } } } }, element_to_dict(fromstring(''.join(request.written))))
def test_process_notifySmsReception(self): """ `SmsNotificationService.process_notifySmsReception` invokes the message delivery callback with the correlator (message identifier) and a `SmsMessage` instance containing the details of the delivered message. """ def callback(*a): self.callbacks.append(a) self.callbacks = [] service = SmsNotificationService(callback, None) self.successResultOf( service.process( None, SOAP_ENV.Body( create_sms_reception_element('1234', 'message', '+27117654321', '54321')), SOAP_ENV.Header( PARLAYX_COMMON_NS.NotifySOAPHeader( PARLAYX_COMMON_NS.linkid('linkid'))))) self.assertEqual(1, len(self.callbacks)) correlator, linkid, msg = self.callbacks[0] self.assertEqual( ('1234', 'linkid', 'message', '+27117654321', '54321', None), (correlator, linkid, msg.message, msg.sender_address, msg.service_activation_number, msg.timestamp))
def test_render_soap_fault(self): """ `SmsNotificationService.render_POST` logs any exceptions that occur during processing and writes a SOAP fault back to the request. If the logged exception is a `SoapFault` its ``to_element`` method is invoked to serialize the fault. """ service = SmsNotificationService(None, None) service.process = lambda *a, **kw: L.done() request = DummyRequest([]) request.content = StringIO(tostring(L.hello())) d = request.notifyFinish() service.render_POST(request) self.successResultOf(d) self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode) failures = self.flushLoggedErrors(SoapFault) self.assertEqual(1, len(failures)) self.assertEqual( { str(SOAP_ENV.Envelope): { str(SOAP_ENV.Body): { str(SOAP_ENV.Fault): { 'faultcode': 'soapenv:Client', 'faultstring': 'Malformed SOAP request' } } } }, element_to_dict(fromstring(''.join(request.written))))
def test_render_exceptions(self): """ `SmsNotificationService.render_POST` logs any exceptions that occur during processing and writes a SOAP fault back to the request. """ def process(*a, **kw): raise ValueError('What is this') service = SmsNotificationService(None, None) service.process = process request = DummyRequest([]) request.content = StringIO(tostring(soap_envelope('hello'))) d = request.notifyFinish() service.render_POST(request) self.successResultOf(d) self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode) failures = self.flushLoggedErrors(ValueError) self.assertEqual(1, len(failures)) self.assertEqual( {str(SOAP_ENV.Envelope): { str(SOAP_ENV.Body): { str(SOAP_ENV.Fault): { 'faultcode': 'soapenv:Server', 'faultstring': 'What is this'}}}}, element_to_dict(fromstring(''.join(request.written))))
def test_render_soap_fault(self): """ `SmsNotificationService.render_POST` logs any exceptions that occur during processing and writes a SOAP fault back to the request. If the logged exception is a `SoapFault` its ``to_element`` method is invoked to serialize the fault. """ service = SmsNotificationService(None, None) service.process = lambda *a, **kw: L.done() request = DummyRequest([]) request.content = StringIO(tostring(L.hello())) d = request.notifyFinish() service.render_POST(request) self.successResultOf(d) self.assertEqual(http.INTERNAL_SERVER_ERROR, request.responseCode) failures = self.flushLoggedErrors(SoapFault) self.assertEqual(1, len(failures)) self.assertEqual( {str(SOAP_ENV.Envelope): { str(SOAP_ENV.Body): { str(SOAP_ENV.Fault): { 'faultcode': 'soapenv:Client', 'faultstring': 'Malformed SOAP request'}}}}, element_to_dict(fromstring(''.join(request.written))))
def test_process_notifySmsReception(self): """ `SmsNotificationService.process_notifySmsReception` invokes the message delivery callback with the correlator (message identifier) and a `SmsMessage` instance containing the details of the delivered message. """ def callback(*a): self.callbacks.append(a) self.callbacks = [] service = SmsNotificationService(callback, None) self.successResultOf(service.process(None, SOAP_ENV.Body( create_sms_reception_element( '1234', 'message', '+27117654321', '54321')), SOAP_ENV.Header( PARLAYX_COMMON_NS.NotifySOAPHeader( PARLAYX_COMMON_NS.linkid('linkid'))))) self.assertEqual(1, len(self.callbacks)) correlator, linkid, msg = self.callbacks[0] self.assertEqual( ('1234', 'linkid', 'message', '+27117654321', '54321', None), (correlator, linkid, msg.message, msg.sender_address, msg.service_activation_number, msg.timestamp))
def test_render(self): """ `SmsNotificationService.render_POST` parses a SOAP request and dispatches it to `SmsNotificationService.process` for processing. """ service = SmsNotificationService(None, None) service.process = lambda *a, **kw: L.done() request = DummyRequest([]) request.content = StringIO(tostring(soap_envelope('hello'))) d = request.notifyFinish() service.render_POST(request) self.successResultOf(d) self.assertEqual(http.OK, request.responseCode) self.assertEqual( {str(SOAP_ENV.Envelope): { str(SOAP_ENV.Body): { 'done': None}}}, element_to_dict(fromstring(''.join(request.written))))
def test_render(self): """ `SmsNotificationService.render_POST` parses a SOAP request and dispatches it to `SmsNotificationService.process` for processing. """ service = SmsNotificationService(None, None) service.process = lambda *a, **kw: L.done() request = DummyRequest([]) request.content = StringIO(tostring(soap_envelope('hello'))) d = request.notifyFinish() service.render_POST(request) self.successResultOf(d) self.assertEqual(http.OK, request.responseCode) self.assertEqual( {str(SOAP_ENV.Envelope): { str(SOAP_ENV.Body): { 'done': None } }}, element_to_dict(fromstring(''.join(request.written))))
def test_process_notifySmsDeliveryReceipt(self): """ `SmsNotificationService.process_notifySmsDeliveryReceipt` invokes the delivery receipt callback with the correlator (message identifier) and the delivery status (translated into a Vumi-compatible value.) """ def callback(*a): self.callbacks.append(a) self.callbacks = [] service = SmsNotificationService(None, callback) self.successResultOf(service.process(None, SOAP_ENV.Body( create_sms_delivery_receipt( '1234', '+27117654321', DeliveryStatus.DeliveryUncertain)))) self.assertEqual(1, len(self.callbacks)) correlator, status = self.callbacks[0] self.assertEqual(('1234', 'pending'), self.callbacks[0])
def test_process_notifySmsDeliveryReceipt(self): """ `SmsNotificationService.process_notifySmsDeliveryReceipt` invokes the delivery receipt callback with the correlator (message identifier) and the delivery status (translated into a Vumi-compatible value.) """ def callback(*a): self.callbacks.append(a) self.callbacks = [] service = SmsNotificationService(None, callback) self.successResultOf( service.process( None, SOAP_ENV.Body( create_sms_delivery_receipt( '1234', '+27117654321', DeliveryStatus.DeliveryUncertain)))) self.assertEqual(1, len(self.callbacks)) correlator, status = self.callbacks[0] self.assertEqual(('1234', 'pending'), self.callbacks[0])