Example #1
0
    def render_POST(self, request):
        """
        Process a SOAP request and convert any exceptions into SOAP faults.
        """
        def _writeResponse(response):
            request.setHeader('Content-Type', 'text/xml; charset="utf-8"')
            request.write(tostring(soap_envelope(response)))
            request.finish()

        def _handleSuccess(result):
            request.setResponseCode(http.OK)
            return result

        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())

        try:
            tree = parse_document(request.content)
            body, header = unwrap_soap_envelope(tree)
        except:
            d = fail()
        else:
            d = maybeDeferred(self.process, request, body, header)
            d.addCallback(_handleSuccess)

        d.addErrback(_handleError)
        d.addCallback(_writeResponse)
        return NOT_DONE_YET
Example #2
0
 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)))
Example #3
0
 def test_unwrap_soap_envelope(self):
     """
     `unwrap_soap_envelope` unwraps a SOAP envelope element, with no header,
     to a tuple of the SOAP body element and ``None``.
     """
     body, header = unwrap_soap_envelope(
         soap_envelope(Element('tag', 'hello')))
     self.assertIdentical(None, header)
     self.assertEqual(
         '<soapenv:Body xmlns:soapenv='
         '"http://schemas.xmlsoap.org/soap/envelope/"><tag>hello</tag>'
         '</soapenv:Body>', tostring(body))
Example #4
0
 def test_unwrap_soap_envelope(self):
     """
     `unwrap_soap_envelope` unwraps a SOAP envelope element, with no header,
     to a tuple of the SOAP body element and ``None``.
     """
     body, header = unwrap_soap_envelope(
         soap_envelope(Element('tag', 'hello')))
     self.assertIdentical(None, header)
     self.assertEqual(
         '<soapenv:Body xmlns:soapenv='
         '"http://schemas.xmlsoap.org/soap/envelope/"><tag>hello</tag>'
         '</soapenv:Body>',
         tostring(body))
Example #5
0
 def test_unwrap_soap_envelope_header(self):
     """
     `unwrap_soap_envelope` unwraps a SOAP envelope element, with a header,
     to a tuple of the SOAP body and header elements.
     """
     body, header = unwrap_soap_envelope(
         soap_envelope(Element('tag', 'hello'), Element('header', 'value')))
     self.assertEqual(
         '<soapenv:Header xmlns:soapenv='
         '"http://schemas.xmlsoap.org/soap/envelope/">'
         '<header>value</header></soapenv:Header>', tostring(header))
     self.assertEqual(
         '<soapenv:Body xmlns:soapenv='
         '"http://schemas.xmlsoap.org/soap/envelope/">'
         '<tag>hello</tag></soapenv:Body>', tostring(body))
Example #6
0
 def test_unwrap_soap_envelope_header(self):
     """
     `unwrap_soap_envelope` unwraps a SOAP envelope element, with a header,
     to a tuple of the SOAP body and header elements.
     """
     body, header = unwrap_soap_envelope(
         soap_envelope(
             Element('tag', 'hello'),
             Element('header', 'value')))
     self.assertEqual(
         '<soapenv:Header xmlns:soapenv='
         '"http://schemas.xmlsoap.org/soap/envelope/">'
         '<header>value</header></soapenv:Header>',
         tostring(header))
     self.assertEqual(
         '<soapenv:Body xmlns:soapenv='
         '"http://schemas.xmlsoap.org/soap/envelope/">'
         '<tag>hello</tag></soapenv:Body>',
         tostring(body))
Example #7
0
    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)))