def _handleError(f): # XXX: Perhaps report this back to the transport somehow??? log.err(f, 'Failure processing SOAP request') request.setResponseCode(http.INTERNAL_SERVER_ERROR) faultcode = u'soapenv:Server' if f.check(SoapFault): return f.value.to_element() return soap_fault(faultcode, f.getErrorMessage())
def test_soap_fault(self): """ `soap_fault` constructs a SOAP fault element from a code and description. """ self.assertEqual( '<soapenv:Fault xmlns:soapenv=' '"http://schemas.xmlsoap.org/soap/envelope/">' '<faultcode>soapenv:Client</faultcode>' '<faultstring>Oops.</faultstring></soapenv:Fault>', tostring(soap_fault('soapenv:Client', 'Oops.')))
def test_fault(self): """ `perform_soap_request` raises `SoapFault`, parsed from the ``Fault`` element in the response, if the response HTTP status is ``500 Internal server error``. """ response = MockResponse.build(http.INTERNAL_SERVER_ERROR, soap_fault('soapenv:Server', 'Whoops')) f = self.failureResultOf( self._perform_soap_request(response, 'uri', 'action', 'request'), SoapFault) self.assertEqual(('soapenv:Server', 'Whoops'), (f.value.code, f.getErrorMessage()))
def test_fault(self): """ `perform_soap_request` raises `SoapFault`, parsed from the ``Fault`` element in the response, if the response HTTP status is ``500 Internal server error``. """ response = MockResponse.build( http.INTERNAL_SERVER_ERROR, soap_fault('soapenv:Server', 'Whoops')) f = self.failureResultOf( self._perform_soap_request(response, 'uri', 'action', 'request'), SoapFault) self.assertEqual( ('soapenv:Server', 'Whoops'), (f.value.code, f.getErrorMessage()))
def test_send_sms_policy_fault(self): """ `ParlayXClient.send_sms` expects `PolicyExceptionDetail` fault details in SOAP requests that fail for remote policy-related reasons. """ detail = PARLAYX_COMMON_NS.PolicyExceptionDetail( L.messageId('a'), L.text('b'), L.variables('c'), L.variables('d')) client = self._make_client( MockResponse.build( http.INTERNAL_SERVER_ERROR, soap_fault('soapenv:Server', 'Whoops', detail=detail))) f = self.failureResultOf( client.send_sms('+27117654321', 'content', 'message_id'), PolicyException) detail = f.value.parsed_detail self.assertEqual(('a', 'b', ['c', 'd']), (detail.message_id, detail.text, detail.variables))
def test_stop_sms_notification_service_fault(self): """ `ParlayXClient.stop_sms_notification` expects `ServiceExceptionDetail` fault details in SOAP requests that fail for remote service-related reasons. """ detail = PARLAYX_COMMON_NS.ServiceExceptionDetail( L.messageId('a'), L.text('b'), L.variables('c'), L.variables('d')) client = self._make_client( MockResponse.build( http.INTERNAL_SERVER_ERROR, soap_fault('soapenv:Server', 'Whoops', detail=detail))) f = self.failureResultOf(client.stop_sms_notification(), ServiceException) detail = f.value.parsed_detail self.assertEqual(('a', 'b', ['c', 'd']), (detail.message_id, detail.text, detail.variables))
def test_expected_fault(self): """ `perform_soap_request` raises a `SoapFault` subclass when a SOAP fault detail matches one of the expected fault types. """ detail = L.ToyFaultDetail(L.foo('a'), L.bar('b')) response = MockResponse.build( http.INTERNAL_SERVER_ERROR, soap_fault('soapenv:Server', 'Whoops', detail=detail)) f = self.failureResultOf( self._perform_soap_request(response, 'uri', 'action', 'request', expected_faults=[ToyFault]), ToyFault) self.assertEqual(('soapenv:Server', 'Whoops'), (f.value.code, f.getErrorMessage())) parsed_detail = f.value.parsed_detail self.assertEqual(('a', 'b'), (parsed_detail.foo, parsed_detail.bar))
def test_expected_fault(self): """ `perform_soap_request` raises a `SoapFault` subclass when a SOAP fault detail matches one of the expected fault types. """ detail = L.ToyFaultDetail(L.foo('a'), L.bar('b')) response = MockResponse.build( http.INTERNAL_SERVER_ERROR, soap_fault('soapenv:Server', 'Whoops', detail=detail)) f = self.failureResultOf( self._perform_soap_request( response, 'uri', 'action', 'request', expected_faults=[ToyFault]), ToyFault) self.assertEqual( ('soapenv:Server', 'Whoops'), (f.value.code, f.getErrorMessage())) parsed_detail = f.value.parsed_detail self.assertEqual( ('a', 'b'), (parsed_detail.foo, parsed_detail.bar))
def _make_fault(*a, **kw): """ Create a SOAP body containing a SOAP fault. """ return SOAP_ENV.Body(soap_fault(*a, **kw))