def test_stop_sms_notification(self): """ `ParlayXClient.stop_sms_notification` performs a SOAP request to the remote ParlayX notification endpoint indicating that delivery and receipt notifications for a particular service activation number can be deactivated. """ client = self._make_client( MockResponse.build( http.OK, NOTIFICATION_MANAGER_NS.stopSmsNotificationResponse)) client._now = partial(datetime, 2013, 6, 18, 10, 59, 33) self.successResultOf(client.stop_sms_notification()) self.assertEqual(1, len(self.requests)) self.assertEqual('notification', self.requests[0][0]) body, header = unwrap_soap_envelope(fromstring(self.requests[0][1])) self.assertEqual( { str(NOTIFICATION_MANAGER_NS.stopSmsNotification): { 'correlator': client._service_correlator } }, element_to_dict( elemfind(body, NOTIFICATION_MANAGER_NS.stopSmsNotification))) self.assertEqual( { str(PARLAYX_HEAD_NS.RequestSOAPHeader): { str(PARLAYX_HEAD_NS.serviceId): 'service_id', str(PARLAYX_HEAD_NS.spId): 'user', str(PARLAYX_HEAD_NS.spPassword): '1f2e67e642b16f6623459fa76dc3894f', str(PARLAYX_HEAD_NS.timeStamp): '20130618105933' } }, element_to_dict(elemfind(header, PARLAYX_HEAD_NS.RequestSOAPHeader)))
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_success(self): """ `perform_soap_request` issues a SOAP request, over HTTP, to a URI, sets the ``SOAPAction`` header and parses the response as a SOAP envelope. """ response = MockResponse.build(http.OK, 'response', 'response_header') body, header = self.successResultOf( self._perform_soap_request(response, 'uri', 'action', 'request')) self.assertEqual([('uri', tostring(soap_envelope('request')), { 'SOAPAction': 'action', 'Content-Type': 'text/xml; charset="utf-8"' })], self.requests) self.assertEqual(SOAP_ENV.Body.text, body.tag) self.assertEqual('response', body.text) self.assertEqual(SOAP_ENV.Header.text, header.tag) self.assertEqual('response_header', header.text)
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_success(self): """ `perform_soap_request` issues a SOAP request, over HTTP, to a URI, sets the ``SOAPAction`` header and parses the response as a SOAP envelope. """ response = MockResponse.build(http.OK, 'response', 'response_header') body, header = self.successResultOf( self._perform_soap_request(response, 'uri', 'action', 'request')) self.assertEqual([ ('uri', tostring(soap_envelope('request')), {'SOAPAction': 'action', 'Content-Type': 'text/xml; charset="utf-8"'})], self.requests) self.assertEqual(SOAP_ENV.Body.text, body.tag) self.assertEqual('response', body.text) self.assertEqual(SOAP_ENV.Header.text, header.tag) self.assertEqual('response_header', header.text)
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_send_sms(self): """ `ParlayXClient.send_sms` performs a SOAP request to the remote ParlayX send endpoint to deliver a message via SMS. """ client = self._make_client( MockResponse.build( http.OK, SEND_NS.sendSmsResponse(SEND_NS.result('reference')))) client._now = partial(datetime, 2013, 6, 18, 10, 59, 33) response = self.successResultOf( client.send_sms('+27117654321', 'content', 'message_id', 'linkid')) self.assertEqual('reference', response) self.assertEqual(1, len(self.requests)) self.assertEqual('send', self.requests[0][0]) body, header = unwrap_soap_envelope(fromstring(self.requests[0][1])) self.assertEqual( { str(SEND_NS.sendSms): { str(SEND_NS.addresses): 'tel:27117654321', str(SEND_NS.message): 'content', str(SEND_NS.receiptRequest): { 'correlator': 'message_id', 'endpoint': 'endpoint', 'interfaceName': 'SmsNotification' } } }, element_to_dict(elemfind(body, SEND_NS.sendSms))) self.assertEqual( { str(PARLAYX_HEAD_NS.RequestSOAPHeader): { str(PARLAYX_HEAD_NS.serviceId): 'service_id', str(PARLAYX_HEAD_NS.spId): 'user', str(PARLAYX_HEAD_NS.spPassword): '1f2e67e642b16f6623459fa76dc3894f', str(PARLAYX_HEAD_NS.timeStamp): '20130618105933', str(PARLAYX_HEAD_NS.linkid): 'linkid', str(PARLAYX_HEAD_NS.OA): 'tel:27117654321' } }, element_to_dict(elemfind(header, PARLAYX_HEAD_NS.RequestSOAPHeader)))
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))